summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/aliases.zsh36
-rw-r--r--lib/clipboard.zsh86
-rw-r--r--lib/compfix.zsh60
-rw-r--r--lib/completion.zsh56
-rw-r--r--lib/correction.zsh20
-rw-r--r--lib/diagnostics.zsh353
-rw-r--r--lib/directories.zsh39
-rw-r--r--lib/functions.zsh168
-rw-r--r--lib/git.zsh147
-rw-r--r--lib/grep.zsh34
-rw-r--r--lib/history.zsh11
-rw-r--r--lib/key-bindings.zsh100
-rw-r--r--lib/misc.zsh41
-rw-r--r--lib/nvm.zsh2
-rw-r--r--lib/prompt_info_functions.zsh33
-rw-r--r--lib/rbenv.zsh2
-rw-r--r--lib/rvm.zsh8
-rw-r--r--lib/spectrum.zsh10
-rw-r--r--lib/termsupport.zsh112
-rw-r--r--lib/theme-and-appearance.zsh15
20 files changed, 1091 insertions, 242 deletions
diff --git a/lib/aliases.zsh b/lib/aliases.zsh
deleted file mode 100644
index b279bf855..000000000
--- a/lib/aliases.zsh
+++ /dev/null
@@ -1,36 +0,0 @@
-# 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 -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/clipboard.zsh b/lib/clipboard.zsh
new file mode 100644
index 000000000..b663800a4
--- /dev/null
+++ b/lib/clipboard.zsh
@@ -0,0 +1,86 @@
+# System clipboard integration
+#
+# This file has support for doing system clipboard copy and paste operations
+# from the command line in a generic cross-platform fashion.
+#
+# On OS X and Windows, the main system clipboard or "pasteboard" is used. On other
+# Unix-like OSes, this considers the X Windows CLIPBOARD selection to be the
+# "system clipboard", and the X Windows `xclip` command must be installed.
+
+# clipcopy - Copy data to clipboard
+#
+# Usage:
+#
+# <command> | clipcopy - copies stdin to clipboard
+#
+# clipcopy <file> - copies a file's contents to clipboard
+#
+function clipcopy() {
+ emulate -L zsh
+ local file=$1
+ if [[ $OSTYPE == darwin* ]]; then
+ if [[ -z $file ]]; then
+ pbcopy
+ else
+ cat $file | pbcopy
+ fi
+ elif [[ $OSTYPE == cygwin* ]]; then
+ if [[ -z $file ]]; then
+ cat > /dev/clipboard
+ else
+ cat $file > /dev/clipboard
+ fi
+ else
+ if which xclip &>/dev/null; then
+ if [[ -z $file ]]; then
+ xclip -in -selection clipboard
+ else
+ xclip -in -selection clipboard $file
+ fi
+ elif which xsel &>/dev/null; then
+ if [[ -z $file ]]; then
+ xsel --clipboard --input
+ else
+ cat "$file" | xsel --clipboard --input
+ fi
+ else
+ print "clipcopy: Platform $OSTYPE not supported or xclip/xsel not installed" >&2
+ return 1
+ fi
+ fi
+}
+
+# clippaste - "Paste" data from clipboard to stdout
+#
+# Usage:
+#
+# clippaste - writes clipboard's contents to stdout
+#
+# clippaste | <command> - pastes contents and pipes it to another process
+#
+# clippaste > <file> - paste contents to a file
+#
+# Examples:
+#
+# # Pipe to another process
+# clippaste | grep foo
+#
+# # Paste to a file
+# clippaste > file.txt
+function clippaste() {
+ emulate -L zsh
+ if [[ $OSTYPE == darwin* ]]; then
+ pbpaste
+ elif [[ $OSTYPE == cygwin* ]]; then
+ cat /dev/clipboard
+ else
+ if which xclip &>/dev/null; then
+ xclip -out -selection clipboard
+ elif which xsel &>/dev/null; then
+ xsel --clipboard --output
+ else
+ print "clipcopy: Platform $OSTYPE not supported or xclip/xsel not installed" >&2
+ return 1
+ fi
+ fi
+}
diff --git a/lib/compfix.zsh b/lib/compfix.zsh
new file mode 100644
index 000000000..208aaadb1
--- /dev/null
+++ b/lib/compfix.zsh
@@ -0,0 +1,60 @@
+# Handle completions insecurities (i.e., completion-dependent directories with
+# insecure ownership or permissions) by:
+#
+# * Human-readably notifying the user of these insecurities.
+# * Moving away all existing completion caches to a temporary directory. Since
+# any of these caches may have been generated from insecure directories, they
+# are all suspect now. Failing to do so typically causes subsequent compinit()
+# calls to fail with "command not found: compdef" errors. (That's bad.)
+function handle_completion_insecurities() {
+ # List of the absolute paths of all unique insecure directories, split on
+ # newline from compaudit()'s output resembling:
+ #
+ # There are insecure directories:
+ # /usr/share/zsh/site-functions
+ # /usr/share/zsh/5.0.6/functions
+ # /usr/share/zsh
+ # /usr/share/zsh/5.0.6
+ #
+ # Since the ignorable first line is printed to stderr and thus not captured,
+ # stderr is squelched to prevent this output from leaking to the user.
+ local -aU insecure_dirs
+ insecure_dirs=( ${(f@):-"$(compaudit 2>/dev/null)"} )
+
+ # If no such directories exist, get us out of here.
+ if (( ! ${#insecure_dirs} )); then
+ print "[oh-my-zsh] No insecure completion-dependent directories detected."
+ return
+ fi
+
+ # List ownership and permissions of all insecure directories.
+ print "[oh-my-zsh] Insecure completion-dependent directories detected:"
+ ls -ld "${(@)insecure_dirs}"
+ print "[oh-my-zsh] For safety, completions will be disabled until you manually fix all"
+ print "[oh-my-zsh] insecure directory permissions and ownership and restart oh-my-zsh."
+ print "[oh-my-zsh] See the above list for directories with group or other writability.\n"
+
+ # Locally enable the "NULL_GLOB" option, thus removing unmatched filename
+ # globs from argument lists *AND* printing no warning when doing so. Failing
+ # to do so prints an unreadable warning if no completion caches exist below.
+ setopt local_options null_glob
+
+ # List of the absolute paths of all unique existing completion caches.
+ local -aU zcompdump_files
+ zcompdump_files=( "${ZSH_COMPDUMP}"(.) "${ZDOTDIR:-${HOME}}"/.zcompdump* )
+
+ # Move such caches to a temporary directory.
+ if (( ${#zcompdump_files} )); then
+ # Absolute path of the directory to which such files will be moved.
+ local ZSH_ZCOMPDUMP_BAD_DIR="${ZSH_CACHE_DIR}/zcompdump-bad"
+
+ # List such files first.
+ print "[oh-my-zsh] Insecure completion caches also detected:"
+ ls -l "${(@)zcompdump_files}"
+
+ # For safety, move rather than permanently remove such files.
+ print "[oh-my-zsh] Moving to \"${ZSH_ZCOMPDUMP_BAD_DIR}/\"...\n"
+ mkdir -p "${ZSH_ZCOMPDUMP_BAD_DIR}"
+ mv "${(@)zcompdump_files}" "${ZSH_ZCOMPDUMP_BAD_DIR}/"
+ fi
+}
diff --git a/lib/completion.zsh b/lib/completion.zsh
index e0cdcf626..f5b292471 100644
--- a/lib/completion.zsh
+++ b/lib/completion.zsh
@@ -15,7 +15,12 @@ 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:|=*'
+ if [ "x$HYPHEN_INSENSITIVE" = "xtrue" ]; then
+ zstyle ':completion:*' matcher-list 'm:{a-zA-Z-_}={A-Za-z_-}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
+ unset HYPHEN_INSENSITIVE
+ else
+ zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
+ fi
fi
zstyle ':completion:*' list-colors ''
@@ -25,48 +30,41 @@ 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"
+if [ "$OSTYPE[0,7]" = "solaris" ]
+then
+ zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm"
+else
+ zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm -w -w"
+fi
# disable named-directories autocompletion
zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories
-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)"}:#[\|]*}%%\ *}%%,*}) || _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[@]"
- "$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 $ZSH/cache/
+zstyle ':completion::complete:*' cache-path $ZSH_CACHE_DIR
# Don't complete uninteresting users
zstyle ':completion:*:*:*:users' ignored-patterns \
- adm amanda apache avahi beaglidx bin cacti canna clamav daemon \
- dbus distcache dovecot fax ftp games gdm gkrellmd gopher \
- hacluster haldaemon halt hsqldb ident junkbust ldap lp mail \
- mailman mailnull mldonkey mysql nagios \
- named netdump news nfsnobody nobody nscd ntp nut nx openvpn \
- operator pcap postfix postgres privoxy pulse pvm quagga radvd \
- rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs
+ 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
+if [[ $COMPLETION_WAITING_DOTS = true ]]; then
expand-or-complete-with-dots() {
- echo -n "\e[31m......\e[0m"
+ # toggle line-wrapping off and back on again
+ [[ -n "$terminfo[rmam]" && -n "$terminfo[smam]" ]] && echoti rmam
+ print -Pn "%{%F{red}......%f%}"
+ [[ -n "$terminfo[rmam]" && -n "$terminfo[smam]" ]] && echoti smam
+
zle expand-or-complete
zle redisplay
}
diff --git a/lib/correction.zsh b/lib/correction.zsh
index 47eb83b1d..3e1415a0b 100644
--- a/lib/correction.zsh
+++ b/lib/correction.zsh
@@ -1,13 +1,13 @@
-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
+ alias ebuild='nocorrect ebuild'
+ alias gist='nocorrect gist'
+ alias heroku='nocorrect heroku'
+ alias hpodder='nocorrect hpodder'
+ alias man='nocorrect man'
+ alias mkdir='nocorrect mkdir'
+ alias mv='nocorrect mv'
+ alias mysql='nocorrect mysql'
+ alias sudo='nocorrect sudo'
+
setopt correct_all
fi
diff --git a/lib/diagnostics.zsh b/lib/diagnostics.zsh
new file mode 100644
index 000000000..9c9905e4d
--- /dev/null
+++ b/lib/diagnostics.zsh
@@ -0,0 +1,353 @@
+# diagnostics.zsh
+#
+# Diagnostic and debugging support for oh-my-zsh
+
+# omz_diagnostic_dump()
+#
+# Author: Andrew Janke <andrew@apjanke.net>
+#
+# Usage:
+#
+# omz_diagnostic_dump [-v] [-V] [file]
+#
+# NOTE: This is a work in progress. Its interface and behavior are going to change,
+# and probably in non-back-compatible ways.
+#
+# Outputs a bunch of information about the state and configuration of
+# oh-my-zsh, zsh, and the user's system. This is intended to provide a
+# bunch of context for diagnosing your own or a third party's problems, and to
+# be suitable for posting to public bug reports.
+#
+# The output is human-readable and its format may change over time. It is not
+# suitable for parsing. All the output is in one single file so it can be posted
+# as a gist or bug comment on GitHub. GitHub doesn't support attaching tarballs
+# or other files to bugs; otherwise, this would probably have an option to produce
+# tarballs that contain copies of the config and customization files instead of
+# catting them all in to one file.
+#
+# This is intended to be widely portable, and run anywhere that oh-my-zsh does.
+# Feel free to report any portability issues as bugs.
+#
+# This is written in a defensive style so it still works (and can detect) cases when
+# basic functionality like echo and which have been redefined. In particular, almost
+# everything is invoked with "builtin" or "command", to work in the face of user
+# redefinitions.
+#
+# OPTIONS
+#
+# [file] Specifies the output file. If not given, a file in the current directory
+# is selected automatically.
+#
+# -v Increase the verbosity of the dump output. May be specified multiple times.
+# Verbosity levels:
+# 0 - Basic info, shell state, omz configuration, git state
+# 1 - (default) Adds key binding info and configuration file contents
+# 2 - Adds zcompdump file contents
+#
+# -V Reduce the verbosity of the dump output. May be specified multiple times.
+#
+# TODO:
+# * Multi-file capture
+# * Add automatic gist uploading
+# * Consider whether to move default output file location to TMPDIR. More robust
+# but less user friendly.
+#
+
+autoload -Uz is-at-least
+
+function omz_diagnostic_dump() {
+ emulate -L zsh
+
+ builtin echo "Generating diagnostic dump; please be patient..."
+
+ local thisfcn=omz_diagnostic_dump
+ local -A opts
+ local opt_verbose opt_noverbose opt_outfile
+ local timestamp=$(date +%Y%m%d-%H%M%S)
+ local outfile=omz_diagdump_$timestamp.txt
+ builtin zparseopts -A opts -D -- "v+=opt_verbose" "V+=opt_noverbose"
+ local verbose n_verbose=${#opt_verbose} n_noverbose=${#opt_noverbose}
+ (( verbose = 1 + n_verbose - n_noverbose ))
+
+ if [[ ${#*} > 0 ]]; then
+ opt_outfile=$1
+ fi
+ if [[ ${#*} > 1 ]]; then
+ builtin echo "$thisfcn: error: too many arguments" >&2
+ return 1
+ fi
+ if [[ -n "$opt_outfile" ]]; then
+ outfile="$opt_outfile"
+ fi
+
+ # Always write directly to a file so terminal escape sequences are
+ # captured cleanly
+ _omz_diag_dump_one_big_text &> "$outfile"
+ if [[ $? != 0 ]]; then
+ builtin echo "$thisfcn: error while creating diagnostic dump; see $outfile for details"
+ fi
+
+ builtin echo
+ builtin echo Diagnostic dump file created at: "$outfile"
+ builtin echo
+ builtin echo To share this with OMZ developers, post it as a gist on GitHub
+ builtin echo at "https://gist.github.com" and share the link to the gist.
+ builtin echo
+ builtin echo "WARNING: This dump file contains all your zsh and omz configuration files,"
+ builtin echo "so don't share it publicly if there's sensitive information in them."
+ builtin echo
+
+}
+
+function _omz_diag_dump_one_big_text() {
+ local program programs progfile md5
+
+ builtin echo oh-my-zsh diagnostic dump
+ builtin echo
+ builtin echo $outfile
+ builtin echo
+
+ # Basic system and zsh information
+ command date
+ command uname -a
+ builtin echo OSTYPE=$OSTYPE
+ builtin echo ZSH_VERSION=$ZSH_VERSION
+ builtin echo User: $USER
+ builtin echo umask: $(umask)
+ builtin echo
+ _omz_diag_dump_os_specific_version
+ builtin echo
+
+ # Installed programs
+ programs=(sh zsh ksh bash sed cat grep ls find git posh)
+ local progfile="" extra_str="" sha_str=""
+ for program in $programs; do
+ extra_str="" sha_str=""
+ progfile=$(builtin which $program)
+ if [[ $? == 0 ]]; then
+ if [[ -e $progfile ]]; then
+ if builtin whence shasum &>/dev/null; then
+ sha_str=($(command shasum $progfile))
+ sha_str=$sha_str[1]
+ extra_str+=" SHA $sha_str"
+ fi
+ if [[ -h "$progfile" ]]; then
+ extra_str+=" ( -> ${progfile:A} )"
+ fi
+ fi
+ builtin printf '%-9s %-20s %s\n' "$program is" "$progfile" "$extra_str"
+ else
+ builtin echo "$program: not found"
+ fi
+ done
+ builtin echo
+ builtin echo Command Versions:
+ builtin echo "zsh: $(zsh --version)"
+ builtin echo "this zsh session: $ZSH_VERSION"
+ builtin echo "bash: $(bash --version | command grep bash)"
+ builtin echo "git: $(git --version)"
+ builtin echo "grep: $(grep --version)"
+ builtin echo
+
+ # Core command definitions
+ _omz_diag_dump_check_core_commands || return 1
+ builtin echo
+
+ # ZSH Process state
+ builtin echo Process state:
+ builtin echo pwd: $PWD
+ if builtin whence pstree &>/dev/null; then
+ builtin echo Process tree for this shell:
+ pstree -p $$
+ else
+ ps -fT
+ fi
+ builtin set | command grep -a '^\(ZSH\|plugins\|TERM\|LC_\|LANG\|precmd\|chpwd\|preexec\|FPATH\|TTY\|DISPLAY\|PATH\)\|OMZ'
+ builtin echo
+ #TODO: Should this include `env` instead of or in addition to `export`?
+ builtin echo Exported:
+ builtin echo $(builtin export | command sed 's/=.*//')
+ builtin echo
+ builtin echo Locale:
+ command locale
+ builtin echo
+
+ # Zsh installation and configuration
+ builtin echo Zsh configuration:
+ builtin echo setopt: $(builtin setopt)
+ builtin echo
+ builtin echo zstyle:
+ builtin zstyle
+ builtin echo
+ builtin echo 'compaudit output:'
+ compaudit
+ builtin echo
+ builtin echo '$fpath directories:'
+ command ls -lad $fpath
+ builtin echo
+
+ # Oh-my-zsh installation
+ builtin echo oh-my-zsh installation:
+ command ls -ld ~/.z*
+ command ls -ld ~/.oh*
+ builtin echo
+ builtin echo oh-my-zsh git state:
+ (cd $ZSH && builtin echo "HEAD: $(git rev-parse HEAD)" && git remote -v && git status | command grep "[^[:space:]]")
+ if [[ $verbose -ge 1 ]]; then
+ (cd $ZSH && git reflog --date=default | command grep pull)
+ fi
+ builtin echo
+ if [[ -e $ZSH_CUSTOM ]]; then
+ local custom_dir=$ZSH_CUSTOM
+ if [[ -h $custom_dir ]]; then
+ custom_dir=$(cd $custom_dir && pwd -P)
+ fi
+ builtin echo "oh-my-zsh custom dir:"
+ builtin echo " $ZSH_CUSTOM ($custom_dir)"
+ (cd ${custom_dir:h} && command find ${custom_dir:t} -name .git -prune -o -print)
+ builtin echo
+ fi
+
+ # Key binding and terminal info
+ if [[ $verbose -ge 1 ]]; then
+ builtin echo "bindkey:"
+ builtin bindkey
+ builtin echo
+ builtin echo "infocmp:"
+ command infocmp -L
+ builtin echo
+ fi
+
+ # Configuration file info
+ local zdotdir=${ZDOTDIR:-$HOME}
+ builtin echo "Zsh configuration files:"
+ local cfgfile cfgfiles
+ # Some files for bash that zsh does not use are intentionally included
+ # to help with diagnosing behavior differences between bash and zsh
+ cfgfiles=( /etc/zshenv /etc/zprofile /etc/zshrc /etc/zlogin /etc/zlogout
+ $zdotdir/.zshenv $zdotdir/.zprofile $zdotdir/.zshrc $zdotdir/.zlogin $zdotdir/.zlogout
+ ~/.zsh.pre-oh-my-zsh
+ /etc/bashrc /etc/profile ~/.bashrc ~/.profile ~/.bash_profile ~/.bash_logout )
+ command ls -lad $cfgfiles 2>&1
+ builtin echo
+ if [[ $verbose -ge 1 ]]; then
+ for cfgfile in $cfgfiles; do
+ _omz_diag_dump_echo_file_w_header $cfgfile
+ done
+ fi
+ builtin echo
+ builtin echo "Zsh compdump files:"
+ local dumpfile dumpfiles
+ command ls -lad $zdotdir/.zcompdump*
+ dumpfiles=( $zdotdir/.zcompdump*(N) )
+ if [[ $verbose -ge 2 ]]; then
+ for dumpfile in $dumpfiles; do
+ _omz_diag_dump_echo_file_w_header $dumpfile
+ done
+ fi
+
+}
+
+function _omz_diag_dump_check_core_commands() {
+ builtin echo "Core command check:"
+ local redefined name builtins externals reserved_words
+ redefined=()
+ # All the zsh non-module builtin commands
+ # These are taken from the zsh reference manual for 5.0.2
+ # Commands from modules should not be included.
+ # (For back-compatibility, if any of these are newish, they should be removed,
+ # or at least made conditional on the version of the current running zsh.)
+ # "history" is also excluded because OMZ is known to redefine that
+ reserved_words=( do done esac then elif else fi for case if while function
+ repeat time until select coproc nocorrect foreach end '!' '[[' '{' '}'
+ )
+ builtins=( alias autoload bg bindkey break builtin bye cd chdir command
+ comparguments compcall compctl compdescribe compfiles compgroups compquote comptags
+ comptry compvalues continue dirs disable disown echo echotc echoti emulate
+ enable eval exec exit false fc fg functions getln getopts hash
+ jobs kill let limit log logout noglob popd print printf
+ pushd pushln pwd r read rehash return sched set setopt shift
+ source suspend test times trap true ttyctl type ulimit umask unalias
+ unfunction unhash unlimit unset unsetopt vared wait whence where which zcompile
+ zle zmodload zparseopts zregexparse zstyle )
+ if is-at-least 5.1; then
+ reserved_word+=( declare export integer float local readonly typeset )
+ else
+ builtins+=( declare export integer float local readonly typeset )
+ fi
+ builtins_fatal=( builtin command local )
+ externals=( zsh )
+ for name in $reserved_words; do
+ if [[ $(builtin whence -w $name) != "$name: reserved" ]]; then
+ builtin echo "reserved word '$name' has been redefined"
+ builtin which $name
+ redefined+=$name
+ fi
+ done
+ for name in $builtins; do
+ if [[ $(builtin whence -w $name) != "$name: builtin" ]]; then
+ builtin echo "builtin '$name' has been redefined"
+ builtin which $name
+ redefined+=$name
+ fi
+ done
+ for name in $externals; do
+ if [[ $(builtin whence -w $name) != "$name: command" ]]; then
+ builtin echo "command '$name' has been redefined"
+ builtin which $name
+ redefined+=$name
+ fi
+ done
+
+ if [[ -n "$redefined" ]]; then
+ builtin echo "SOME CORE COMMANDS HAVE BEEN REDEFINED: $redefined"
+ else
+ builtin echo "All core commands are defined normally"
+ fi
+
+}
+
+function _omz_diag_dump_echo_file_w_header() {
+ local file=$1
+ if [[ ( -f $file || -h $file ) ]]; then
+ builtin echo "========== $file =========="
+ if [[ -h $file ]]; then
+ builtin echo "========== ( => ${file:A} ) =========="
+ fi
+ command cat $file
+ builtin echo "========== end $file =========="
+ builtin echo
+ elif [[ -d $file ]]; then
+ builtin echo "File '$file' is a directory"
+ elif [[ ! -e $file ]]; then
+ builtin echo "File '$file' does not exist"
+ else
+ command ls -lad "$file"
+ fi
+}
+
+function _omz_diag_dump_os_specific_version() {
+ local osname osver version_file version_files
+ case "$OSTYPE" in
+ darwin*)
+ osname=$(command sw_vers -productName)
+ osver=$(command sw_vers -productVersion)
+ builtin echo "OS Version: $osname $osver build $(sw_vers -buildVersion)"
+ ;;
+ cygwin)
+ command systeminfo | command head -4 | command tail -2
+ ;;
+ esac
+
+ if builtin which lsb_release >/dev/null; then
+ builtin echo "OS Release: $(command lsb_release -s -d)"
+ fi
+
+ version_files=( /etc/*-release(N) /etc/*-version(N) /etc/*_version(N) )
+ for version_file in $version_files; do
+ builtin echo "$version_file:"
+ command cat "$version_file"
+ builtin echo
+ done
+}
+
diff --git a/lib/directories.zsh b/lib/directories.zsh
index 1896945f4..a50a692c8 100644
--- a/lib/directories.zsh
+++ b/lib/directories.zsh
@@ -1,16 +1,14 @@
# 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 -g ...='../..'
+alias -g ....='../../..'
+alias -g .....='../../../..'
+alias -g ......='../../../../..'
+alias -- -='cd -'
alias 1='cd -'
alias 2='cd -2'
alias 3='cd -3'
@@ -21,23 +19,16 @@ 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'
+
+# List directory contents
+alias lsa='ls -lah'
+alias l='ls -lah'
+alias ll='ls -lh'
+alias la='ls -lAh'
+
+# Push and pop directories on directory stack
+alias pu='pushd'
+alias po='popd'
diff --git a/lib/functions.zsh b/lib/functions.zsh
index aaf8a03e3..f9d4a9717 100644
--- a/lib/functions.zsh
+++ b/lib/functions.zsh
@@ -1,13 +1,13 @@
function zsh_stats() {
- 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
+ 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 uninstall_oh_my_zsh() {
- /usr/bin/env ZSH=$ZSH /bin/sh $ZSH/tools/uninstall.sh
+ env ZSH=$ZSH /bin/sh $ZSH/tools/uninstall.sh
}
function upgrade_oh_my_zsh() {
- /usr/bin/env ZSH=$ZSH /bin/sh $ZSH/tools/upgrade.sh
+ env ZSH=$ZSH /bin/sh $ZSH/tools/upgrade.sh
}
function take() {
@@ -15,6 +15,31 @@ function take() {
cd $1
}
+function open_command() {
+ emulate -L zsh
+ setopt shwordsplit
+
+ local open_cmd
+
+ # define the open command
+ case "$OSTYPE" in
+ darwin*) open_cmd='open' ;;
+ cygwin*) open_cmd='cygstart' ;;
+ linux*) open_cmd='xdg-open' ;;
+ msys*) open_cmd='start ""' ;;
+ *) echo "Platform $OSTYPE not supported"
+ return 1
+ ;;
+ esac
+
+ # don't use nohup on OSX
+ if [[ "$OSTYPE" == darwin* ]]; then
+ $open_cmd "$@" &>/dev/null
+ else
+ nohup $open_cmd "$@" &>/dev/null
+ fi
+}
+
#
# Get the value of an alias.
#
@@ -51,7 +76,7 @@ function try_alias_value() {
#
# Arguments:
# 1. name - The variable to set
-# 2. val - The default value
+# 2. val - The default value
# Return value:
# 0 if the variable exists, 3 if it was set
#
@@ -65,11 +90,142 @@ function default() {
#
# Arguments:
# 1. name - The env variable to set
-# 2. val - The default value
+# 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
+ env | grep -q "^$1=" && return 0
export "$1=$2" && return 3
}
+
+
+# Required for $langinfo
+zmodload zsh/langinfo
+
+# URL-encode a string
+#
+# Encodes a string using RFC 2396 URL-encoding (%-escaped).
+# See: https://www.ietf.org/rfc/rfc2396.txt
+#
+# By default, reserved characters and unreserved "mark" characters are
+# not escaped by this function. This allows the common usage of passing
+# an entire URL in, and encoding just special characters in it, with
+# the expectation that reserved and mark characters are used appropriately.
+# The -r and -m options turn on escaping of the reserved and mark characters,
+# respectively, which allows arbitrary strings to be fully escaped for
+# embedding inside URLs, where reserved characters might be misinterpreted.
+#
+# Prints the encoded string on stdout.
+# Returns nonzero if encoding failed.
+#
+# Usage:
+# omz_urlencode [-r] [-m] [-P] <string>
+#
+# -r causes reserved characters (;/?:@&=+$,) to be escaped
+#
+# -m causes "mark" characters (_.!~*''()-) to be escaped
+#
+# -P causes spaces to be encoded as '%20' instead of '+'
+function omz_urlencode() {
+ emulate -L zsh
+ zparseopts -D -E -a opts r m P
+
+ local in_str=$1
+ local url_str=""
+ local spaces_as_plus
+ if [[ -z $opts[(r)-P] ]]; then spaces_as_plus=1; fi
+ local str="$in_str"
+
+ # URLs must use UTF-8 encoding; convert str to UTF-8 if required
+ local encoding=$langinfo[CODESET]
+ local safe_encodings
+ safe_encodings=(UTF-8 utf8 US-ASCII)
+ if [[ -z ${safe_encodings[(r)$encoding]} ]]; then
+ str=$(echo -E "$str" | iconv -f $encoding -t UTF-8)
+ if [[ $? != 0 ]]; then
+ echo "Error converting string from $encoding to UTF-8" >&2
+ return 1
+ fi
+ fi
+
+ # Use LC_CTYPE=C to process text byte-by-byte
+ local i byte ord LC_ALL=C
+ export LC_ALL
+ local reserved=';/?:@&=+$,'
+ local mark='_.!~*''()-'
+ local dont_escape="[A-Za-z0-9"
+ if [[ -z $opts[(r)-r] ]]; then
+ dont_escape+=$reserved
+ fi
+ # $mark must be last because of the "-"
+ if [[ -z $opts[(r)-m] ]]; then
+ dont_escape+=$mark
+ fi
+ dont_escape+="]"
+
+ # Implemented to use a single printf call and avoid subshells in the loop,
+ # for performance (primarily on Windows).
+ local url_str=""
+ for (( i = 1; i <= ${#str}; ++i )); do
+ byte="$str[i]"
+ if [[ "$byte" =~ "$dont_escape" ]]; then
+ url_str+="$byte"
+ else
+ if [[ "$byte" == " " && -n $spaces_as_plus ]]; then
+ url_str+="+"
+ else
+ ord=$(( [##16] #byte ))
+ url_str+="%$ord"
+ fi
+ fi
+ done
+ echo -E "$url_str"
+}
+
+# URL-decode a string
+#
+# Decodes a RFC 2396 URL-encoded (%-escaped) string.
+# This decodes the '+' and '%' escapes in the input string, and leaves
+# other characters unchanged. Does not enforce that the input is a
+# valid URL-encoded string. This is a convenience to allow callers to
+# pass in a full URL or similar strings and decode them for human
+# presentation.
+#
+# Outputs the encoded string on stdout.
+# Returns nonzero if encoding failed.
+#
+# Usage:
+# omz_urldecode <urlstring> - prints decoded string followed by a newline
+function omz_urldecode {
+ emulate -L zsh
+ local encoded_url=$1
+
+ # Work bytewise, since URLs escape UTF-8 octets
+ local caller_encoding=$langinfo[CODESET]
+ local LC_ALL=C
+ export LC_ALL
+
+ # Change + back to ' '
+ local tmp=${encoded_url:gs/+/ /}
+ # Protect other escapes to pass through the printf unchanged
+ tmp=${tmp:gs/\\/\\\\/}
+ # Handle %-escapes by turning them into `\xXX` printf escapes
+ tmp=${tmp:gs/%/\\x/}
+ local decoded
+ eval "decoded=\$'$tmp'"
+
+ # Now we have a UTF-8 encoded string in the variable. We need to re-encode
+ # it if caller is in a non-UTF-8 locale.
+ local safe_encodings
+ safe_encodings=(UTF-8 utf8 US-ASCII)
+ if [[ -z ${safe_encodings[(r)$caller_encoding]} ]]; then
+ decoded=$(echo -E "$decoded" | iconv -f UTF-8 -t $caller_encoding)
+ if [[ $? != 0 ]]; then
+ echo "Error converting string from UTF-8 to $caller_encoding" >&2
+ return 1
+ fi
+ fi
+
+ echo -E "$decoded"
+}
diff --git a/lib/git.zsh b/lib/git.zsh
index 305a77aff..f91b516bd 100644
--- a/lib/git.zsh
+++ b/lib/git.zsh
@@ -1,79 +1,129 @@
-# get the name of the branch we are on
+# Outputs current branch info in prompt format
function git_prompt_info() {
- if [[ "$(git config --get oh-my-zsh.hide-status)" != "1" ]]; then
+ local ref
+ if [[ "$(command git config --get oh-my-zsh.hide-status 2>/dev/null)" != "1" ]]; then
ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
- ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
+ ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
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
+function parse_git_dirty() {
+ local STATUS=''
+ local FLAGS
+ FLAGS=('--porcelain')
+ if [[ "$(command git config --get oh-my-zsh.hide-dirty)" != "1" ]]; then
if [[ $POST_1_7_2_GIT -gt 0 ]]; then
- SUBMODULE_SYNTAX="--ignore-submodules=dirty"
+ FLAGS+='--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"
+ FLAGS+='--untracked-files=no'
fi
+ STATUS=$(command git status ${FLAGS} 2> /dev/null | tail -n1)
+ fi
+ if [[ -n $STATUS ]]; then
+ echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
else
echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
fi
}
-# get the difference between the local and remote branches
-git_remote_status() {
+# Gets the difference between the local and remote branches
+function git_remote_status() {
+ local remote ahead behind git_remote_status git_remote_status_detailed
remote=${$(command git rev-parse --verify ${hook_com[branch]}@{upstream} --symbolic-full-name 2>/dev/null)/refs\/remotes\/}
- if [[ -n ${remote} ]] ; then
+ 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"
+ if [[ $ahead -eq 0 ]] && [[ $behind -eq 0 ]]; then
+ git_remote_status="$ZSH_THEME_GIT_PROMPT_EQUAL_REMOTE"
+ elif [[ $ahead -gt 0 ]] && [[ $behind -eq 0 ]]; then
+ git_remote_status="$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE"
+ git_remote_status_detailed="$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE_COLOR$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE$((ahead))%{$reset_color%}"
+ elif [[ $behind -gt 0 ]] && [[ $ahead -eq 0 ]]; then
+ git_remote_status="$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE"
+ git_remote_status_detailed="$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE_COLOR$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE$((behind))%{$reset_color%}"
+ elif [[ $ahead -gt 0 ]] && [[ $behind -gt 0 ]]; then
+ git_remote_status="$ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE"
+ git_remote_status_detailed="$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE_COLOR$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE$((ahead))%{$reset_color%}$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE_COLOR$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE$((behind))%{$reset_color%}"
fi
+
+ if [[ -n $ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_DETAILED ]]; then
+ git_remote_status="$ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_PREFIX$remote$git_remote_status_detailed$ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_SUFFIX"
+ fi
+
+ echo $git_remote_status
fi
}
-# Checks if there are commits ahead from remote
+# Outputs the name of the current branch
+# Usage example: git pull origin $(git_current_branch)
+# Using '--quiet' with 'symbolic-ref' will not cause a fatal error (128) if
+# it's not a symbolic ref, but in a Git repo.
+function git_current_branch() {
+ local ref
+ ref=$(command git symbolic-ref --quiet HEAD 2> /dev/null)
+ local ret=$?
+ if [[ $ret != 0 ]]; then
+ [[ $ret == 128 ]] && return # no git repo.
+ ref=$(command git rev-parse --short HEAD 2> /dev/null) || return
+ fi
+ echo ${ref#refs/heads/}
+}
+
+
+# Gets the number of commits ahead from remote
+function git_commits_ahead() {
+ if $(echo "$(command git log @{upstream}..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
+ local COMMITS
+ COMMITS=$(command git log @{upstream}..HEAD | grep '^commit' | wc -l | tr -d ' ')
+ echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$COMMITS$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX"
+ fi
+}
+
+# Outputs if current branch is ahead of remote
function git_prompt_ahead() {
- if $(echo "$(command git log origin/$(current_branch)..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
+ if [[ -n "$(command git rev-list origin/$(git_current_branch)..HEAD 2> /dev/null)" ]]; then
echo "$ZSH_THEME_GIT_PROMPT_AHEAD"
fi
}
+# Outputs if current branch is behind remote
+function git_prompt_behind() {
+ if [[ -n "$(command git rev-list HEAD..origin/$(git_current_branch) 2> /dev/null)" ]]; then
+ echo "$ZSH_THEME_GIT_PROMPT_BEHIND"
+ fi
+}
+
+# Outputs if current branch exists on remote or not
+function git_prompt_remote() {
+ if [[ -n "$(command git show-ref origin/$(git_current_branch) 2> /dev/null)" ]]; then
+ echo "$ZSH_THEME_GIT_PROMPT_REMOTE_EXISTS"
+ else
+ echo "$ZSH_THEME_GIT_PROMPT_REMOTE_MISSING"
+ fi
+}
+
# Formats prompt string for current git commit short SHA
function git_prompt_short_sha() {
+ local 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() {
+ local 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() {
+function git_prompt_status() {
+ local INDEX STATUS
INDEX=$(command git status --porcelain -b 2> /dev/null)
STATUS=""
- if $(echo "$INDEX" | grep -E '^\?\? ' &> /dev/null); then
+ if $(echo "$INDEX" | command grep -E '^\?\? ' &> /dev/null); then
STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$STATUS"
fi
if $(echo "$INDEX" | grep '^A ' &> /dev/null); then
@@ -116,28 +166,29 @@ git_prompt_status() {
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
+# Compares the provided version of git to the version installed and on path
+# Outputs -1, 0, or 1 if the installed version is less than, equal to, or
+# greater than the input version, respectively.
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]});
+ local INPUT_GIT_VERSION INSTALLED_GIT_VERSION
+ INPUT_GIT_VERSION=(${(s/./)1})
+ 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] -gt $INPUT_GIT_VERSION[$i] ]]; then
+ echo 1
+ return 0
+ fi
if [[ $INSTALLED_GIT_VERSION[$i] -lt $INPUT_GIT_VERSION[$i] ]]; then
echo -1
return 0
fi
done
- echo 1
+ echo 0
}
-#this is unlikely to change so make it all statically assigned
+# 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
-
-
+# Clean up the namespace slightly by removing the checker function
+unfunction git_compare_version
diff --git a/lib/grep.zsh b/lib/grep.zsh
index 93c4270b6..abc1650a1 100644
--- a/lib/grep.zsh
+++ b/lib/grep.zsh
@@ -1,6 +1,28 @@
-#
-# Color grep results
-# Examples: http://rubyurl.com/ZXv
-#
-export GREP_OPTIONS='--color=auto'
-export GREP_COLOR='1;32' \ No newline at end of file
+# is x grep argument available?
+grep-flag-available() {
+ echo | grep $1 "" >/dev/null 2>&1
+}
+
+GREP_OPTIONS=""
+
+# color grep results
+if grep-flag-available --color=auto; then
+ GREP_OPTIONS+=" --color=auto"
+fi
+
+# ignore VCS folders (if the necessary grep flags are available)
+VCS_FOLDERS="{.bzr,CVS,.git,.hg,.svn}"
+
+if grep-flag-available --exclude-dir=.cvs; then
+ GREP_OPTIONS+=" --exclude-dir=$VCS_FOLDERS"
+elif grep-flag-available --exclude=.cvs; then
+ GREP_OPTIONS+=" --exclude=$VCS_FOLDERS"
+fi
+
+# export grep settings
+alias grep="grep $GREP_OPTIONS"
+
+# clean up
+unset GREP_OPTIONS
+unset VCS_FOLDERS
+unfunction grep-flag-available
diff --git a/lib/history.zsh b/lib/history.zsh
index 655945166..5de71c2d3 100644
--- a/lib/history.zsh
+++ b/lib/history.zsh
@@ -1,10 +1,19 @@
## Command history configuration
-if [ -z $HISTFILE ]; then
+if [ -z "$HISTFILE" ]; then
HISTFILE=$HOME/.zsh_history
fi
+
HISTSIZE=10000
SAVEHIST=10000
+# Show history
+case $HIST_STAMPS in
+ "mm/dd/yyyy") alias history='fc -fl 1' ;;
+ "dd.mm.yyyy") alias history='fc -El 1' ;;
+ "yyyy-mm-dd") alias history='fc -il 1' ;;
+ *) alias history='fc -l 1' ;;
+esac
+
setopt append_history
setopt extended_history
setopt hist_expire_dups_first
diff --git a/lib/key-bindings.zsh b/lib/key-bindings.zsh
index 49f80c8f3..0e056dc72 100644
--- a/lib/key-bindings.zsh
+++ b/lib/key-bindings.zsh
@@ -1,40 +1,78 @@
-# TODO: Explain what some of this does..
-
-bindkey -e
-bindkey '\ew' kill-region
-bindkey -s '\el' "ls\n"
-bindkey '^r' history-incremental-search-backward
-bindkey "^[[5~" up-line-or-history
-bindkey "^[[6~" down-line-or-history
-
-# make search up and down work, so partially type and hit up/down to find relevant stuff
-bindkey '^[[A' up-line-or-search
-bindkey '^[[B' down-line-or-search
-
-bindkey "^[[H" beginning-of-line
-bindkey "^[[1~" beginning-of-line
-bindkey "^[OH" beginning-of-line
-bindkey "^[[F" end-of-line
-bindkey "^[[4~" end-of-line
-bindkey "^[OF" end-of-line
-bindkey ' ' magic-space # also do history expansion on space
-
-bindkey "^[[1;5C" forward-word
-bindkey "^[[1;5D" backward-word
-
-bindkey '^[[Z' reverse-menu-complete
-
-# Make the delete key (or Fn + Delete on the Mac) work instead of outputting a ~
-bindkey '^?' backward-delete-char
-bindkey "^[[3~" delete-char
-bindkey "^[3;5~" delete-char
-bindkey "\e[3~" delete-char
+# 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
+
+# start typing + [Up-Arrow] - fuzzy find history forward
+if [[ "${terminfo[kcuu1]}" != "" ]]; then
+ autoload -U up-line-or-beginning-search
+ zle -N up-line-or-beginning-search
+ bindkey "${terminfo[kcuu1]}" up-line-or-beginning-search
+fi
+# start typing + [Down-Arrow] - fuzzy find history backward
+if [[ "${terminfo[kcud1]}" != "" ]]; then
+ autoload -U down-line-or-beginning-search
+ zle -N down-line-or-beginning-search
+ bindkey "${terminfo[kcud1]}" down-line-or-beginning-search
+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
+# file rename magick
+bindkey "^[m" copy-prev-shell-word
+
# consider emacs keybindings:
#bindkey -e ## emacs key bindings
diff --git a/lib/misc.zsh b/lib/misc.zsh
index a8678b8ec..c81dab413 100644
--- a/lib/misc.zsh
+++ b/lib/misc.zsh
@@ -1,9 +1,19 @@
-## smart urls
-autoload -U url-quote-magic
-zle -N self-insert url-quote-magic
-
-## file rename magick
-bindkey "^[m" copy-prev-shell-word
+## Load smart urls if available
+# bracketed-paste-magic is known buggy in zsh 5.1.1 (only), so skip it there; see #4434
+autoload -Uz is-at-least
+if [[ $ZSH_VERSION != 5.1.1 ]]; then
+ for d in $fpath; do
+ if [[ -e "$d/url-quote-magic" ]]; then
+ if is-at-least 5.1; then
+ autoload -Uz bracketed-paste-magic
+ zle -N bracketed-paste bracketed-paste-magic
+ fi
+ autoload -Uz url-quote-magic
+ zle -N self-insert url-quote-magic
+ break
+ fi
+ done
+fi
## jobs
setopt long_list_jobs
@@ -12,4 +22,21 @@ setopt long_list_jobs
export PAGER="less"
export LESS="-R"
-export LC_CTYPE=$LANG
+## super user alias
+alias _='sudo'
+alias please='sudo'
+
+## more intelligent acking for ubuntu users
+if which ack-grep &> /dev/null; then
+ alias afind='ack-grep -il'
+else
+ alias afind='ack -il'
+fi
+
+# only define LC_CTYPE if undefined
+if [[ -z "$LC_CTYPE" && -z "$LC_ALL" ]]; then
+ export LC_CTYPE=${LANG%%:*} # pick the first entry from LANG
+fi
+
+# recognize comments
+setopt interactivecomments
diff --git a/lib/nvm.zsh b/lib/nvm.zsh
index 5cadf7061..61d997fc0 100644
--- a/lib/nvm.zsh
+++ b/lib/nvm.zsh
@@ -1,6 +1,6 @@
# get the node.js version
function nvm_prompt_info() {
- [ -f $HOME/.nvm/nvm.sh ] || return
+ [ -f "$HOME/.nvm/nvm.sh" ] || return
local nvm_prompt
nvm_prompt=$(node -v 2>/dev/null)
[[ "${nvm_prompt}x" == "x" ]] && return
diff --git a/lib/prompt_info_functions.zsh b/lib/prompt_info_functions.zsh
new file mode 100644
index 000000000..335c02a3d
--- /dev/null
+++ b/lib/prompt_info_functions.zsh
@@ -0,0 +1,33 @@
+# *_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)
+}
diff --git a/lib/rbenv.zsh b/lib/rbenv.zsh
deleted file mode 100644
index a8b6c323c..000000000
--- a/lib/rbenv.zsh
+++ /dev/null
@@ -1,2 +0,0 @@
-# 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
deleted file mode 100644
index e8744e61e..000000000
--- a/lib/rvm.zsh
+++ /dev/null
@@ -1,8 +0,0 @@
-# get the name of the ruby version
-function rvm_prompt_info() {
- [ -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/spectrum.zsh b/lib/spectrum.zsh
index 166c942fb..87092d8ae 100644
--- a/lib/spectrum.zsh
+++ b/lib/spectrum.zsh
@@ -3,7 +3,7 @@
# P.C. Shyamshankar <sykora@lucentbeing.com>
# Copied from http://github.com/sykora/etc/blob/master/zsh/functions/spectrum/
-typeset -Ag FX FG BG
+typeset -AHg FX FG BG
FX=(
reset "%{%}"
@@ -19,17 +19,19 @@ for color in {000..255}; do
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}Test%f"
+ print -P -- "$code: %{$FG[$code]%}$ZSH_SPECTRUM_TEXT%{$reset_color%}"
done
}
# Show all 256 colors where the background is set to specific color
function spectrum_bls() {
for code in {000..255}; do
- ((cc = code + 1))
- print -P -- "$BG[$code]$code: Test %{$reset_color%}"
+ print -P -- "$code: %{$BG[$code]%}$ZSH_SPECTRUM_TEXT%{$reset_color%}"
done
}
diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh
index 80319e1a8..871ab28df 100644
--- a/lib/termsupport.zsh
+++ b/lib/termsupport.zsh
@@ -1,37 +1,105 @@
-#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)
+# Set terminal window and tab/icon title
+#
+# usage: title short_tab_title [long_window_title]
+#
+# See: http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1
+# Fully supports screen, iterm, and probably most modern xterm and rxvt
+# (In screen, only short_tab_title is used)
+# Limited support for Apple Terminal (Terminal can't set window and 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
+ emulate -L zsh
+ setopt prompt_subst
+
+ [[ "$EMACS" == *term* ]] && return
+
+ # if $2 is unset use $1 as default
+ # if it is set and empty, leave it as is
+ : ${2=$1}
+
+ case "$TERM" in
+ cygwin|xterm*|putty*|rxvt*|ansi)
+ print -Pn "\e]2;$2:q\a" # set window name
+ print -Pn "\e]1;$1:q\a" # set tab name
+ ;;
+ screen*)
+ print -Pn "\ek$1:q\e\\" # set screen hardstatus
+ ;;
+ *)
+ if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
+ print -Pn "\e]2;$2:q\a" # set window name
+ print -Pn "\e]1;$1:q\a" # set tab name
+ else
+ # Try to use terminfo to set the title
+ # If the feature is available set title
+ if [[ -n "$terminfo[fsl]" ]] && [[ -n "$terminfo[tsl]" ]]; then
+ echoti tsl
+ print -Pn "$1"
+ echoti fsl
+ fi
+ fi
+ ;;
+ esac
}
ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD
ZSH_THEME_TERM_TITLE_IDLE="%n@%m: %~"
+# Avoid duplication of directory in terminals with independent dir display
+if [[ "$TERM_PROGRAM" == Apple_Terminal ]]; then
+ ZSH_THEME_TERM_TITLE_IDLE="%n@%m"
+fi
-#Appears when you have the prompt
+# Runs before showing the prompt
function omz_termsupport_precmd {
+ emulate -L zsh
+
+ if [[ "$DISABLE_AUTO_TITLE" == true ]]; then
+ return
+ fi
+
title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE
}
-#Appears at the beginning of (and during) of command execution
+# Runs before executing the command
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/$/\\$}"
- LINE="${LINE:gs/%/%%}"
- title "$CMD" "%100>...>$LINE%<<"
+
+ if [[ "$DISABLE_AUTO_TITLE" == true ]]; then
+ return
+ fi
+
+ # cmd name only, or if this is sudo or ssh, the next cmd
+ local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%}
+ 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
+precmd_functions+=(omz_termsupport_precmd)
+preexec_functions+=(omz_termsupport_preexec)
+
+
+# Keep Apple Terminal.app's current working directory updated
+# Based on this answer: http://superuser.com/a/315029
+# With extra fixes to handle multibyte chars and non-UTF-8 locales
+
+if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then
+ # Emits the control sequence to notify Terminal.app of the cwd
+ # Identifies the directory using a file: URI scheme, including
+ # the host name to disambiguate local vs. remote paths.
+ function update_terminalapp_cwd() {
+ emulate -L zsh
+
+ # Percent-encode the pathname.
+ local URL_PATH="$(omz_urlencode -P $PWD)"
+ [[ $? != 0 ]] && return 1
+
+ # Undocumented Terminal.app-specific control sequence
+ printf '\e]7;%s\a' "file://$HOST$URL_PATH"
+ }
+
+ # Use a precmd hook instead of a chpwd hook to avoid contaminating output
+ precmd_functions+=(update_terminalapp_cwd)
+ # Run once to get initial cwd set
+ update_terminalapp_cwd
+fi
diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh
index 0353f9db4..ebb11fb31 100644
--- a/lib/theme-and-appearance.zsh
+++ b/lib/theme-and-appearance.zsh
@@ -1,19 +1,21 @@
# ls colors
-autoload colors; colors;
+autoload -U 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);
+ # 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
+ # On OpenBSD, "gls" (ls from GNU coreutils) and "colorls" (ls from base,
+ # with color and multibyte support) are available from ports. "colorls"
+ # will be installed on purpose and can't be pulled in by installing
+ # coreutils, so prefer it to "gls".
+ gls --color -d . &>/dev/null 2>&1 && alias ls='gls --color=tty'
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'
@@ -23,7 +25,7 @@ fi
#setopt no_beep
setopt auto_cd
setopt multios
-setopt cdablevarS
+setopt cdablevars
if [[ x$WINDOW != x ]]
then
@@ -43,4 +45,3 @@ ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is c
# Setup the prompt with pretty colors
setopt prompt_subst
-