diff --git a/zsh/config b/zsh/config index d0e3883e..9fbf7328 100644 --- a/zsh/config +++ b/zsh/config @@ -1,4 +1,3 @@ - # Disable autocorrect behavior, very annoying! unsetopt correct_all diff --git a/zsh/functions b/zsh/functions index ef1ade28..ef46935a 100644 --- a/zsh/functions +++ b/zsh/functions @@ -4,6 +4,44 @@ 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' ]] +} + +# 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 +} + # Ask for admin password up front and keep sudo alive until the end of the script function keep_alive { sudo -v @@ -31,7 +69,23 @@ function unpack { fi } -# Source library -for f in ~/.zsh/lib/*; do source "$f"; done +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: diff --git a/zsh/lib/os b/zsh/lib/os deleted file mode 100644 index d3ade8f8..00000000 --- a/zsh/lib/os +++ /dev/null @@ -1,58 +0,0 @@ -function is_deb { - command_exists apt-get -} - -function is_mac { - [[ $(uname) == 'Darwin' ]] -} - -function is_linux { - [[ $(uname) == 'Linux' ]] -} - -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 ] - } - - function pkg_install() { - brew install $1 - } - - function pkg_remove() { - brew remove $1 - } - - function pkg_update() { - brew update && brew upgrade - } - -elif is_deb; then - - function pkg_install() { - sudo apt-get -y install $1 - } - - function pkg_remove() { - sudo apt-get -y remove $1 - } - - function pkg_update() { - sudo apt-get update && sudo apt-get upgrade - } - -fi - -# vim:set ft=zsh: diff --git a/zsh/lib/output b/zsh/lib/output deleted file mode 100644 index 3551441f..00000000 --- a/zsh/lib/output +++ /dev/null @@ -1,36 +0,0 @@ - -# Normal Colors -black='\e[0;30m' # Black -red='\e[0;31m' # Red -green='\e[0;32m' # Green -yellow='\e[0;33m' # Yellow -blue='\e[0;34m' # Blue -purple='\e[0;35m' # Purple -cyan='\e[0;36m' # Cyan -white='\e[0;37m' # White - -# Background -BLACK='\e[40m' # Black -RED='\e[41m' # Red -GREEN='\e[42m' # Green -YELLOw='\e[43m' # Yellow -BLUE='\e[44m' # Blue -PURPLE='\e[45m' # Purple -CYAN='\e[46m' # Cyan -WHITE='\e[47m' # White - -NC="\e[m" # Color Reset - -function echo_g { - echo -e "$green$1$NC" -} - -function echo_r { - echo -e "$red$1$NC" -} - -function indent { - sed "s/^/ /" -} - -# vim:set ft=zsh: diff --git a/zsh/lib/util b/zsh/lib/util deleted file mode 100644 index 795a7818..00000000 --- a/zsh/lib/util +++ /dev/null @@ -1,12 +0,0 @@ - -# Check if a symlink exists before trying to create it -function do_link { - if [ -e "$2" ]; then - rm -rf "$2" - fi - if [ ! -e "$2" ]; then - ln -sf "$1" "$2" - fi -} - -# vim:set ft=zsh: