File: quitcd.elv

package info (click to toggle)
nnn 5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,184 kB
  • sloc: ansic: 11,902; sh: 3,585; makefile: 512; cpp: 80; python: 31; csh: 2
file content (41 lines) | stat: -rw-r--r-- 922 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Append this file to ~/.elvish/rc.elv (Elvish > 0.17.0)

use path

fn n {|@a|
	# Block nesting of nnn in subshells
	if (has-env NNNLVL) {
		try {
			if (>= $E:NNNLVL 1) {
				echo "nnn is already running"
				return
			}
		} catch e {
			nop
		}
	}

	# The behaviour is set to cd on quit (nnn checks if NNN_TMPFILE is set)
  # If NNN_TMPFILE is set to a custom path, it must be exported for nnn to
  # see.
  if (has-env XDG_CONFIG_HOME) {
		set-env NNN_TMPFILE $E:XDG_CONFIG_HOME/nnn/.lastd
	} else {
		set-env NNN_TMPFILE $E:HOME/.config/nnn/.lastd
	}

	# Unmask ^Q (, ^V etc.) (if required, see `stty -a`) to Quit nnn
  # stty start undef
  # stty stop undef
  # stty lwrap undef
  # stty lnext undef

	# The e: prefix allows one to alias n to nnn if desired without making an
	# infinitely recursive alias
	e:nnn $@a

	if (path:is-regular $E:NNN_TMPFILE) {
		eval (slurp < $E:NNN_TMPFILE)
		rm -- $E:NNN_TMPFILE
	}
}