2023-02-28 15:26:36 +00:00
|
|
|
# The behaviour is set to cd on quit (nnn checks if NNN_TMPFILE is set)
|
2023-03-07 14:40:10 +00:00
|
|
|
let cfgHome = ($env | default $"($env.HOME)/.config" XDG_CONFIG_HOME | get XDG_CONFIG_HOME)
|
2023-12-14 00:14:21 +00:00
|
|
|
$env.NNN_TMPFILE = $"($cfgHome)/nnn/.lastd"
|
2023-02-28 15:26:36 +00:00
|
|
|
|
2023-12-14 00:14:21 +00:00
|
|
|
def --env n [...x] {
|
2023-02-28 15:26:36 +00:00
|
|
|
# Launch nnn. Add desired flags after `^nnn`, ex: `^nnn -eda ($x | str join)`
|
|
|
|
^nnn ($x | str join)
|
|
|
|
let newpath = (
|
|
|
|
if ($env.NNN_TMPFILE | path exists) {
|
2023-09-30 16:19:01 +00:00
|
|
|
# FIXME: fails if path contains single-quote
|
|
|
|
let newpath = (open $env.NNN_TMPFILE | parse "cd '{nnnpath}'").0.nnnpath
|
2023-02-28 15:26:36 +00:00
|
|
|
^rm -f $env.NNN_TMPFILE
|
|
|
|
echo $newpath
|
|
|
|
} else {
|
|
|
|
pwd
|
|
|
|
}
|
|
|
|
)
|
|
|
|
cd $newpath
|
|
|
|
}
|