Skip to content

Instantly share code, notes, and snippets.

@st-f
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save st-f/d143513d5cb02554a7c8 to your computer and use it in GitHub Desktop.
Save st-f/d143513d5cb02554a7c8 to your computer and use it in GitHub Desktop.
HomeBrew Cask automatic search / install
###############################################################################
# Homebrew and softwares #
###############################################################################
clear
rulem () {
if [ $# -eq 0 ]; then
echo "Usage: rulem MESSAGE [RULE_CHARACTER]"
return 1
fi
size=${#1}
# Fill line with ruler character ($2, default "-"), reset cursor, move 2 cols right, print message
printf -v _hr "%*s" $(tput cols) && echo ${_hr// /${2--}} && echo "\r\033[2C$1"
}
repeat () {
c=$1
size=${#2}
n=$((48-size))
if ! [ "$c" ] || ! [ "$n" ]; then
echo "Error: please supply a string and the number of times to repeat it, e.g.:"
echo "$(basename $0) - 5"
else
echo $(printf "%${n}s\n" | sed "s/ /${c}/g")
fi
}
echo "Installing Homebrew"
#ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
echo "Installing Homebrew Cask"
#brew install caskroom/cask/brew-cask
echo "\nSearching for all softwares via Homebrew Cask"
export HOMEBREW_CASK_OPTS="--appdir=/Applications"
list=$(<softwarelist.txt)
arr=$(echo $list | tr "," "\n")
for x in $arr
do
OUT=`brew-cask search $x`
OUT2=${OUT//$'\n'/ }
OUT2=${OUT2//==> / }
first2=${OUT:0:2}
first5=${OUT2:0:6}
trimed=`echo $OUT2 | cut -c 1-80`
if [ $first2 != "No" ]
then
#OUT3=$(printf "%-48s %s %48s %s\n" "Installing $x" "$OUT2")
#echo $first5
if [ $first5 == "Exact" ]
then
string=$(echo $x)
echo $string$(repeat "." "$string") "OK !"
brew-cask install $string
else
string=$(echo $x)
#string=$(echo "No match found for" $x)
echo $string$(repeat "." "$string") "NOT FOUND :" $trimed
fi
#echo $string$(repeat "." "$string") $trimed
fi
done
echo "Homebrew Cask cleanup"
brew-cask cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment