我使用Homebrew Cask在OS x上安装应用程序,如何升级所有已安装的Cask ?


当前回答

基于@Atais的回答,我将他的逻辑增强为更好的东西。我想要一种方法,在真正强制升级之前,首先检查要升级的包。

$ brew- bucket .sh只是列出了一个类似Homebrew的酿造更新的输出。 上面的列表显示了所有安装的包,绿色的特遣队表示任何未决的更新。 $ brew- bucket .sh upgrade将强制升级这些包。

代码:

# Usage:
#
#  $ brew update
#    You should execute this first to update everything locally.
#
#  $ brew-cask.sh [update]
#    This will list all of your cask packages and rather there is an upgrade
#    pending with a ✔ checkmark, just like Homebrew does with "brew update".
#    The update command is optional, as it doesn't actually do any tracking, there's
#    not really anything to "update" with cask.  But it keeps with the pattern of
#    of Homebrew's "brew update" pattern for those with memory muscle fingers (like me).
#
#  $ brew-cask.sh upgrade
#    This performs a "brew cask install <cask> --force" of all cask packages that have
#    an update pending.
#
# This code was inspired by http://stackoverflow.com/a/36000907/56693

# get the list of installed casks
casks=( $(brew cask list) )

if [[ "$1" == "upgrade" ]]; then
  for cask in ${casks[@]}; do
    current="$(brew cask info $cask | sed -n '1p' | sed -n 's/^.*: \(.*\)$/\1/p')"
    installed=( $(ls /opt/homebrew-cask/Caskroom/$cask))
    if (! [[ " ${installed[@]} " == *" $current "* ]]); then
      echo "Upgrading $cask to v$current."
      (set -x; brew cask install $cask --force;)
    else
      echo "$cask v$current is up-to-date, skipping."
    fi
  done
else
  echo "Inspecting ${#casks[@]} casks. Use 'brew-cask.sh upgrade' to perform any updates."
  for (( i = i ; i < ${#casks[@]} ; i++ )); do
    current="$(brew cask info ${casks[$i]} | sed -n '1p' | sed -n 's/^.*: \(.*\)$/\1/p')"
    installed=( $(ls /opt/homebrew-cask/Caskroom/${casks[$i]}))
    if (! [[ " ${installed[@]} " == *" $current "* ]]); then
      casks[$i]="${casks[$i]}$(tput sgr0)$(tput setaf 2) ✔$(tput sgr0)"
    fi
  done
  echo " ${casks[@]/%/$'\n'}" | column
fi

只要安装它(也就是“我现在就需要它!”)

它被检入我的。dotfiles回购;所以,你可以快速地将它安装到你的~/binwith:

$ curl -L https://raw.githubusercontent.com/eduncan911/dotfiles/master/bin/brew-cask.sh --create-dirs -o ~/bin/brew-cask.sh
$ chmod 755 ~/bin/brew-cask.sh

然后像这样使用它:

$ brew-cask.sh
$ brew-cask.sh upgrade

如果你的路径中没有~/bin,在上面的语句前加上~/bin/。

其他回答

我认为使用

brew cask reinstall `brew cask outdated`

会成功的。这也将有助于删除应用程序的以前版本,并安装新版本。

这是我写的处理这个的函数。注意,我个人不希望它只是盲目地重新安装所有东西,因为我使用的一些桶需要一段时间才能安装或需要额外的提示。

brew_cask_upgrade() { 
  if [ "$1" != '--continue' ]; then 
    echo "Removing brew cache" 
    rm -rf "$(brew --cache)" 
    echo "Running brew update" 
    brew update 
  fi 
  for c in $(brew cask list); do 
    echo -e "\n\nInstalled versions of $c: " 
    ls /opt/homebrew-cask/Caskroom/$c 
    echo "Cask info for $c" 
    brew cask info $c 
    select ynx in "Yes" "No" "Exit"; do  
      case $ynx in 
        "Yes") echo "Uninstalling $c"; brew cask uninstall --force "$c"; echo "Re-installing $c"; brew cask install "$c"; break;; 
        "No") echo "Skipping $c"; break;; 
        "Exit") echo "Exiting brew_cask_upgrade"; return;; 
      esac 
    done 
  done 
} 

这样的剧本是我自己做的。请查看github https://github.com/pesh1983/brew_cask_upgrade。它有很好的描述,但如果你有任何其他问题,请随时问我。它进行了公平的升级:卸载和安装,因此任何必要的清理将由“brew”本身执行。

酿造桶升级

升级命令最近已经在Homebrew Cask中引入,应该不建议使用其他回答中描述的所有其他手动方法。

基于@Atais的回答,我将他的逻辑增强为更好的东西。我想要一种方法,在真正强制升级之前,首先检查要升级的包。

$ brew- bucket .sh只是列出了一个类似Homebrew的酿造更新的输出。 上面的列表显示了所有安装的包,绿色的特遣队表示任何未决的更新。 $ brew- bucket .sh upgrade将强制升级这些包。

代码:

# Usage:
#
#  $ brew update
#    You should execute this first to update everything locally.
#
#  $ brew-cask.sh [update]
#    This will list all of your cask packages and rather there is an upgrade
#    pending with a ✔ checkmark, just like Homebrew does with "brew update".
#    The update command is optional, as it doesn't actually do any tracking, there's
#    not really anything to "update" with cask.  But it keeps with the pattern of
#    of Homebrew's "brew update" pattern for those with memory muscle fingers (like me).
#
#  $ brew-cask.sh upgrade
#    This performs a "brew cask install <cask> --force" of all cask packages that have
#    an update pending.
#
# This code was inspired by http://stackoverflow.com/a/36000907/56693

# get the list of installed casks
casks=( $(brew cask list) )

if [[ "$1" == "upgrade" ]]; then
  for cask in ${casks[@]}; do
    current="$(brew cask info $cask | sed -n '1p' | sed -n 's/^.*: \(.*\)$/\1/p')"
    installed=( $(ls /opt/homebrew-cask/Caskroom/$cask))
    if (! [[ " ${installed[@]} " == *" $current "* ]]); then
      echo "Upgrading $cask to v$current."
      (set -x; brew cask install $cask --force;)
    else
      echo "$cask v$current is up-to-date, skipping."
    fi
  done
else
  echo "Inspecting ${#casks[@]} casks. Use 'brew-cask.sh upgrade' to perform any updates."
  for (( i = i ; i < ${#casks[@]} ; i++ )); do
    current="$(brew cask info ${casks[$i]} | sed -n '1p' | sed -n 's/^.*: \(.*\)$/\1/p')"
    installed=( $(ls /opt/homebrew-cask/Caskroom/${casks[$i]}))
    if (! [[ " ${installed[@]} " == *" $current "* ]]); then
      casks[$i]="${casks[$i]}$(tput sgr0)$(tput setaf 2) ✔$(tput sgr0)"
    fi
  done
  echo " ${casks[@]/%/$'\n'}" | column
fi

只要安装它(也就是“我现在就需要它!”)

它被检入我的。dotfiles回购;所以,你可以快速地将它安装到你的~/binwith:

$ curl -L https://raw.githubusercontent.com/eduncan911/dotfiles/master/bin/brew-cask.sh --create-dirs -o ~/bin/brew-cask.sh
$ chmod 755 ~/bin/brew-cask.sh

然后像这样使用它:

$ brew-cask.sh
$ brew-cask.sh upgrade

如果你的路径中没有~/bin,在上面的语句前加上~/bin/。