diff options
Diffstat (limited to 'Computer/tools/cli/scripts.md')
-rw-r--r-- | Computer/tools/cli/scripts.md | 130 |
1 files changed, 0 insertions, 130 deletions
diff --git a/Computer/tools/cli/scripts.md b/Computer/tools/cli/scripts.md deleted file mode 100644 index 6e631c7..0000000 --- a/Computer/tools/cli/scripts.md +++ /dev/null @@ -1,130 +0,0 @@ -+++ -title = "CLI Helper scripts" -weight = 1 -+++ - -## Commandline enhancements - -### [fzf](https://github.com/junegunn/fzf) - -`fzf` is a fuzzy selection tool written in Go. An alternative in Rust would be -[skim](https://github.com/lotabout/skim). - -fzf can be used to automate a lot of things, for example it can replace the -`CTRL-R` shortcut in bash: - -```bash -## Include in your .bashrc: -source PATH_TO_FZF_CLONE/shell/key-bindings.bash -``` - -And now, `CTRL-R` will fuzzy search the history. - -`fzf` is a huge productivity boost for commandline work and even other tools -where it integrates. - -Some more examples: - -```bash -## fco - fuzzy checkout git branch -fco() { - local tags branches target - local fzf_cmd="fzf" - tags=$(git tag | awk '{print "\x1b[31;1mtag\x1b[m\t" $1}') \ - || return - - branches=$(git branch --all | grep -v HEAD | \ - sed "s/.* //" | sed "s#remotes/[^/]*/##" | \ - sort -u | awk '{print "\x1b[34;1mbranch\x1b[m\t" $1}') \ - || return - - [[ $TMUX ]] && [[ $(which fzf-tmux 2>/dev/null) ]] && \ - fzf_cmd="fzf-tmux -l30 -- " - - target=$( (echo "$tags"; echo "$branches") | \ - $fzf_cmd --no-hscroll --ansi +m -d "\t" -n 2) \ - || return - - git checkout $(echo "$target" | awk '{print $2}') -} - -## Fuzzy foreground, if you use `CTRL-Z` a lot -fj() { - [ $(jobs | wc -l) -eq 0 ] && return - local j=$(jobs | awk '{ print $3, " - ", $2, " - ", $1; }' | fzf -1 -0) - echo $j - fg $(echo $j | sed -r 's/(.*)\[([0-9]*).*/\2/g') -} - -## Fuzzy select the right tmux session, even within a tmux session -fmux() { - local session - session=$(tmux list-sessions -F "#{session_name}" | \ - fzf --query="$1" --select-1 --exit-0) - - if [[ -z "${TMUX}" ]]; then - tmux -2 attach -t "$session" - else - tmux -2 switch-client -t "$session" - fi -} -``` - -### fzf in vim - -It can also be integrated in `vim` for fuzzy selecting. Things like -fuzzy-jump-to-line, for example: - -```viml -" Using the fzf-preview plugin, this can even be enhanced with a preview window: -nmap <Leader>zf :FZF<CR> -nmap <Leader>zr :FZFRg<CR> -nmap <Leader>zh :FZFHistory<CR> -nmap <Leader>zl :FZFBLines<CR> -nmap <Leader>zt :FZFTags<CR> -nmap <Leader>zT :FZFBTags<CR> -nmap <Leader>zm :FZFMarks<CR> -nmap <Leader>zw :FZFWindows<CR> -``` - - -## Ranger - -Ranger is a nice CLI filemanager (TUI). - - -### (Not) Nesting ranger - -With the following script, one can -ensure that only one ranger instance is running in the terminal (no nested -sessions): - -```bash -r() { - if [ $(jobs | grep ranger | wc -l) -gt 0 ]; then - fg $(jobs | grep ranger | sed 's,^\[,,; s,\].*,,') - else - if [ -z "$RANGER_LEVEL" ]; then - ranger - else - exit - fi - fi -} -``` - - -### tmux integration - -Using tmux from ranger is as simple as - -``` -map ef eval if 'TMUX' in os.environ.keys(): fm.run("tmux splitw -h 'rifle \"" + fm.thisfile.basename + "\"'") -map ev eval if 'TMUX' in os.environ.keys(): fm.run("tmux splitw -v 'rifle \"" + fm.thisfile.basename + "\"'") -map ew eval if 'TMUX' in os.environ.keys(): fm.run("tmux new-window 'rifle \"" + fm.thisfile.basename + "\"'") - -map sf eval if 'TMUX' in os.environ.keys(): fm.run("tmux splitw -h") -map sv eval if 'TMUX' in os.environ.keys(): fm.run("tmux splitw -v") -map sw eval if 'TMUX' in os.environ.keys(): fm.run("tmux new-window") -``` - |