❯ find . -name “requirements.in” -print0 | xargs -0 sh -c ‘for arg in “$@”; do echo “awscli” »"$arg"; done’
Posts tagged: bash
All posts with the tag "bash"
I use Tmux and Vim for most of my workflow, but I end up with a lot of dangling
tmux sessions that dont’ really need to persist… but killing them one at a
time is a pain so I wrote a little script-kitty nonsense to pipe multiple
choices from fzf into tmux kill-session
I defined a little function in my .zshrc
destroy() {
tmux list-sessions -F '#{session_name}' | fzf -m | xargs -d $'\n' sh -c 'echo "killing $0"; tmux kill-session -t "$0"; for arg;do echo "killing $arg";tmux kill-session -t "$arg"; done'
}
bindkey -s '^d' 'destroy \n'
tmux list-sessions -F '#{session_name}' prints all my active tmux sessions to the console with the format of just their name
pype.dev main ×1 via v3.8.11(pype.dev) on (us-east-1) proxy
❯ tmux list-sessions -F '#{session_name}'
session-01
session-02
session-03
...
Pipe that to fzf -m to allow multiple choices to be made using tab
Then the nasty bit in xargs… I echo killing @0 and killing $arg because the sh -c passes the first tmux session name to @0 (it’s just what bash does) and then the rest get handled in the for loop.
Basically then I get an fzf list to choose multiple tmux sessions to destroy to clean up some RAM!
I started my homelab journey being super naive about ZFS and how to manage the
filesystem… that bit me in the butt when transfering a ton of files out of
folders and into datasets because ZFS is copy on write so I was essentially
duplicating my storage until I got a hair smarter about removing files after
they’re moved (rsync –remove-source-file ftw). But I had a ton of snapshots of
child datasets with a ton of data that I just never will need, so I learned
zfs list -H -o name -t snapshot tank/dataset1/dataset2 will list just the
snapshots for dataset2 and if you pipe that into xargs -n1 zfs destroy then
you have a way to clear out some snapshots you don’t need!
Stow is a great tool for managing dotfiles. My usage looks like cloning my dotfiles to my home directory, setting some environment variables via a script, then stowing relevant packages and boom my config is good to go…
cd ~
git clone <my dotfiles repo>
cd dotfiles
# env variable stuff ignored here
stow zsh # This will symlink my .zshrc file which is in ~/dotfiles/zsh to ~/.zshrc
By default stow will stow packages up one directory from the root directory.
In this example the root directory is ~/dotfiles and the package is zsh.
So the files in the zsh package will symlinked into ~/.
stow makes it easy to share dotfiles across machines, or safely experiment with config changes while always being protected by git since your dotfiles are in a git repo!
…They are in a git repo… right?
Check out stow for a brief introduction to stow
What if I want to stow a package somewhere else?
Boom, that’s where -t comes in…
Maybe I don’t like having my dotfiles repo at $HOME and instead I want it in ~/git or ~/personal just to stay organized…
Well then I could have the same workflow except the stow command looks like this:
stow zsh -t ~/
#or
stow zsh -t $HOME