0

I found the command I want to use: cd $(ls -d */|head -n 1) and it works as expected when I do it in the terminal. However when I map it in ranger (either with map g1 cd... or map g1 shell cd...) I don't get it to work.

Could it be that ranger doesn't support nested commands?

Edit:
The answer works, for clarity sake what I wanted to do was to have one keybinding in ranger that cd's me into the first of the currently visible folders, one keybinding that cd's me into the second etc. Also for example to cd into the third folder I discovered that I need to use cd $(ls -d */ |head -n 3 | tail -1) which in line with the answer would translate to

map g3 eval from ranger.ext.spawn import spawn; fm.cd(spawn("ls -d */|head -n 3| tail -1").strip())
0

While you did not say what you are trying to achieve, to cd $(ls -d */|head -n 1) within ranger you need to use:

map g1 eval from ranger.ext.spawn import spawn; fm.cd(spawn("ls -d */|head -n 1").strip())
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.