Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

We all know that ~ maps to $HOME or /home/user.

Is it possible to make other mappings like this on other characters (@,_)?

A possible workaround I thought of was to use variables (which require at least two characters)...

H=/run/media/user/Storage
cp $H/file.txt .

But is there a better way?

share|improve this question
    
A workaround could be to make a function and bind it to a particular key, maybe Ctrl+z (I know that's 2 key strokes but you could find a good alternative, I like to put my ñ to good use). So, this way you type cd ñ, the 'ñ' isn't echoed and instead it turns your current line in something like cd /run/media/user/Sterage/ so you just keep going from there. That is easy with zsh, I'm sure it's also possible with bash. –  Martín Canaval Jan 25 '13 at 20:24

2 Answers 2

In bash, no. I'm not aware of any shells which provide such a feature.

share|improve this answer
1  
You could have just added this as a comment... –  Kyle Jan 25 '13 at 20:04
    
It's a factually correct answer: bash does not have a way of defining additional ~-like shortcuts. –  chepner Jan 25 '13 at 20:26
    
Facts require a source. You said, "In bash, no. 'I'm' not aware" this leads the reader to believe this is your opinion. Heck, I can go to any question on this site I don't know the answer to and write the same thing you wrote while being technically correct. A simple link would make this answer worthwhile. –  Kyle Jan 25 '13 at 20:43
    
Not trying to start a problem your answer just showed up in the review queue. –  Kyle Jan 25 '13 at 20:43

This is possible on a Mac and Linux

On Mac

  • /Users/[yourusername]/.bash_profile

Note: You should also be able to use .profile file, but I do not use it. I just use .bash_profile, because it more specific, like .bashrc on linux, rather than .cshrc.

Instructions

Make a directory mapping (set a variable) to the desktop.

  1. In Terminal.app, run

    nano ~/.bash_profile OR nano $HOME/.bash_profile

  2. Add the following somewhere in your file.

    [nameofvariable]="$HOME/Desktop"

    (for example, pathtodesktop="$HOME/Desktop")

  3. Quit Terminal and restart or run

    source ~/.bash_profile

Finished! Your new variable should function just like $HOME or ~, except to whichever path you choose.

In order to test it you could run:

cd $pathtodesktop

On Linux Just follow the same instructions, except the file you want to edit is under $HOME/.bashrc


Above and Beyond the Question If you have a command that you frequently run, you could create an alias in your .bash_profile as well like this:

alias dt="cd $HOME/Desktop"

Refresh your terminal paths by restarting terminal or with

source ~/.bash_profile

Type just dt and your path should change to the Desktop

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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