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.

I'm fairly new to zsh, or bash for that matter.

I wish to set up custom commands, i.e. type desktop to bring me to my desktop. I have heard that if I edit my .bash_profile file with the following code, this would work in bash:

desktop() {
    cd /Users/me/Desktop
{

It does not seem to be working with zsh.

Is it just a matter of which file I place the above code in? Or am I going about this all wrong?

I appreciate any help you can provide.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Edit the ~/.bashrc file. Find the alias section and add the following
alias desktop='cd /path/to/desktop'

Doing so, you'll declare some aliases. You can make any custom alias you want !
(ie. i have alias ne='emacs -nw' and everytime i run
ne "some file"
it opens the file in shell based emacs.)

Whenever you'll write desktop, it'll bring you there :-) (theoretically)

share|improve this answer
    
You may need to reboot for the changes to be effective. –  PatrickCUDO Jan 20 '12 at 16:55
    
I appreciate the info, but it would seem I do not have a ~/.bashrc file. Is this because I'm using zsh or oh-my-zsh? I was able to get the code in my question working by placing it in the ~/.oh-my-zsh/oh-my-zsh.sh file, but when I use the same method to open a file, I get a cd:cd:10: not a directory:. So first, is it ok for me to place the code in the oh-my-zsh.sh file? And second, why would I be getting the cd:cd:10 alert? –  stefmikhail Jan 20 '12 at 18:03
1  
I figured out why I was getting the cd:cd:10 alert, so the only question that stands is concerning placement. I found that the code also works in ~/.zshrc which seems for apt. Is it ok to be placed here? And what about the difference between my code and your code? Are they doing two different things? Or is mine wrong, and yours right? –  stefmikhail Jan 20 '12 at 18:13
    
my code works for bash. I am not familiar with zsh but I have found this : acm.uiuc.edu/workshops/zsh/alias.html I hope it will help. ~/.zshrc is used when you run zsh, while ~/.bashrc is for bash. I don't know oh-my-zsh at all. You can place the code line in ~/.zshrc if you want to run your alias through zsh. Your code is hum, I wouldn't say incorrect but incomplete, and it's much harder to get it to work the way you try to attain. With the code line I provided you, you're using some shell built in scripts. –  PatrickCUDO Jan 20 '12 at 18:54
    
Thanks a bunch. I've got it working now without a hitch. You should really check out oh-my-zsh. Very cool stuff! –  stefmikhail Jan 20 '12 at 19:06
show 1 more comment

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.