quitcd.elv (919B)
1 # Append this file to ~/.elvish/rc.elv (Elvish > 0.17.0) 2 3 use path 4 5 fn n {|@a| 6 # Block nesting of nnn in subshells 7 if (has-env NNNLVL) { 8 try { 9 if (>= $E:NNNLVL 1) { 10 echo "nnn is already running" 11 return 12 } 13 } catch e { 14 nop 15 } 16 } 17 18 # The behaviour is set to cd on quit (nnn checks if NNN_TMPFILE is set) 19 # If NNN_TMPFILE is set to a custom path, it must be exported for nnn to 20 # see. 21 if (has-env XDG_CONFIG_HOME) { 22 set-env NNN_TMPFILE $E:XDG_CONFIG_HOME/nnn/.lastd 23 } else { 24 set-env NNN_TMPFILE $E:HOME/.config/nnn/.lastd 25 } 26 27 # Unmask ^Q (, ^V etc.) (if required, see `stty -a`) to Quit nnn 28 # stty start undef 29 # stty stop undef 30 # stty lwrap undef 31 # stty lnext undef 32 33 # The e: prefix allows one to alias n to nnn if desired without making an 34 # infinitely recursive alias 35 e:nnn $@a 36 37 if (path:is-regular $E:NNN_TMPFILE) { 38 eval (slurp < $E:NNN_TMPFILE) 39 rm $E:NNN_TMPFILE 40 } 41 }