MacOS – How to make a command run automatically when I open a new terminal window

macosterminal

How do I make a command run automatically (in my case: alias t="todo.sh") whenever I open a new terminal window? I've looked for many posts but they all have personalised commands, which then led to personalised answers. Can anybody help me with this?

Best Answer

Each shell has initialisation files which get run at each start (aka new Terminal tab/window). Put the command into the appropriate one and it will be available in new tabs.

  • for bash, use ~/.bashrc
  • for zsh, use ~/.zshrc

You can use echo $SHELL to determine which shell you are using.