I want to permanently store zsh aliases. When I make an alias and shut down ITerm and reopen and it's gone!
alias mkcd="function _mkcd(){mkdir "$1"; cd "$1"} _mkcd"
mkcd Ken
zsh: command not found: mkcd
How can I make it permanent?
I want to permanently store zsh aliases. When I make an alias and shut down ITerm and reopen and it's gone!
alias mkcd="function _mkcd(){mkdir "$1"; cd "$1"} _mkcd"
mkcd Ken
zsh: command not found: mkcd
How can I make it permanent?
Create a file .zshrc
in your home directory if it does not exist already and add the alias to the file.
Next time when you open the terminal. It will be available.
To use it in the same session, just source the .zshrc
file by running the command . .zshrc
from your home directory.
~/.zshrc
. That's the main configuration file for zsh. Type:nano ~/.zshrc
and go to the last section of the file. There are examples commented. Copy and edit them (in Nano: alt+a
to start selection, alt+6
to copy, ctrl+u
to paste).
$ZSH_CUSTOM
(equal to $ZSH/custom
). Open it:cd $ZSH_CUSTOM
Create a blank file to hold the aliases:
nano aliases.zsh
It opens the editor. Create an alias like this:
alias <name>=<command>
e.g., alias h='cd ~'
Another option would be to create a variable and use it instead of an alias:
myVar=<value>
e.g., h='~'
and using it, for instance, like: cd $h
Now close the editor (ctrl+x
for Nano) saving the work (read the text at the bottom). Reload your terminal to bring the changes in effect.
© 2022 - 2024 — McMap. All rights reserved.
take
command (take Ken
), and works for nested too:take foo/bar/Ken
– Hinze