summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/aliases.zsh2
-rw-r--r--lib/bzr.zsh10
-rw-r--r--lib/completion.zsh9
-rw-r--r--lib/correction.zsh24
-rw-r--r--lib/directories.zsh31
-rw-r--r--lib/edit-command-line.zsh3
-rw-r--r--lib/functions.zsh2
-rw-r--r--lib/git.zsh97
-rw-r--r--lib/history.zsh4
-rw-r--r--lib/key-bindings.zsh6
-rw-r--r--lib/misc.zsh4
-rw-r--r--lib/nvm.zsh9
-rw-r--r--lib/rbenv.zsh2
-rw-r--r--lib/rvm.zsh11
-rw-r--r--lib/termsupport.zsh12
-rw-r--r--lib/theme-and-appearance.zsh12
16 files changed, 183 insertions, 55 deletions
diff --git a/lib/aliases.zsh b/lib/aliases.zsh
index 0555be264..9b3709172 100644
--- a/lib/aliases.zsh
+++ b/lib/aliases.zsh
@@ -8,6 +8,7 @@ alias -- -='cd -'
# Super user
alias _='sudo'
+alias please='sudo'
#alias g='grep -in'
@@ -18,6 +19,7 @@ alias history='fc -l 1'
alias lsa='ls -lah'
alias l='ls -la'
alias ll='ls -l'
+alias la='ls -lA'
alias sl=ls # often screw this up
alias afind='ack-grep -il'
diff --git a/lib/bzr.zsh b/lib/bzr.zsh
new file mode 100644
index 000000000..005a16500
--- /dev/null
+++ b/lib/bzr.zsh
@@ -0,0 +1,10 @@
+## Bazaar integration
+## Just works with the GIT integration just add $(bzr_prompt_info) to the PROMPT
+function bzr_prompt_info() {
+ BZR_CB=`bzr nick 2> /dev/null | grep -v "ERROR" | cut -d ":" -f2 | awk -F / '{print "bzr::"$1}'`
+ if [ -n "$BZR_CB" ]; then
+ BZR_DIRTY=""
+ [[ -n `bzr status` ]] && BZR_DIRTY=" %{$fg[red]%} * %{$fg[green]%}"
+ echo "$ZSH_THEME_SCM_PROMPT_PREFIX$BZR_CB$BZR_DIRTY$ZSH_THEME_GIT_PROMPT_SUFFIX"
+ fi
+} \ No newline at end of file
diff --git a/lib/completion.zsh b/lib/completion.zsh
index 0e5d480ff..e0cdcf626 100644
--- a/lib/completion.zsh
+++ b/lib/completion.zsh
@@ -32,21 +32,24 @@ zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-dir
cdpath=(.)
# use /etc/hosts and known_hosts for hostname completion
-[ -r /etc/ssh/ssh_known_hosts ] && _global_ssh_hosts=(${${${${(f)"$(</etc/ssh/ssh_known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=()
+[ -r /etc/ssh/ssh_known_hosts ] && _global_ssh_hosts=(${${${${(f)"$(</etc/ssh/ssh_known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _global_ssh_hosts=()
[ -r ~/.ssh/known_hosts ] && _ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=()
+[ -r ~/.ssh/config ] && _ssh_config=($(cat ~/.ssh/config | sed -ne 's/Host[=\t ]//p')) || _ssh_config=()
[ -r /etc/hosts ] && : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} || _etc_hosts=()
hosts=(
+ "$_ssh_config[@]"
"$_global_ssh_hosts[@]"
"$_ssh_hosts[@]"
"$_etc_hosts[@]"
- `hostname`
+ "$HOST"
localhost
)
zstyle ':completion:*:hosts' hosts $hosts
+zstyle ':completion:*' users off
# Use caching so that commands like apt and dpkg complete are useable
zstyle ':completion::complete:*' use-cache 1
-zstyle ':completion::complete:*' cache-path ~/.oh-my-zsh/cache/
+zstyle ':completion::complete:*' cache-path $ZSH/cache/
# Don't complete uninteresting users
zstyle ':completion:*:*:*:users' ignored-patterns \
diff --git a/lib/correction.zsh b/lib/correction.zsh
index fc60dcdbd..436446101 100644
--- a/lib/correction.zsh
+++ b/lib/correction.zsh
@@ -1,10 +1,14 @@
-setopt correct_all
-
-alias man='nocorrect man'
-alias mv='nocorrect mv'
-alias mysql='nocorrect mysql'
-alias mkdir='nocorrect mkdir'
-alias gist='nocorrect gist'
-alias heroku='nocorrect heroku'
-alias ebuild='nocorrect ebuild'
-alias hpodder='nocorrect hpodder'
+if [[ "$DISABLE_CORRECTION" == "true" ]]; then
+ return
+else
+ setopt correct_all
+ alias man='nocorrect man'
+ alias mv='nocorrect mv'
+ alias mysql='nocorrect mysql'
+ alias mkdir='nocorrect mkdir'
+ alias gist='nocorrect gist'
+ alias heroku='nocorrect heroku'
+ alias ebuild='nocorrect ebuild'
+ alias hpodder='nocorrect hpodder'
+ alias sudo='nocorrect sudo'
+fi
diff --git a/lib/directories.zsh b/lib/directories.zsh
index bb114f615..1896945f4 100644
--- a/lib/directories.zsh
+++ b/lib/directories.zsh
@@ -2,6 +2,7 @@
setopt auto_name_dirs
setopt auto_pushd
setopt pushd_ignore_dups
+setopt pushdminus
alias ..='cd ..'
alias cd..='cd ..'
@@ -11,14 +12,14 @@ alias cd.....='cd ../../../..'
alias cd/='cd /'
alias 1='cd -'
-alias 2='cd +2'
-alias 3='cd +3'
-alias 4='cd +4'
-alias 5='cd +5'
-alias 6='cd +6'
-alias 7='cd +7'
-alias 8='cd +8'
-alias 9='cd +9'
+alias 2='cd -2'
+alias 3='cd -3'
+alias 4='cd -4'
+alias 5='cd -5'
+alias 6='cd -6'
+alias 7='cd -7'
+alias 8='cd -8'
+alias 9='cd -9'
cd () {
if [[ "x$*" == "x..." ]]; then
@@ -26,9 +27,12 @@ cd () {
elif [[ "x$*" == "x...." ]]; then
cd ../../..
elif [[ "x$*" == "x....." ]]; then
- cd ../../..
- elif [[ "x$*" == "x......" ]]; then
cd ../../../..
+ elif [[ "x$*" == "x......" ]]; then
+ cd ../../../../..
+ elif [ -d ~/.autoenv ]; then
+ source ~/.autoenv/activate.sh
+ autoenv_cd "$@"
else
builtin cd "$@"
fi
@@ -36,9 +40,4 @@ cd () {
alias md='mkdir -p'
alias rd=rmdir
-alias d='dirs -v'
-
-# mkdir & cd to it
-function mcd() {
- mkdir -p "$1" && cd "$1";
-} \ No newline at end of file
+alias d='dirs -v | head -10'
diff --git a/lib/edit-command-line.zsh b/lib/edit-command-line.zsh
deleted file mode 100644
index db2000325..000000000
--- a/lib/edit-command-line.zsh
+++ /dev/null
@@ -1,3 +0,0 @@
-autoload -U edit-command-line
-zle -N edit-command-line
-bindkey '\C-x\C-e' edit-command-line
diff --git a/lib/functions.zsh b/lib/functions.zsh
index d2dcadd0c..63ab755cf 100644
--- a/lib/functions.zsh
+++ b/lib/functions.zsh
@@ -1,5 +1,5 @@
function zsh_stats() {
- history | awk '{print $2}' | sort | uniq -c | sort -rn | head
+ history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n20
}
function uninstall_oh_my_zsh() {
diff --git a/lib/git.zsh b/lib/git.zsh
index defa062c6..305a77aff 100644
--- a/lib/git.zsh
+++ b/lib/git.zsh
@@ -1,40 +1,79 @@
# get the name of the branch we are on
function git_prompt_info() {
- ref=$(git symbolic-ref HEAD 2> /dev/null) || return
- echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
+ if [[ "$(git config --get oh-my-zsh.hide-status)" != "1" ]]; then
+ ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
+ ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
+ echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
+ fi
}
+
# Checks if working tree is dirty
parse_git_dirty() {
- if [[ -n $(git status -s --ignore-submodules=dirty 2> /dev/null) ]]; then
- echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
+ local SUBMODULE_SYNTAX=''
+ local GIT_STATUS=''
+ local CLEAN_MESSAGE='nothing to commit (working directory clean)'
+ if [[ "$(command git config --get oh-my-zsh.hide-status)" != "1" ]]; then
+ if [[ $POST_1_7_2_GIT -gt 0 ]]; then
+ SUBMODULE_SYNTAX="--ignore-submodules=dirty"
+ fi
+ if [[ "$DISABLE_UNTRACKED_FILES_DIRTY" == "true" ]]; then
+ GIT_STATUS=$(command git status -s ${SUBMODULE_SYNTAX} -uno 2> /dev/null | tail -n1)
+ else
+ GIT_STATUS=$(command git status -s ${SUBMODULE_SYNTAX} 2> /dev/null | tail -n1)
+ fi
+ if [[ -n $GIT_STATUS ]]; then
+ echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
+ else
+ echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
+ fi
else
echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
fi
}
+# get the difference between the local and remote branches
+git_remote_status() {
+ remote=${$(command git rev-parse --verify ${hook_com[branch]}@{upstream} --symbolic-full-name 2>/dev/null)/refs\/remotes\/}
+ if [[ -n ${remote} ]] ; then
+ ahead=$(command git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
+ behind=$(command git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l)
+
+ if [ $ahead -eq 0 ] && [ $behind -gt 0 ]
+ then
+ echo "$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE"
+ elif [ $ahead -gt 0 ] && [ $behind -eq 0 ]
+ then
+ echo "$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE"
+ elif [ $ahead -gt 0 ] && [ $behind -gt 0 ]
+ then
+ echo "$ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE"
+ fi
+ fi
+}
+
# Checks if there are commits ahead from remote
function git_prompt_ahead() {
- if $(echo "$(git log origin/$(current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
+ if $(echo "$(command git log origin/$(current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
echo "$ZSH_THEME_GIT_PROMPT_AHEAD"
fi
}
# Formats prompt string for current git commit short SHA
function git_prompt_short_sha() {
- SHA=$(git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
+ SHA=$(command git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
}
# Formats prompt string for current git commit long SHA
function git_prompt_long_sha() {
- SHA=$(git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
+ SHA=$(command git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
}
# Get the status of the working tree
git_prompt_status() {
- INDEX=$(git status --porcelain 2> /dev/null)
+ INDEX=$(command git status --porcelain -b 2> /dev/null)
STATUS=""
- if $(echo "$INDEX" | grep '^?? ' &> /dev/null); then
+ if $(echo "$INDEX" | grep -E '^\?\? ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$STATUS"
fi
if $(echo "$INDEX" | grep '^A ' &> /dev/null); then
@@ -54,11 +93,51 @@ git_prompt_status() {
fi
if $(echo "$INDEX" | grep '^ D ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
+ elif $(echo "$INDEX" | grep '^D ' &> /dev/null); then
+ STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
elif $(echo "$INDEX" | grep '^AD ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
fi
+ if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then
+ STATUS="$ZSH_THEME_GIT_PROMPT_STASHED$STATUS"
+ fi
if $(echo "$INDEX" | grep '^UU ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS"
fi
+ if $(echo "$INDEX" | grep '^## .*ahead' &> /dev/null); then
+ STATUS="$ZSH_THEME_GIT_PROMPT_AHEAD$STATUS"
+ fi
+ if $(echo "$INDEX" | grep '^## .*behind' &> /dev/null); then
+ STATUS="$ZSH_THEME_GIT_PROMPT_BEHIND$STATUS"
+ fi
+ if $(echo "$INDEX" | grep '^## .*diverged' &> /dev/null); then
+ STATUS="$ZSH_THEME_GIT_PROMPT_DIVERGED$STATUS"
+ fi
echo $STATUS
}
+
+#compare the provided version of git to the version installed and on path
+#prints 1 if input version <= installed version
+#prints -1 otherwise
+function git_compare_version() {
+ local INPUT_GIT_VERSION=$1;
+ local INSTALLED_GIT_VERSION
+ INPUT_GIT_VERSION=(${(s/./)INPUT_GIT_VERSION});
+ INSTALLED_GIT_VERSION=($(command git --version 2>/dev/null));
+ INSTALLED_GIT_VERSION=(${(s/./)INSTALLED_GIT_VERSION[3]});
+
+ for i in {1..3}; do
+ if [[ $INSTALLED_GIT_VERSION[$i] -lt $INPUT_GIT_VERSION[$i] ]]; then
+ echo -1
+ return 0
+ fi
+ done
+ echo 1
+}
+
+#this is unlikely to change so make it all statically assigned
+POST_1_7_2_GIT=$(git_compare_version "1.7.2")
+#clean up the namespace slightly by removing the checker function
+unset -f git_compare_version
+
+
diff --git a/lib/history.zsh b/lib/history.zsh
index 876936b87..655945166 100644
--- a/lib/history.zsh
+++ b/lib/history.zsh
@@ -1,5 +1,7 @@
## Command history configuration
-HISTFILE=$HOME/.zsh_history
+if [ -z $HISTFILE ]; then
+ HISTFILE=$HOME/.zsh_history
+fi
HISTSIZE=10000
SAVEHIST=10000
diff --git a/lib/key-bindings.zsh b/lib/key-bindings.zsh
index 5c1b90bfa..49f80c8f3 100644
--- a/lib/key-bindings.zsh
+++ b/lib/key-bindings.zsh
@@ -3,7 +3,6 @@
bindkey -e
bindkey '\ew' kill-region
bindkey -s '\el' "ls\n"
-bindkey -s '\e.' "..\n"
bindkey '^r' history-incremental-search-backward
bindkey "^[[5~" up-line-or-history
bindkey "^[[6~" down-line-or-history
@@ -31,6 +30,11 @@ bindkey "^[[3~" delete-char
bindkey "^[3;5~" delete-char
bindkey "\e[3~" delete-char
+# Edit the current command line in $EDITOR
+autoload -U edit-command-line
+zle -N edit-command-line
+bindkey '\C-x\C-e' edit-command-line
+
# consider emacs keybindings:
#bindkey -e ## emacs key bindings
diff --git a/lib/misc.zsh b/lib/misc.zsh
index 88732e664..a8678b8ec 100644
--- a/lib/misc.zsh
+++ b/lib/misc.zsh
@@ -9,5 +9,7 @@ bindkey "^[m" copy-prev-shell-word
setopt long_list_jobs
## pager
-export PAGER=less
+export PAGER="less"
+export LESS="-R"
+
export LC_CTYPE=$LANG
diff --git a/lib/nvm.zsh b/lib/nvm.zsh
new file mode 100644
index 000000000..5cadf7061
--- /dev/null
+++ b/lib/nvm.zsh
@@ -0,0 +1,9 @@
+# get the node.js version
+function nvm_prompt_info() {
+ [ -f $HOME/.nvm/nvm.sh ] || return
+ local nvm_prompt
+ nvm_prompt=$(node -v 2>/dev/null)
+ [[ "${nvm_prompt}x" == "x" ]] && return
+ nvm_prompt=${nvm_prompt:1}
+ echo "${ZSH_THEME_NVM_PROMPT_PREFIX}${nvm_prompt}${ZSH_THEME_NVM_PROMPT_SUFFIX}"
+}
diff --git a/lib/rbenv.zsh b/lib/rbenv.zsh
new file mode 100644
index 000000000..a8b6c323c
--- /dev/null
+++ b/lib/rbenv.zsh
@@ -0,0 +1,2 @@
+# using the rbenv plugin will override this with a real implementation
+function rbenv_prompt_info() {}
diff --git a/lib/rvm.zsh b/lib/rvm.zsh
index 597be1b33..e8744e61e 100644
--- a/lib/rvm.zsh
+++ b/lib/rvm.zsh
@@ -1,7 +1,8 @@
-# get the name of the branch we are on
+# get the name of the ruby version
function rvm_prompt_info() {
- ruby_version=$(~/.rvm/bin/rvm-prompt 2> /dev/null) || return
- echo "($ruby_version)"
+ [ -f $HOME/.rvm/bin/rvm-prompt ] || return
+ local rvm_prompt
+ rvm_prompt=$($HOME/.rvm/bin/rvm-prompt ${ZSH_THEME_RVM_PROMPT_OPTIONS} 2>/dev/null)
+ [[ "${rvm_prompt}x" == "x" ]] && return
+ echo "${ZSH_THEME_RVM_PROMPT_PREFIX:=(}${rvm_prompt}${ZSH_THEME_RVM_PROMPT_SUFFIX:=)}"
}
-
-
diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh
index 221989502..80319e1a8 100644
--- a/lib/termsupport.zsh
+++ b/lib/termsupport.zsh
@@ -3,10 +3,12 @@
#Fully support screen, iterm, and probably most modern xterm and rxvt
#Limited support for Apple Terminal (Terminal can't set window or tab separately)
function title {
- [ "$DISABLE_AUTO_TITLE" != "true" ] || return
+ if [[ "$DISABLE_AUTO_TITLE" == "true" ]] || [[ "$EMACS" == *term* ]]; then
+ return
+ fi
if [[ "$TERM" == screen* ]]; then
print -Pn "\ek$1:q\e\\" #set screen hardstatus, usually truncated at 20 chars
- elif [[ "$TERM" == xterm* ]] || [[ $TERM == rxvt* ]] || [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
+ elif [[ "$TERM" == xterm* ]] || [[ $TERM == rxvt* ]] || [[ $TERM == ansi ]] || [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
print -Pn "\e]2;$2:q\a" #set window name
print -Pn "\e]1;$1:q\a" #set icon (=tab) name (will override window name on broken terminal)
fi
@@ -24,8 +26,10 @@ function omz_termsupport_precmd {
function omz_termsupport_preexec {
emulate -L zsh
setopt extended_glob
- local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]} #cmd name only, or if this is sudo or ssh, the next cmd
- title "$CMD" "%100>...>$2%<<"
+ local CMD=${1[(wr)^(*=*|sudo|ssh|rake|-*)]} #cmd name only, or if this is sudo or ssh, the next cmd
+ local LINE="${2:gs/$/\\$}"
+ LINE="${LINE:gs/%/%%}"
+ title "$CMD" "%100>...>$LINE%<<"
}
autoload -U add-zsh-hook
diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh
index aec67721a..0353f9db4 100644
--- a/lib/theme-and-appearance.zsh
+++ b/lib/theme-and-appearance.zsh
@@ -7,7 +7,17 @@ export LSCOLORS="Gxfxcxdxbxegedabagacad"
if [ "$DISABLE_LS_COLORS" != "true" ]
then
# Find the option for using colors in ls, depending on the version: Linux or BSD
- ls --color -d . &>/dev/null 2>&1 && alias ls='ls --color=tty' || alias ls='ls -G'
+ if [[ "$(uname -s)" == "NetBSD" ]]; then
+ # On NetBSD, test if "gls" (GNU ls) is installed (this one supports colors);
+ # otherwise, leave ls as is, because NetBSD's ls doesn't support -G
+ gls --color -d . &>/dev/null 2>&1 && alias ls='gls --color=tty'
+ elif [[ "$(uname -s)" == "OpenBSD" ]]; then
+ # On OpenBSD, test if "colorls" is installed (this one supports colors);
+ # otherwise, leave ls as is, because OpenBSD's ls doesn't support -G
+ colorls -G -d . &>/dev/null 2>&1 && alias ls='colorls -G'
+ else
+ ls --color -d . &>/dev/null 2>&1 && alias ls='ls --color=tty' || alias ls='ls -G'
+ fi
fi
#setopt no_beep