Oh My Zsh multiple commands with one alias

19,215

Solution 1

As you've discovered, you can chain commands in a single alias using ;:

alias update_my_gems="echo foo; echo bar"

Alternatively, you can write a function very easily in your ~/.zshrc file:

update_my_gems() {
    echo foo
    echo bar
}

For readability, I'd personally go for a function for anything that's semi-complex.

Solution 2

If there are many commands, I find it useful to alias the execution of a .sh file located on my home directory

alias start_containers="./start-containers.sh"

To throw the alias inside the config file, you can do

echo alias start_containers="./start-containers.sh" >> ~/.zshrc
Share:
19,215

Related videos on Youtube

snakesonatoni
Author by

snakesonatoni

Updated on June 10, 2022

Comments

  • snakesonatoni
    snakesonatoni almost 2 years

    I'm using Oh My Zsh, and was wondering if there is a way to create a function or alias to run multiple commands. Just as an example, running an 'update' command will update specific gems, but not all of them.

    • snakesonatoni
      snakesonatoni over 10 years
      Figured it out alias name="something; something else"
  • chepner
    chepner over 10 years
    I'd default to using a function for anything, unless there is a reason why an alias is better (which will rarely be the case).
  • snakesonatoni
    snakesonatoni over 10 years
    I ended up making a function exactly like that. Thank you!
  • Steven Choi
    Steven Choi about 4 years
    @snakesonatoni, do you know of an effective way to replace an OMZ alias with one that accepts parameters? I haven't had much luck: stackoverflow.com/questions/61109665/…