Put all functions into zsh/function

This commit is contained in:
Henrik Lissner 2013-11-30 12:50:35 -05:00
parent 07dd7afffa
commit e37b878ef1
5 changed files with 56 additions and 109 deletions

View file

@ -1,4 +1,3 @@
# Disable autocorrect behavior, very annoying!
unsetopt correct_all

View file

@ -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:

View file

@ -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:

View file

@ -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:

View file

@ -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: