]> Sergey Matveev's repositories - nnn.git/blob - misc/quitcd/quitcd.bash_zsh
2450b7956dd564d3b04ebcb047981d79fc63b912
[nnn.git] / misc / quitcd / quitcd.bash_zsh
1 n ()
2 {
3     # Block nesting of nnn in subshells
4     if [[ "${NNNLVL:-0}" -ge 1 ]]; then
5         echo "nnn is already running"
6         return
7     fi
8
9     # The behaviour is set to cd on quit (nnn checks if NNN_TMPFILE is set)
10     # If NNN_TMPFILE is set to a custom path, it must be exported for nnn to
11     # see. To cd on quit only on ^G, remove the "export" and make sure not to
12     # use a custom path, i.e. set NNN_TMPFILE *exactly* as follows:
13     #     NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"
14     export NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"
15
16     # Unmask ^Q (, ^V etc.) (if required, see `stty -a`) to Quit nnn
17     # stty start undef
18     # stty stop undef
19     # stty lwrap undef
20     # stty lnext undef
21
22     # The backslash allows one to alias n to nnn if desired without making an
23     # infinitely recursive alias
24     \nnn "$@"
25
26     if [ -f "$NNN_TMPFILE" ]; then
27             . "$NNN_TMPFILE"
28             rm -f "$NNN_TMPFILE" > /dev/null
29     fi
30 }