4

Shell beginner here! I'd like to create aliases and functions in zsh shell to speed up my workflow. For example:

tw() { open -a //Applications/Textwrangler.app "$*"; }

The function itself works, but the problem is that the function definition disappears once I exit the shell. What's the procedure for saving user defined functions and aliases for future use? The zsh documentation isn't particularly helpful... or maybe I'm just being stupid!

5

What's the procedure for saving user defined functions and aliases for future use?

You probably want to save your customisations in ~/.zshrc.

~/.zshrc is always executed when zsh starts (both interactive logins and non-interactive logins).


Further reading

  • zsh - Installation and Configation, links to example configuration files.
1
  • Thanks! Since I have oh-my-zsh installed, a comment inside of ~/.zshrc suggested I add my customizations to the ~/.oh-my-zsh/custom folder, using any filename with a .zsh extension. – Juho Karppinen Apr 21 '15 at 9:18
0

Restoring from file is already answered.
For saving aliases to file, alias -L will list your aliases in command form. This can easily be redirected to any file you wish, ready to be sourced from ~/.zshrc or elsewhere.

I always do this via a super-useful "save aliases" alias:

alias sa="alias -L > ~/.zsh_aliases"

This way I can add new aliases on the command line and immediately save them on the fly, without opening an editor or thinking about config files. Note that removals of anything coming from the file will also be persisted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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