Slightly simpler "cd on quit"; running in a subshell #1733
Replies: 1 comment 2 replies
-
The If it works for you, then that's great, but I don't think we can recommend as basic guideline since it might cause issues. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all, I've been using nnn for a long time. I'm also a long-time user of the "configure cd on quit" behaviour. IIRC this used to be done with a bash alias
n()
(which I still use from time to time) and requires messing around with a file. There are new instructions there now.I think this can be achieved using a simple subshell, and I wonder whether anyone else uses this workflow, or if it would be helpful to mention it in the wiki. The basic idea is to use the
-p
argument, e.g.this is similar to
vim $(fzf)
, which I've definitely seen other people use. The behaviour is slightly different because you have to select the directory to be changed to rather than merely inhabiting it. It's possible to add some error checking (in case you select nothing, or multiple things, or select a file which is not a directory).This can be unworkable if you do not have execute permission of the parent of the directory you want to access, but in normal usage I have never had this happen (if I want to cd to my home directory for example, I would not even open nnn). This could be easily fixed by optionally including
.
when nnn lists a directory. Enabling hidden files doesn't do this, on my end.There are actually a lot more use cases when using
nnn -p -
in a subshell like this. For instance, I think "open file" only works with the currently hovered file, but it is easy to generalise it to multiple files in this way. I think that's how I came across it in the first place.I wonder if I'm just saying something "everybody knows" or if this actually helps people using the tool.
Beta Was this translation helpful? Give feedback.
All reactions