nnn

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 69882b3bff20afd2160ab9cf5878b2b08f0a6013
parent 2a38132012583c60b1a1ec0ed8bf48e402ee116e
Author: Henri Bourcereau <henri.bourcereau@gmail.com>
Date:   Tue, 28 Feb 2023 16:26:36 +0100

Create quitcd script for nushell
Diffstat:
Amisc/quitcd/quitcd.nu | 18++++++++++++++++++
1 file changed, 18 insertions(+), 0 deletions(-)

diff --git a/misc/quitcd/quitcd.nu b/misc/quitcd/quitcd.nu @@ -0,0 +1,18 @@ +# The behaviour is set to cd on quit (nnn checks if NNN_TMPFILE is set) +let cfgHome = ($env | default $env.HOME XDG_CONFIG_HOME | get XDG_CONFIG_HOME) +let-env NNN_TMPFILE = $"($cfgHome)/.config/nnn/.lastd" + +def-env n [...x] { + # 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) { + let newpath = (open $env.NNN_TMPFILE | parse 'cd "{nnnpath}"').0.nnnpath + ^rm -f $env.NNN_TMPFILE + echo $newpath + } else { + pwd + } + ) + cd $newpath +}