helm/zsh/functions
2014-07-17 04:26:38 -04:00

62 lines
1.6 KiB
Bash

#!/bin/zsh
# Check to see if a command exists
function command_exists {
command -v "$1" &> /dev/null
}
# OS detection
function is_deb {
command_exists apt-get
}
function is_mac {
[[ $(uname) == 'Darwin' ]]
}
function is_linux {
[[ $(uname) == 'Linux' ]]
}
# Extract a compressed file with the appropriate command
function unpack {
if [ -f "$1" ]; then
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
}
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
# vim:set ft=zsh: