I'm currently trying to write a shell function for updating my .zshrc file. I currently have an alias that is as follows

alias zshrc="vim ~/.zshrc"

I was wondering if there is any way to write a function that would wait for me to close vim then run a command after vim has closed. For reference the command I would want to run is.

source ~/.zshrc
  • Just right a normal function, with the commands you want to run after vim included. The subsequent commands will not run until vim has been closed by default. – Jaken551 Jul 8 '18 at 21:34
  • 1
    can zsh aliases not include a ; or &&? alias zshrc='vim ~/.zshrc; source ~/.zshrc'? – glenn jackman Jul 9 '18 at 1:26
  • @glennjackman Yes, they can. Aliases are expanded before the command line is parsed. So they can contain anything you otherwise could type on the command line because they are replaced by their value as if you had typed it on the command line. – Adaephon Jul 10 '18 at 9:25

To run one command after another, simply write them on separate lines, or with ; after the first command. So change your alias to a function, and make it run source ~/.zshrc after vim has finished running.

function zshrc {
  vim ~/.zshrc
  source ~/.zshrc

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.