0

I'm using MacOSX, and the Terminal.app is now all using zsh as default shell. I use Homebrew to manage all kinds of packages/application installation, while every day I will have to open the terminal and run my custom zsh script to update:

  1. Homebrew
  2. Vim package

I'm thinking about is it possible to schedule these scripts so that if the terminal is open and it's time to do all these updating stuff it will remind me and I just have decide yes/no, and won't forget to udpate anything.

1 Answer 1

1

You can run them automatically as a background job. For Homebrew, add this to your .zshrc file:

{ 
  # If xcode-select --install returns 0, it'll start an installer dialog.
  # Since some packages depend on this, then we should not yet run brew.
  # If it returns non-zero, that means it's already installed and it will
  # print a message that says so (which we suppress).
  xcode-select --install 2> /dev/null ||
      brew update --quiet &&
      brew upgrade --fetch-HEAD --quiet 
} &|  # Start in background and immediately disown.

You can add a similar { ... } &| block for your Vim package manager.

6
  • So the effect of this line is that it will run the codes inside the curly braces every time I open it?
    – Niing
    Commented Apr 14, 2021 at 10:31
  • Yes, but silently. You will only see output if there is actually something to update (or if an update fails). If xcode-select or brew doesn't find anything to update, then it won't update anything. And since this happens in the background, your shell startup time is not affected. The only time this could be a problem would be when you start many shells at the exact same time, but brew does not even let you run it more than once concurrently. Commented Apr 14, 2021 at 11:38
  • 1
    @Niing I noticed that the code I originally posted can still produce unwanted output occasionally. I've now updated my answer to be even more silent. Commented Apr 16, 2021 at 19:26
  • Thanks for your kindness, hope you have a good day after seeing this :)
    – Niing
    Commented Apr 17, 2021 at 3:02
  • Thanks. Same to you! :) Commented Apr 17, 2021 at 9:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .