0

I have a directory which has a really long path. However, I use this directory constantly and I cannot move it (WSL Windows directory). I generally use z to jump around to it quickly which is useful, but I would like to have an abbreviation when I need to specify a path in command-line. For example, the Fish shell that I use has an inbuilt "abbr" feature which auto expands text after you press spacebar after typing it. However, this only works if the abbreviation is the first text in the line. If I want to copy something from my home directory I would type

cp filename.txt /c/mnt/Users/%name%/program/directory/subdirectory

But I would like to have something that works like this

cp filename.txt udir

where it expands udir to the path I want.

4
  • Use a soft link. That is one of the many reasons they exist. No, it won't be quite what you point out in your example but it can be "short".. another option is to use an alias for your copy command like cp2 filename.txt that automatically adds the second path. Jun 7, 2021 at 15:10
  • Yeah, I wanted something more versatile, but I'll make do with your suggestion. Thanks
    – ZackT
    Jun 7, 2021 at 17:34
  • one other thought... you can make your own version of cp that interprets the command if the right pattern is found.. otherwise, calls the original copy in /bin/cp.. you just need to have your script at the front of the path so it catches the cp call and not the original one. Jun 8, 2021 at 4:19
  • 1
    And just a heads-up that there's currently an open feature request for what you are asking for. Some of the devs agree that it would be handy, but as far as I know, no work has been done on it yet. Jun 8, 2021 at 13:18

1 Answer 1

0

You could use just use a variable:

udir="/c/mnt/Users/%name%/program/directory/subdirectory"
cp filename.txt $udir

which isn't quite what you wanted because you need the '$', but still saves quite a bit of typing.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .