2014-07-17 01:26:38 -07:00
|
|
|
#!/bin/zsh
|
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' ]]
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
# vim:set ft=zsh:
|