back

by JNRowe·5y ago·view on hn ↗
Hmm, if you mean the C-g behaviour then you need to set $NNN_TMPFILE:

    nnn() {
      declare -x +g NNN_TMPFILE=$(mktemp --tmpdir $0.XXXX)
      trap "rm -f $NNN_TMPFILE" EXIT
      =nnn $@
      [ -s $NNN_TMPFILE ] && source $NNN_TMPFILE
    }
You can use a static file if you're sure you'll never be running more than one instance.

I'd prefer something like:

    nnn() {
      local tmp=$(mktemp --tmpdir $0.XXXX)
      trap "rm -f $tmp" EXIT
      =nnn -p $tmp $@
      [ -s $tmp ] && cd ${"$(< $tmp)":h}
    }
That will cd to the selected file's directory with enter/right, or do nothing if you simply quit. I guess it depends if you use it for browsing a lot or simply picking a file.