# Start with: rc2 -m $home/.rcrc # This example defines commands and editor bindings, not Fish abbreviations. EDITOR=vis VISUAL=vis LESS='-F -g -i -M -R -S -w -X -z-4' LS_OPTIONS='--color=auto' if (~ $#history 0) history=$home/.rc2_history # Keep POSIX children and rc's path list consistent. Changes affect this session. fn paths { if (! ~ $#* 1) { echo 'usage: paths directory' >[1=2]; return 2 } if (! test -d $1) return 1 _rc2_entry=() { for (_rc2_entry in $path) { if (test $_rc2_entry '=' $1) return } path=($1 $path) PATH=$path(1) for (_rc2_entry in $path(2-)) { PATH=$PATH:$_rc2_entry } } } _rc2_entry=() { for (_rc2_entry in $home/.local/bin $home/go/bin $home/.cargo/bin) { if (test -d $_rc2_entry) paths $_rc2_entry } } if (test -d /Applications/Obsidian.app/Contents/MacOS) paths /Applications/Obsidian.app/Contents/MacOS if (whatis -p janet > /dev/null >[2=1]) { JANET_TREE=$home/.local/share/janet JANET_PATH=$JANET_TREE/lib if (test -d $JANET_TREE/bin) paths $JANET_TREE/bin } fn gp { git pull --rebase $* } fn gu { git push $* } fn gc { git commit $* } fn gs { git status $* } fn gb { git branch $* } fn gd { git diff $* } fn ga { git add $* } fn glog { git log --graph --decorate --oneline --all $* } fn ghclone { git clone git@github.com:chiefnoah/$* } fn srhtclone { git clone git@git.sr.ht:~chiefnoah/$* } fn r { cd $home/Documents/repos } fn n { cd $home/repos/notes } fn ne { if (cd $home/repos/notes) nvim $* } if (whatis -p multipass > /dev/null >[2=1]) { fn mp { multipass $* } } if (whatis -p kitty > /dev/null >[2=1]) { fn icat { kitty +kitten icat $* } fn d { kitty +kitten diff $* } } if (whatis -p 9 > /dev/null >[2=1]) { fn mk { 9 mk $* } } # Fix the output protocol regardless of inherited Fish fzf options. fn _rc2_pick { FZF_DEFAULT_OPTS=() FZF_DEFAULT_OPTS_FILE=() fzf '--height=40%' '--layout=reverse' --border --read0 --print0 --no-multi $* } # Remove NUL delimiters outside command substitution. Preserve spaces and newlines. fn c { if (! ~ $#* 0 1) { echo 'usage: c [directory]' >[1=2]; return 2 } _rc2_root=. _rc2_selected=() ifs=() { if (~ $#* 1) { switch ($1) { case /*; _rc2_root=$1 case *; _rc2_root=./$1 } } _rc2_selected=`{find $_rc2_root -name .git -prune -o -type d -print0 | _rc2_pick | xargs -0 printf %s} if (~ $#_rc2_selected 1) cd $_rc2_selected } } fn fe { if (! ~ $#* 0) { echo 'usage: fe' >[1=2]; return 2 } _rc2_selected=() ifs=() { _rc2_selected=`{find . -name .git -prune -o -type f -print0 | _rc2_pick | xargs -0 printf %s} if (~ $#_rc2_selected 1) $EDITOR -- $_rc2_selected } } # Search complete history records without execution or evaluation. fn _rc2_history0 { if (~ $#history 1 && test -f $history) { bind -history0 $history; return $status } bind -history0 } fn _rc2_select_history { bind -read0 bind_result <{_rc2_history0 | _rc2_pick '--scheme=history' --multi --no-multi-line '--bind=ctrl-r:toggle-sort' --query $"*} } fn fh { bind_result=() _rc2_selected=() { if (_rc2_select_history $*) { for (_rc2_selected in $bind_result) printf %s\n $_rc2_selected } } } # Preserve every newline except the final record separator from lf and bm. fn _rc2_chomp { awk 'NR > 1 {printf "\n"} {printf "%s", $0}' $* } fn lfcd { _rc2_file=() _rc2_dir=() _rc2_current=() ifs=() { _rc2_file=`{mktemp | _rc2_chomp} if (! ~ $#_rc2_file 1) return 1 lf '-last-dir-path='$_rc2_file $* if (test -f $_rc2_file) _rc2_dir=`{_rc2_chomp $_rc2_file} rm -f $_rc2_file if (~ $#_rc2_dir 1 && test -d $_rc2_dir) { _rc2_current=`{pwd | _rc2_chomp} if (~ $#_rc2_current 1 && ! test $_rc2_dir '=' $_rc2_current) { if (cd $_rc2_dir) ls } } } } fn bm { switch ($"1) { case add rm list -h --help; builtin bm $*; return $status } _rc2_dir=() ifs=() { _rc2_dir=`{builtin bm --path $* | _rc2_chomp} if (~ $#_rc2_dir 1 && test -d $_rc2_dir) cd $_rc2_dir } } fn t { _rc2_dir=() ifs=() { _rc2_dir=`{mktemp -d | _rc2_chomp} if (~ $#_rc2_dir 1) cd $_rc2_dir } } # Hooks return text through bind_result. The editor does not evaluate the result. fn _rc2_bind_history { _rc2_select_history $bind_line } fn _rc2_bind_file { bind -read0 bind_result <{_rc2_pick '--walker=file,dir,follow,hidden' '--scheme=path' --multi --walker-root $bind_root --query $bind_query} } fn _rc2_bind_cd { if (bind -read0 bind_result <{_rc2_pick '--walker=dir,follow,hidden' '--scheme=path' --no-multi --walker-root $bind_root --query $bind_query}) { if (~ $#bind_result 1 && cd $bind_result) bind_result='' } } fn _rc2_bind_lf { lfcd } # Match fish_user_key_bindings. The editor redraws after each hook. fn rc2_key_bindings { if (whatis -p fzf > /dev/null >[2=1]) { bind ctrl-r line _rc2_bind_history bind ctrl-t token _rc2_bind_file bind alt-c token _rc2_bind_cd } bind ctrl-o run _rc2_bind_lf } rc2_key_bindings