I know that in bash you can set up aliases in a .bash_aliases file so that the command you type doesnt need to be a command stored in the binaries in the system. Is there any way I can get aliases into zsh?
I know that in bash you can set up aliases in a .bash_aliases file so that the command you type doesnt need to be a command stored in the binaries in the system. Is there any way I can get aliases into zsh?
I go back and forth between bash and zsh, and use the same
.aliases
file for both. They share the same basic alias syntax, so you can create a.aliases
file and link it to.bashrc
and.zshrc
:.bashrc
.zshrc
FWIW this can also be done with environment variable declarations, in a separate
.env
file.You can do it by the "alias" command with this syntax:
For "gmrL" switches, see this guide, which is my reference.
For each name, with no value, zsh will print the name and what it is aliased to previously. With no arguments at all,
alias
prints the values of ALL defined aliases.To define one or more aliases, simply enter:
For each name with a corresponding value, zsh defines an alias with that value. For further info, check out that link. ;-)
You generally put them in
~/.zshenv
. But many programs use/bin/sh
(usuallybash
) instead of$SHELL
to execute shell commands, so for it to work everywhere you will probably need to put thebash
equivalent of the alias into~/.bash_aliases
anyway.I was trying some things and I found a way to use my aliases created in bash into zsh, only I had to copy these lines from bashrc:
.zshrc
add this line at the bottom of the file (assuming that your aliases located in
~/.profile
):If anyone find this useful: My situation is that I have a Macbook Laptop, Ubuntu Laptop, Ubuntu Desktop and couple of Ubuntu VMs. In all of them I want to use defaults (so Bash in Ubuntu and Zsh in OSX) but with same aliases.
The way I handle it is that I have my alias file
.bash_aliases
in git repo calleddotfiles
. I just clone the repo in all my computers and I just create a symlink to the alias file:in Ubuntu I add this to
~/.bashrc
:in OSX I add this to
.zshrc
:I wrote this and put it in my
~/.bashrc
a long time ago. I didn't put all that can be done with saving your settings, but just use your imagination!Note: If you're updating
~/.bash_aliases
then update~/.oh-my-zsh/.zsh_aliases
too.Saves your
~/.bash_history
,~/.bashrc
,~/.bash_aliases
and~/.profile
in Dropbox. First make a file named after your files in the Dropbox folder. That way no matter where you edit it, if it's edited? It's up-to-date on all you devices. Add the following lines in your~/.bashrc
: