diff options
Diffstat (limited to '.config/fish/functions/n.fish')
| -rw-r--r-- | .config/fish/functions/n.fish | 33 | 
1 files changed, 33 insertions, 0 deletions
| diff --git a/.config/fish/functions/n.fish b/.config/fish/functions/n.fish new file mode 100644 index 0000000..042011c --- /dev/null +++ b/.config/fish/functions/n.fish | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | function n --wraps=nnn --description 'support nnn quit and change directory' | ||
| 2 | # Block nesting of nnn in subshells | ||
| 3 | if test -n "$NNNLVL" | ||
| 4 | if [ (expr $NNNLVL + 0) -ge 1 ] | ||
| 5 | echo "nnn is already running" | ||
| 6 | return | ||
| 7 | end | ||
| 8 | end | ||
| 9 | |||
| 10 | # The behaviour is set to cd on quit (nnn checks if NNN_TMPFILE is set) | ||
| 11 | # To cd on quit only on ^G, remove the "-x" as in: | ||
| 12 | # set NNN_TMPFILE "$XDG_CONFIG_HOME/nnn/.lastd" | ||
| 13 | # (or, to a custom path: set NNN_TMPFILE "/tmp/.lastd") | ||
| 14 | # or, export NNN_TMPFILE after nnn invocation | ||
| 15 | if test -n "$XDG_CONFIG_HOME" | ||
| 16 | set NNN_TMPFILE "$XDG_CONFIG_HOME/nnn/.lastd" | ||
| 17 | else | ||
| 18 | set NNN_TMPFILE "$HOME/.config/nnn/.lastd" | ||
| 19 | end | ||
| 20 | |||
| 21 | # Unmask ^Q (, ^V etc.) (if required, see `stty -a`) to Quit nnn | ||
| 22 | # stty start undef | ||
| 23 | # stty stop undef | ||
| 24 | # stty lwrap undef | ||
| 25 | # stty lnext undef | ||
| 26 | |||
| 27 | nnn -c $argv | ||
| 28 | |||
| 29 | if test -e $NNN_TMPFILE | ||
| 30 | source $NNN_TMPFILE | ||
| 31 | rm $NNN_TMPFILE | ||
| 32 | end | ||
| 33 | end | ||
