From 0dcaf3473913e6180d9de19d2d22f197e57194a5 Mon Sep 17 00:00:00 2001 From: Sloane Perrault Date: Sat, 6 Aug 2022 08:33:27 -0400 Subject: [PATCH] prevent saving a package to brewfile more than once --- .config/fish/functions/brew-save.fish | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.config/fish/functions/brew-save.fish b/.config/fish/functions/brew-save.fish index e5097c4..79cd9ad 100755 --- a/.config/fish/functions/brew-save.fish +++ b/.config/fish/functions/brew-save.fish @@ -6,10 +6,16 @@ function brew-save -d "Install a new homebrew cask and update the global Brewfil else set -f brewfile_keyword brew end - echo "$brewfile_keyword \"$package\"" >> ~/.Brewfile - brew bundle --global + set -l brewfile_line "$brewfile_keyword \"$package\"" + if grep $brewfile_line ~/.Brewfile &> /dev/null + echo "package already in ~/.Brewfile: $package" + return 1 + else + echo "$brewfile_keyword \"$package\"" >> ~/.Brewfile + brew bundle --global + end else - echo "package not found: $argv" + echo "package not found: $package" return 1 end end