quitcd.fish (1134B)
1 # Rename this file to match the name of the function 2 # e.g. ~/.config/fish/functions/n.fish 3 # or, add the lines to the 'config.fish' file. 4 5 function n --wraps nnn --description 'support nnn quit and change directory' 6 # Block nesting of nnn in subshells 7 if test -n "$NNNLVL" 8 if [ (expr $NNNLVL + 0) -ge 1 ] 9 echo "nnn is already running" 10 return 11 end 12 end 13 14 # The behaviour is set to cd on quit (nnn checks if NNN_TMPFILE is set) 15 # To cd on quit only on ^G, remove the "-x" as in: 16 # set NNN_TMPFILE "$XDG_CONFIG_HOME/nnn/.lastd" 17 # (or, to a custom path: set NNN_TMPFILE "/tmp/.lastd") 18 # or, export NNN_TMPFILE after nnn invocation 19 if test -n "$XDG_CONFIG_HOME" 20 set -x NNN_TMPFILE "$XDG_CONFIG_HOME/nnn/.lastd" 21 else 22 set -x NNN_TMPFILE "$HOME/.config/nnn/.lastd" 23 end 24 25 # Unmask ^Q (, ^V etc.) (if required, see `stty -a`) to Quit nnn 26 # stty start undef 27 # stty stop undef 28 # stty lwrap undef 29 # stty lnext undef 30 31 nnn $argv 32 33 if test -e $NNN_TMPFILE 34 source $NNN_TMPFILE 35 rm $NNN_TMPFILE 36 end 37 end