function nnncd --description "nnn file manager with cd on exit"
# Block nesting of nnn in subshells
if test -n "$NNNLVL" -a "$NNNLVL" -ge 1
echo "nnn is already running"
return
end
# Use -Q to quit on cd
set -x NNN_TMPFILE "$XDG_CONFIG_HOME/nnn/.lastd"
if test -z "$NNN_TMPFILE"
set -x NNN_TMPFILE "$HOME/.config/nnn/.lastd"
end
nnn -Q $argv
if test -e "$NNN_TMPFILE"
source "$NNN_TMPFILE"
rm -f "$NNN_TMPFILE"
end
end
# Alias n to nnncd
function n --description "nnn with cd on exit"
nnncd $argv
end