2013-03-16 15:00:51 -07:00
|
|
|
|
2013-10-26 08:49:34 -07:00
|
|
|
# Check to see if a command exists
|
|
|
|
function command_exists {
|
|
|
|
command -v "$1" &> /dev/null
|
|
|
|
}
|
|
|
|
|
2013-11-30 09:50:35 -08:00
|
|
|
# OS detection
|
|
|
|
function is_deb {
|
|
|
|
command_exists apt-get
|
|
|
|
}
|
|
|
|
|
|
|
|
function is_mac {
|
|
|
|
[[ $(uname) == 'Darwin' ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
function is_linux {
|
|
|
|
[[ $(uname) == 'Linux' ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
# Package management aliases
|
|
|
|
function pkg_install() {
|
|
|
|
if is_mac; then
|
|
|
|
brew install $1
|
|
|
|
elif is_deb; then
|
|
|
|
sudo apt-get -y install $1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function pkg_remove() {
|
|
|
|
if is_mac; then
|
|
|
|
brew remove $1
|
|
|
|
elif is_deb; then
|
|
|
|
sudo apt-get -y remove $1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function pkg_update() {
|
|
|
|
if is_mac; then
|
|
|
|
brew update && brew upgrade
|
|
|
|
elif is_deb; then
|
|
|
|
sudo apt-get update && sudo apt-get upgrade
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-10-26 08:49:34 -07:00
|
|
|
# Ask for admin password up front and keep sudo alive until the end of the script
|
|
|
|
function keep_alive {
|
|
|
|
sudo -v
|
|
|
|
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
|
2013-03-16 15:00:51 -07:00
|
|
|
}
|
2013-03-21 00:07:56 -07:00
|
|
|
|
2013-03-21 19:25:01 -07:00
|
|
|
# Extract a compressed file with the appropriate command
|
2013-10-16 22:35:25 -07:00
|
|
|
function unpack {
|
|
|
|
if [ -f "$1" ]; then
|
2013-03-21 00:07:56 -07:00
|
|
|
case $1 in
|
|
|
|
*.tar.bz2) tar xjf $1 ;;
|
|
|
|
*.tar.gz) tar xzf $1 ;;
|
|
|
|
*.bz2) bunzip2 $1 ;;
|
|
|
|
*.rar) unrar x $1 ;;
|
|
|
|
*.gz) gunzip $1 ;;
|
|
|
|
*.tar) tar xf $1 ;;
|
|
|
|
*.tbz2) tar xjf $1 ;;
|
|
|
|
*.tgz) tar xzf $1 ;;
|
|
|
|
*.zip) unzip $1 ;;
|
|
|
|
*.Z) uncompress $1 ;;
|
|
|
|
*) echo "'$1' cannot be extracted via extract()" ;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
echo "'$1' is not a valid file"
|
|
|
|
fi
|
|
|
|
}
|
2013-03-22 10:15:50 -07:00
|
|
|
|
2013-11-30 09:50:35 -08:00
|
|
|
if is_mac; then
|
|
|
|
|
|
|
|
# Change working directory to the top-most Finder window location
|
|
|
|
function cdf() { # short for `cdfinder`
|
|
|
|
cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Open a file in Mac OS's quick-look
|
|
|
|
function quicklook {
|
|
|
|
(( $# > 0 )) && qlmanage -p $* &>/dev/null &
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check to see if the (mac) app exists
|
|
|
|
function app_exists {
|
|
|
|
[ -d /Applications/"$1" ] || [ -e /Applications/"$1".app ] || [ -e ~/Applications/"$1".app ]
|
|
|
|
}
|
|
|
|
|
|
|
|
fi
|
2013-03-22 18:10:59 -07:00
|
|
|
|
2013-11-30 10:00:18 -08:00
|
|
|
# Output functions
|
|
|
|
function echo_g {
|
|
|
|
echo -e "$green$1$NC"
|
|
|
|
}
|
|
|
|
|
|
|
|
function echo_r {
|
|
|
|
echo -e "$red$1$NC"
|
|
|
|
}
|
|
|
|
|
2013-03-22 18:10:59 -07:00
|
|
|
# vim:set ft=zsh:
|