When I type cd ~foo, I'd like bash to take me to some directory foo as a shortcut for typing the full directory path of foo. and I'd like to be able to cp ~foo/bar.txt ~/bar.txt to copy a file from the /foo/ directory to the home directory... So basically, I want something that works exactly like ~/ does, but where I specify what the directory should be. [I'm sure I should jfgi, but I don't know what to fg]
|
|
|||
|
|
|
The way I used to do this is to create a directory that contains symlinks to the directories you want shortcuts do, and add that directory to your CDPATH. CDPATH controls where
The downside of course is it won't work if there's a directory in your current directory named "b" -- that takes precedence over the CDPATH I normally dislike answers that say "first you need to switch shells", but this exact feature exists in ZSH, if you're willing to use that instead; it's called named directories. You export a variable
|
|||||||||||||||||
|
|
You could write a wrapper function for
|
|||
|
|
|
with bash:
You can make your life easier (or harder) when changing directories by setting the Apart from that, the only way to think of would be to set environment variables for those directories you want to abbreviate.
|
||||
|
|
|
An way would be creating an alias for cd which replaces |
|||||
|
|
For changing directories, you could use wcd: Wherever Change Directory With that, it'll be like |
||||
|
|
|
I have the below function which will create alias on the fly,
When I want to bookmark a directory, I just type |
|||
|
|