Clean up zsh rcfiles + add py|rbenv init

* Made PATH initializing smarter
* zsh rcfiles are no longer fired twice (thanks to zshenv)
* Introduced speculative rb|pyenv support
* General cleanup all around
This commit is contained in:
Henrik Lissner 2014-03-29 17:56:33 -04:00
parent 5976d3341f
commit 91ebf6e21f
7 changed files with 65 additions and 74 deletions

View file

@ -30,6 +30,7 @@ alias va='vagrant'
# Interpreters
command_exists "ruby" && alias rb='ruby'
command_exists "rbenv" && alias re='rbenv'
command_exists "python" && alias py='python'
command_exists "node" && alias js='node'
if [ -e /Applications/love.app ]; then
@ -55,16 +56,10 @@ alias wget='wget -c'
alias sudo='sudo '
if is_linux; then
alias ls='ls --color'
# iptables
alias ipt='sudo iptables'
elif is_mac; then
alias ls='ls -G'
alias b='brew'
alias ql='quicklook'
@ -75,7 +70,6 @@ elif is_mac; then
open "$@"
fi
}
fi
alias v="vim"
@ -85,5 +79,7 @@ function mkd {
mkdir "$@" && cd "$@"
}
alias reload='exec $SHELL -l'
alias c='clear'
# vim:set ft=zsh:

View file

@ -73,4 +73,14 @@ if is_mac; then
zle -N zle-keymap-select
fi
autoload colors
if [[ "$terminfo[colors]" -gt 8 ]]; then
colors
fi
for COLOR in RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE; do
eval $COLOR='$fg_no_bold[${(L)COLOR}]'
eval BOLD_$COLOR='$fg_bold[${(L)COLOR}]'
done
eval RESET='$reset_color'
# vim:set ft=zsh:

View file

@ -17,37 +17,6 @@ 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
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
}
# Extract a compressed file with the appropriate command
function unpack {
if [ -f "$1" ]; then
@ -88,13 +57,4 @@ if is_mac; then
fi
# Output functions
function echo_g {
echo -e "\e[0;32m$1\e[m"
}
function echo_r {
echo -e "\e[0;31m$1\e[m"
}
# vim:set ft=zsh:

View file

@ -1,22 +1,40 @@
if [ -e /usr/local/bin/brew ]; then
BREWDIR=`/usr/local/bin/brew --prefix`
PATH=$BREWDIR/sbin:$PATH
function _init_paths {
export PATH=/usr/bin:/bin:/usr/sbin
# Setup homebrew paths
if [ -e /usr/local/bin/brew ]; then
local BREWDIR=`/usr/local/bin/brew --prefix`
PATH=$BREWDIR/bin:$PATH
COREUTIL=`$BREWDIR/bin/brew --prefix coreutils`
if [ -d "$COREUTIL" ]; then
PATH=$COREUTIL/libexec/bin/gnubin:$PATH
local COREUTILS=`brew --prefix coreutils`
if [ -d "$COREUTILS" ]; then
PATH="$COREUTILS/libexec/gnubin:$PATH"
MANPATH="$COREUTILS/libexec/gnuman:$MANPATH"
fi
fi
fi
# rbenv paths
[ -d $HOME/.rbenv ] && PATH=$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH
# rb/pyenv paths
local RBENV_DIR="`brew --prefix rbenv`"
local PYENV_DIR="`brew --prefix pyenv`"
if [ -d "$RBENV_DIR" ]; then
PATH=$RBENV_DIR/bin:$PATH
export RBENV_ROOT=$RBENV_DIR
fi
if [ -d "$PYENV_DIR" ]; then
PATH=$PYENV_DIR/bin:$PATH
export PYENV_ROOT=$PYENV_DIR
fi
# hostname-specific bins
[ -d $HOME/.dotfiles/bin/`hostname` ] && PATH=$HOME/.dotfiles/bin/`hostname`:$PATH
# hostname-specific bins
[ -d $HOME/.dotfiles/bin/`hostname` ] && PATH=$HOME/.dotfiles/bin/`hostname`:$PATH
# global bins
PATH=$HOME/.dotfiles/bin:$PATH
# global bins
PATH=$HOME/.dotfiles/bin:$PATH
}
_init_paths
unset -f _init_paths
# vim:set ft=zsh:

View file

@ -8,7 +8,7 @@ ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}+%{$fg[white]%}"
# Build Prompt #
##################
function prompt_pwd {
function _prompt_pwd {
SHORTPWD=`print -Pn "%4~"`
if [[ -n "${ZSH_VERSION:-}" ]]
@ -21,11 +21,11 @@ function prompt_pwd {
echo -n $SHORTPWD
}
function prompt_git {
function _prompt_git {
[ "`git_prompt_info`" ] && echo -n "$(git_prompt_info)"
}
function prompt_vimode {
function _prompt_vimode {
# The prompt turns green in command mode, and red in insert mode
PROMPT="$"
@ -39,7 +39,7 @@ function prompt_vimode {
}
# prompts
function lprompt {
function _lprompt {
# Start each prompt with a newline
echo
@ -54,22 +54,22 @@ function lprompt {
fi
# Print the prompt
echo -n '%{$fg[red]%}%{$FX[bold]%}$(prompt_vimode)%{$reset_color%}'
echo -n '%{$fg[red]%}%{$FX[bold]%}$(_prompt_vimode)%{$reset_color%}'
}
function rprompt {
function _rprompt {
# Make the rprompt a bright grey to set it apart
echo -n "%{$FG[245]%}"
echo -n '$(prompt_pwd)'
echo -n '$(_prompt_pwd)'
# Show the branch/status if in a git repo
echo -n '$(prompt_git)'
echo -n '$(_prompt_git)'
# Reset formatting for command output
echo -n "%{$reset_color%}"
}
PROMPT="$(lprompt)"
RPROMPT="$(rprompt)"
PROMPT="$(_lprompt)"
RPROMPT="$(_rprompt)"
# vim:set ft=zsh:

8
zshenv
View file

@ -1,3 +1,5 @@
source ~/.zsh/functions
source ~/.zsh/aliases
source ~/.zsh/paths
if [ -z ${ZSH_INIT+x} ]; then
source ~/.zsh/functions
source ~/.zsh/aliases
source ~/.zsh/paths
fi

5
zshrc
View file

@ -1,4 +1,5 @@
# ZSH Env variables
export ZSH_INIT=1
export ZSH=$HOME/.oh-my-zsh
source ~/.zsh/functions
@ -24,3 +25,7 @@ source ~/.zsh/prompt
# Have a system specific rcfile? Source it!
[ -f ~/.localrc ] && source ~/.localrc
# Init rbenv & pyenv
command_exists rbenv && eval "$(rbenv init -)"
command_exists pyenv && eval "$(pyenv init -)"