Nushell: Support path shortcuts

Created on 6 Apr 2020  路  4Comments  路  Source: nushell/nushell

Is your feature request related to a problem? Please describe.
Navigation between folders can be tedious if there are many levels of folders to go through.

For example, I work on Windows for my day job, and have my code checked out in my user folder. However, I need to run some of the code in a Linux process, which I use Windows Subsystem for Linux (WSL) for. But to find my code, I have to navigate out of the Linux folders and into Windows, so I end up doing a lot of cd /mnt/c/Users/Kasper/project/e/t/c

Another example is that the project I work on includes a web client written in Elm. The Elm compiler is loaded as a development dependency by NPM, so invoking my compiler is done with ./project/node_modules/elm/bin/elm if I want to do something that's not part of our build scripts. I could install the Elm compiler globally, but I would rather just be locked into the version my project is using, and not risk compiling my code with two different compilers, if I forget to update the global one.

Describe the solution you'd like
I would like to be able to specify certain shortcuts to folders basically. A simple solution would be a section in the config where I can list shortcuts ala: desktop=C:\Users\Kasper\Desktop and invoke it with a syntax ala cd */desktop and mv file */desktop (so the shortcut is not only understood by cd, but by all commands preferably)

Describe alternatives you've considered
There are a few existing solutions to this problem out there:

  1. zsh has this exact feature built-in (though it uses ~ instead of */)
  2. bash comes with autocd, which allows you to skip typing cd (as I have understood it at least)
  3. Programs like z/z.lua/zoxide attempt to replace cd with a command that learns your frequently visited folders and lets you type their names without providing a path.
  4. Use symlinks for making shortcuts in the file system, though this is not very user friendly to get started with.

Additional context
This is relevant to what is discussed in https://github.com/nushell/nushell/issues/687

delight enhancement

Most helpful comment

Using ~ is a good option, ZSH is already a complete shell, copying this idea from there may result in fewer drawbacks in the future.

All 4 comments

I like the idea!

A couple of points:

  1. It would have to be something other than *. For example, */desktop could be asking to look for a file/directory named desktop in all subdirectories. Best to avoid ambiguous statements if at all possible.
  2. We do have autocd behaviour 馃檪

Using ~ is a good option, ZSH is already a complete shell, copying this idea from there may result in fewer drawbacks in the future.

The reason I liked */ is that it looks sort of like a path and evokes the idea that you're entering this folder from anywhere, due to the wildcard. I'm happy to use something else though if the risk of clashing with actual globs is too great 馃槉

Another alternative is CDPATH. From man bash:

       CDPATH The search path for the cd command.  This is a colon-separated
              list of directories in which the shell looks for destination
              directories specified by the cd command.  A sample value is
              ".:~:/usr".

I would love a built-in autojump, though.

edit: oh, CDPATH is part of 4th suggestion

Was this page helpful?
0 / 5 - 0 ratings