691 строка
22 KiB
Bash
691 строка
22 KiB
Bash
# Push and pop directories on directory stack
|
||
alias pu='pushd'
|
||
alias po='popd'
|
||
|
||
# Basic directory operations
|
||
alias ...='cd ../..'
|
||
alias -- -='cd -'
|
||
|
||
# Super user
|
||
alias _='sudo'
|
||
alias please='sudo'
|
||
|
||
#alias g='grep -in'
|
||
|
||
# Show history
|
||
if [ "$HIST_STAMPS" = "mm/dd/yyyy" ]
|
||
then
|
||
alias history='fc -fl 1'
|
||
elif [ "$HIST_STAMPS" = "dd.mm.yyyy" ]
|
||
then
|
||
alias history='fc -El 1'
|
||
elif [ "$HIST_STAMPS" = "yyyy-mm-dd" ]
|
||
then
|
||
alias history='fc -il 1'
|
||
else
|
||
alias history='fc -l 1'
|
||
fi
|
||
|
||
# List direcory contents
|
||
alias lsa='ls -lAh'
|
||
alias l='ls -lAh'
|
||
alias ll='ls -lh'
|
||
alias la='ls -lAh'
|
||
alias sl=ls # often screw this up
|
||
|
||
alias afind='ack-grep -il'
|
||
|
||
## 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
|
||
}
|
||
|
||
# fixme - the load process here seems a bit bizarre
|
||
|
||
unsetopt menu_complete # do not autoselect the first completion entry
|
||
unsetopt flowcontrol
|
||
setopt auto_menu # show completion menu on succesive tab press
|
||
setopt complete_in_word
|
||
setopt always_to_end
|
||
|
||
WORDCHARS=''
|
||
|
||
zmodload -i zsh/complist
|
||
|
||
## case-insensitive (all),partial-word and then substring completion
|
||
if [ "x$CASE_SENSITIVE" = "xtrue" ]; then
|
||
zstyle ':completion:*' matcher-list 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
|
||
unset CASE_SENSITIVE
|
||
else
|
||
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
|
||
fi
|
||
|
||
zstyle ':completion:*' list-colors ''
|
||
|
||
# should this be in keybindings?
|
||
bindkey -M menuselect '^o' accept-and-infer-next-history
|
||
|
||
zstyle ':completion:*:*:*:*:*' menu select
|
||
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
|
||
zstyle ':completion:*:*:*:*:processes' command "ps -u `whoami` -o pid,user,comm -w -w"
|
||
|
||
# disable named-directories autocompletion
|
||
zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories
|
||
cdpath=(.)
|
||
|
||
# Use caching so that commands like apt and dpkg complete are useable
|
||
zstyle ':completion::complete:*' use-cache 1
|
||
zstyle ':completion::complete:*' cache-path $ZSH/cache/
|
||
|
||
# Don't complete uninteresting users
|
||
zstyle ':completion:*:*:*:users' ignored-patterns \
|
||
adm amanda apache at avahi avahi-autoipd beaglidx bin cacti canna \
|
||
clamav daemon dbus distcache dnsmasq dovecot fax ftp games gdm \
|
||
gkrellmd gopher hacluster haldaemon halt hsqldb ident junkbust kdm \
|
||
ldap lp mail mailman mailnull man messagebus mldonkey mysql nagios \
|
||
named netdump news nfsnobody nobody nscd ntp nut nx obsrun openvpn \
|
||
operator pcap polkitd postfix postgres privoxy pulse pvm quagga radvd \
|
||
rpc rpcuser rpm rtkit scard shutdown squid sshd statd svn sync tftp \
|
||
usbmux uucp vcsa wwwrun xfs
|
||
|
||
# ... unless we really want to.
|
||
zstyle '*' single-ignored show
|
||
|
||
if [ "x$COMPLETION_WAITING_DOTS" = "xtrue" ]; then
|
||
expand-or-complete-with-dots() {
|
||
echo -n "\e[31m......\e[0m"
|
||
zle expand-or-complete
|
||
zle redisplay
|
||
}
|
||
zle -N expand-or-complete-with-dots
|
||
bindkey "^I" expand-or-complete-with-dots
|
||
fi
|
||
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'
|
||
|
||
if [[ "$ENABLE_CORRECTION" == "true" ]]; then
|
||
setopt correct_all
|
||
fi
|
||
|
||
# Changing/making/removing directory
|
||
setopt auto_name_dirs
|
||
setopt auto_pushd
|
||
setopt pushd_ignore_dups
|
||
setopt pushdminus
|
||
|
||
alias ..='cd ..'
|
||
alias cd..='cd ..'
|
||
alias cd...='cd ../..'
|
||
alias cd....='cd ../../..'
|
||
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'
|
||
|
||
cd () {
|
||
if [[ "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
|
||
}
|
||
|
||
alias md='mkdir -p'
|
||
alias rd=rmdir
|
||
alias d='dirs -v | head -10'
|
||
function zsh_stats() {
|
||
fc -l 1 | 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 take() {
|
||
mkdir -p $1
|
||
cd $1
|
||
}
|
||
|
||
#
|
||
# Get the value of an alias.
|
||
#
|
||
# Arguments:
|
||
# 1. alias - The alias to get its value from
|
||
# STDOUT:
|
||
# The value of alias $1 (if it has one).
|
||
# Return value:
|
||
# 0 if the alias was found,
|
||
# 1 if it does not exist
|
||
#
|
||
function alias_value() {
|
||
alias "$1" | sed "s/^$1='\(.*\)'$/\1/"
|
||
test $(alias "$1")
|
||
}
|
||
|
||
#
|
||
# Try to get the value of an alias,
|
||
# otherwise return the input.
|
||
#
|
||
# Arguments:
|
||
# 1. alias - The alias to get its value from
|
||
# STDOUT:
|
||
# The value of alias $1, or $1 if there is no alias $1.
|
||
# Return value:
|
||
# Always 0
|
||
#
|
||
function try_alias_value() {
|
||
alias_value "$1" || echo "$1"
|
||
}
|
||
|
||
#
|
||
# Set variable "$1" to default value "$2" if "$1" is not yet defined.
|
||
#
|
||
# Arguments:
|
||
# 1. name - The variable to set
|
||
# 2. val - The default value
|
||
# Return value:
|
||
# 0 if the variable exists, 3 if it was set
|
||
#
|
||
function default() {
|
||
test `typeset +m "$1"` && return 0
|
||
typeset -g "$1"="$2" && return 3
|
||
}
|
||
|
||
#
|
||
# Set enviroment variable "$1" to default value "$2" if "$1" is not yet defined.
|
||
#
|
||
# Arguments:
|
||
# 1. name - The env variable to set
|
||
# 2. val - The default value
|
||
# Return value:
|
||
# 0 if the env variable exists, 3 if it was set
|
||
#
|
||
function env_default() {
|
||
env | grep -q "^$1=" && return 0
|
||
export "$1=$2" && return 3
|
||
}
|
||
# get the name of the branch we are on
|
||
function git_prompt_info() {
|
||
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() {
|
||
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 "$(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=$(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=$(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=$(command git status --porcelain -b 2> /dev/null)
|
||
STATUS=""
|
||
if $(echo "$INDEX" | grep -E '^\?\? ' &> /dev/null); then
|
||
STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$STATUS"
|
||
fi
|
||
if $(echo "$INDEX" | grep '^A ' &> /dev/null); then
|
||
STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"
|
||
elif $(echo "$INDEX" | grep '^M ' &> /dev/null); then
|
||
STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"
|
||
fi
|
||
if $(echo "$INDEX" | grep '^ M ' &> /dev/null); then
|
||
STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
|
||
elif $(echo "$INDEX" | grep '^AM ' &> /dev/null); then
|
||
STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
|
||
elif $(echo "$INDEX" | grep '^ T ' &> /dev/null); then
|
||
STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
|
||
fi
|
||
if $(echo "$INDEX" | grep '^R ' &> /dev/null); then
|
||
STATUS="$ZSH_THEME_GIT_PROMPT_RENAMED$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
|
||
|
||
|
||
#
|
||
# Color grep results
|
||
# Examples: http://rubyurl.com/ZXv
|
||
#
|
||
|
||
GREP_OPTIONS="--color=auto"
|
||
|
||
# avoid VCS folders (if the necessary grep flags are available)
|
||
grep-flag-available() {
|
||
echo | grep $1 "" >/dev/null 2>&1
|
||
}
|
||
if grep-flag-available --exclude-dir=.cvs; then
|
||
for PATTERN in .cvs .git .hg .svn; do
|
||
GREP_OPTIONS+=" --exclude-dir=$PATTERN"
|
||
done
|
||
elif grep-flag-available --exclude=.cvs; then
|
||
for PATTERN in .cvs .git .hg .svn; do
|
||
GREP_OPTIONS+=" --exclude=$PATTERN"
|
||
done
|
||
fi
|
||
unfunction grep-flag-available
|
||
|
||
export GREP_OPTIONS="$GREP_OPTIONS"
|
||
export GREP_COLOR='1;32'
|
||
## Command history configuration
|
||
if [ -z $HISTFILE ]; then
|
||
HISTFILE=$HOME/.zsh_history
|
||
fi
|
||
HISTSIZE=10000
|
||
SAVEHIST=10000
|
||
|
||
setopt extended_history
|
||
setopt hist_expire_dups_first
|
||
setopt hist_ignore_dups # ignore duplication command history list
|
||
setopt hist_ignore_space
|
||
setopt hist_verify
|
||
setopt inc_append_history
|
||
setopt share_history # share command history data
|
||
# http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html
|
||
# http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Zle-Builtins
|
||
# http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Standard-Widgets
|
||
|
||
# Make sure that the terminal is in application mode when zle is active, since
|
||
# only then values from $terminfo are valid
|
||
if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
|
||
function zle-line-init() {
|
||
echoti smkx
|
||
}
|
||
function zle-line-finish() {
|
||
echoti rmkx
|
||
}
|
||
zle -N zle-line-init
|
||
zle -N zle-line-finish
|
||
fi
|
||
|
||
bindkey -e # Use emacs key bindings
|
||
|
||
bindkey '\ew' kill-region # [Esc-w] - Kill from the cursor to the mark
|
||
bindkey -s '\el' 'ls\n' # [Esc-l] - run command: ls
|
||
bindkey '^r' history-incremental-search-backward # [Ctrl-r] - Search backward incrementally for a specified string. The string may begin with ^ to anchor the search to the beginning of the line.
|
||
if [[ "${terminfo[kpp]}" != "" ]]; then
|
||
bindkey "${terminfo[kpp]}" up-line-or-history # [PageUp] - Up a line of history
|
||
fi
|
||
if [[ "${terminfo[knp]}" != "" ]]; then
|
||
bindkey "${terminfo[knp]}" down-line-or-history # [PageDown] - Down a line of history
|
||
fi
|
||
|
||
if [[ "${terminfo[kcuu1]}" != "" ]]; then
|
||
bindkey "${terminfo[kcuu1]}" up-line-or-search # start typing + [Up-Arrow] - fuzzy find history forward
|
||
fi
|
||
if [[ "${terminfo[kcud1]}" != "" ]]; then
|
||
bindkey "${terminfo[kcud1]}" down-line-or-search # start typing + [Down-Arrow] - fuzzy find history backward
|
||
fi
|
||
|
||
if [[ "${terminfo[khome]}" != "" ]]; then
|
||
bindkey "${terminfo[khome]}" beginning-of-line # [Home] - Go to beginning of line
|
||
fi
|
||
if [[ "${terminfo[kend]}" != "" ]]; then
|
||
bindkey "${terminfo[kend]}" end-of-line # [End] - Go to end of line
|
||
fi
|
||
|
||
bindkey ' ' magic-space # [Space] - do history expansion
|
||
|
||
bindkey '^[[1;5C' forward-word # [Ctrl-RightArrow] - move forward one word
|
||
bindkey '^[[1;5D' backward-word # [Ctrl-LeftArrow] - move backward one word
|
||
|
||
if [[ "${terminfo[kcbt]}" != "" ]]; then
|
||
bindkey "${terminfo[kcbt]}" reverse-menu-complete # [Shift-Tab] - move through the completion menu backwards
|
||
fi
|
||
|
||
bindkey '^?' backward-delete-char # [Backspace] - delete backward
|
||
if [[ "${terminfo[kdch1]}" != "" ]]; then
|
||
bindkey "${terminfo[kdch1]}" delete-char # [Delete] - delete forward
|
||
else
|
||
bindkey "^[[3~" delete-char
|
||
bindkey "^[3;5~" delete-char
|
||
bindkey "\e[3~" delete-char
|
||
fi
|
||
|
||
# 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
|
||
#
|
||
#bindkey '^[[A' up-line-or-search
|
||
#bindkey '^[[B' down-line-or-search
|
||
#bindkey '^[^[[C' emacs-forward-word
|
||
#bindkey '^[^[[D' emacs-backward-word
|
||
#
|
||
#bindkey -s '^X^Z' '%-^M'
|
||
#bindkey '^[e' expand-cmd-path
|
||
#bindkey '^[^I' reverse-menu-complete
|
||
#bindkey '^X^N' accept-and-infer-next-history
|
||
#bindkey '^W' kill-region
|
||
#bindkey '^I' complete-word
|
||
## Fix weird sequence that rxvt produces
|
||
#bindkey -s '^[[Z' '\t'
|
||
#
|
||
## smart urls
|
||
autoload -U url-quote-magic
|
||
zle -N self-insert url-quote-magic
|
||
|
||
## file rename magick
|
||
bindkey "^[m" copy-prev-shell-word
|
||
|
||
## jobs
|
||
setopt long_list_jobs
|
||
|
||
## pager
|
||
export PAGER="less"
|
||
export LESS="-R"
|
||
|
||
export LC_CTYPE=$LANG
|
||
# 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}"
|
||
}
|
||
# *_prompt_info functions for usage in your prompt
|
||
#
|
||
# Plugin creators, please add your *_prompt_info function to the list
|
||
# of dummy implementations to help theme creators not receiving errors
|
||
# without the need of implementing conditional clauses.
|
||
#
|
||
# See also lib/bzr.zsh, lib/git.zsh and lib/nvm.zsh for
|
||
# git_prompt_info, bzr_prompt_info and nvm_prompt_info
|
||
|
||
# Dummy implementations that return false to prevent command_not_found
|
||
# errors with themes, that implement these functions
|
||
# Real implementations will be used when the respective plugins are loaded
|
||
function chruby_prompt_info hg_prompt_info pyenv_prompt_info \
|
||
rbenv_prompt_info svn_prompt_info vi_mode_prompt_info \
|
||
virtualenv_prompt_info {
|
||
return 1
|
||
}
|
||
|
||
# oh-my-zsh supports an rvm prompt by default
|
||
# get the name of the rvm ruby version
|
||
function rvm_prompt_info() {
|
||
[ -f $HOME/.rvm/bin/rvm-prompt ] || return 1
|
||
local rvm_prompt
|
||
rvm_prompt=$($HOME/.rvm/bin/rvm-prompt ${=ZSH_THEME_RVM_PROMPT_OPTIONS} 2>/dev/null)
|
||
[[ "${rvm_prompt}x" == "x" ]] && return 1
|
||
echo "${ZSH_THEME_RVM_PROMPT_PREFIX:=(}${rvm_prompt}${ZSH_THEME_RVM_PROMPT_SUFFIX:=)}"
|
||
}
|
||
|
||
# use this to enable users to see their ruby version, no matter which
|
||
# version management system they use
|
||
function ruby_prompt_info() {
|
||
echo $(rvm_prompt_info || rbenv_prompt_info || chruby_prompt_info)
|
||
}
|
||
#! /bin/zsh
|
||
# A script to make using 256 colors in zsh less painful.
|
||
# P.C. Shyamshankar <sykora@lucentbeing.com>
|
||
# Copied from http://github.com/sykora/etc/blob/master/zsh/functions/spectrum/
|
||
|
||
typeset -Ag FX FG BG
|
||
|
||
FX=(
|
||
reset "%{[00m%}"
|
||
bold "%{[01m%}" no-bold "%{[22m%}"
|
||
italic "%{[03m%}" no-italic "%{[23m%}"
|
||
underline "%{[04m%}" no-underline "%{[24m%}"
|
||
blink "%{[05m%}" no-blink "%{[25m%}"
|
||
reverse "%{[07m%}" no-reverse "%{[27m%}"
|
||
)
|
||
|
||
for color in {000..255}; do
|
||
FG[$color]="%{[38;5;${color}m%}"
|
||
BG[$color]="%{[48;5;${color}m%}"
|
||
done
|
||
|
||
|
||
ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris}
|
||
|
||
# Show all 256 colors with color number
|
||
function spectrum_ls() {
|
||
for code in {000..255}; do
|
||
print -P -- "$code: %F{$code}$ZSH_SPECTRUM_TEXT%f"
|
||
done
|
||
}
|
||
|
||
# Show all 256 colors where the background is set to specific color
|
||
function spectrum_bls() {
|
||
for code in {000..255}; do
|
||
print -P -- "$BG[$code]$code: $ZSH_SPECTRUM_TEXT %{$reset_color%}"
|
||
done
|
||
}
|
||
#usage: title short_tab_title looooooooooooooooooooooggggggg_windows_title
|
||
#http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1
|
||
#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 {
|
||
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 == 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
|
||
}
|
||
|
||
ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD
|
||
ZSH_THEME_TERM_TITLE_IDLE="%n@%m: %~"
|
||
|
||
#Appears when you have the prompt
|
||
function omz_termsupport_precmd {
|
||
title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE
|
||
}
|
||
|
||
#Appears at the beginning of (and during) of command execution
|
||
function omz_termsupport_preexec {
|
||
emulate -L zsh
|
||
setopt extended_glob
|
||
|
||
local CMD=${1[(wr)^(*=*|sudo|ssh|rake|-*)]} #cmd name only, or if this is sudo or ssh, the next cmd
|
||
local LINE="${2:gs/%/%%}"
|
||
title '$CMD' '%100>...>$LINE%<<'
|
||
}
|
||
|
||
autoload -U add-zsh-hook
|
||
add-zsh-hook precmd omz_termsupport_precmd
|
||
add-zsh-hook preexec omz_termsupport_preexec
|
||
# ls colors
|
||
autoload colors; colors;
|
||
export LSCOLORS="Gxfxcxdxbxegedabagacad"
|
||
#export LS_COLORS
|
||
|
||
# Enable ls colors
|
||
if [ "$DISABLE_LS_COLORS" != "true" ]
|
||
then
|
||
# Find the option for using colors in ls, depending on the version: Linux or BSD
|
||
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
|
||
setopt auto_cd
|
||
setopt multios
|
||
setopt cdablevarS
|
||
|
||
if [[ x$WINDOW != x ]]
|
||
then
|
||
SCREEN_NO="%B$WINDOW%b "
|
||
else
|
||
SCREEN_NO=""
|
||
fi
|
||
|
||
# Apply theming defaults
|
||
PS1="%n@%m:%~%# "
|
||
|
||
# git theming default: Variables for theming the git info prompt
|
||
ZSH_THEME_GIT_PROMPT_PREFIX="git:(" # Prefix at the very beginning of the prompt, before the branch name
|
||
ZSH_THEME_GIT_PROMPT_SUFFIX=")" # At the very end of the prompt
|
||
ZSH_THEME_GIT_PROMPT_DIRTY="*" # Text to display if the branch is dirty
|
||
ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is clean
|
||
|
||
# Setup the prompt with pretty colors
|
||
setopt prompt_subst
|
||
|
||
local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ %s)"
|
||
PROMPT='%{$fg_bold[green]%}± %{$fg[magenta]%}%n@%m%{$reset_color%}:%{$fg[green]%}%~
|
||
%{$fg_bold[magenta]%}$(git_prompt_info)$(git_prompt_status) %{$fg_bold[magenta]%}%{$fg[yellow]%}» % %{$reset_color%}'
|
||
|
||
ZSH_THEME_GIT_PROMPT_PREFIX="git:(%{$fg[yellow]%}"
|
||
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
|
||
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[magenta]%}) %{$fg[magenta]%}✗%{$reset_color%} "
|
||
#ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[magenta]%}) "
|
||
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[magenta]%})"
|
||
|
||
ZSH_THEME_GIT_PROMPT_ADDED=" %{$fg_bold[yellow]%}+"
|
||
ZSH_THEME_GIT_PROMPT_MODIFIED="%{$fg_bold[green]%}!"
|
||
ZSH_THEME_GIT_PROMPT_DELETED="%{$fg_bold[red]%}-"
|
||
ZSH_THEME_GIT_PROMPT_RENAMED="%{$fg_bold[cyan]%}>"
|
||
ZSH_THEME_GIT_PROMPT_UNMERGED="%{$fg_bold[blue]%}#"
|
||
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg_bold[magenta]%}?"
|