diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/clipboard.zsh | 8 | ||||
| -rw-r--r-- | lib/compfix.zsh | 44 | ||||
| -rw-r--r-- | lib/completion.zsh | 38 | ||||
| -rw-r--r-- | lib/correction.zsh | 1 | ||||
| -rw-r--r-- | lib/directories.zsh | 5 | ||||
| -rw-r--r-- | lib/functions.zsh | 48 | ||||
| -rw-r--r-- | lib/git.zsh | 120 | ||||
| -rw-r--r-- | lib/history.zsh | 54 | ||||
| -rw-r--r-- | lib/key-bindings.zsh | 10 | ||||
| -rw-r--r-- | lib/misc.zsh | 6 | ||||
| -rw-r--r-- | lib/nvm.zsh | 2 | ||||
| -rw-r--r-- | lib/prompt_info_functions.zsh | 2 | ||||
| -rw-r--r-- | lib/spectrum.zsh | 8 | ||||
| -rw-r--r-- | lib/termsupport.zsh | 55 | ||||
| -rw-r--r-- | lib/theme-and-appearance.zsh | 56 | 
15 files changed, 266 insertions, 191 deletions
| diff --git a/lib/clipboard.zsh b/lib/clipboard.zsh index b663800a4..2c93d1bb5 100644 --- a/lib/clipboard.zsh +++ b/lib/clipboard.zsh @@ -31,13 +31,13 @@ function clipcopy() {        cat $file > /dev/clipboard      fi    else -    if which xclip &>/dev/null; then +    if (( $+commands[xclip] )); then        if [[ -z $file ]]; then          xclip -in -selection clipboard        else          xclip -in -selection clipboard $file        fi -    elif which xsel &>/dev/null; then +    elif (( $+commands[xsel] )); then        if [[ -z $file ]]; then          xsel --clipboard --input         else @@ -74,9 +74,9 @@ function clippaste() {    elif [[ $OSTYPE == cygwin* ]]; then      cat /dev/clipboard    else -    if which xclip &>/dev/null; then +    if (( $+commands[xclip] )); then        xclip -out -selection clipboard -    elif which xsel &>/dev/null; then +    elif (( $+commands[xsel] )); then        xsel --clipboard --output      else        print "clipcopy: Platform $OSTYPE not supported or xclip/xsel not installed" >&2 diff --git a/lib/compfix.zsh b/lib/compfix.zsh index 208aaadb1..68decc1ed 100644 --- a/lib/compfix.zsh +++ b/lib/compfix.zsh @@ -2,10 +2,6 @@  # 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: @@ -22,39 +18,27 @@ function handle_completion_insecurities() {    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 +  (( ! ${#insecure_dirs} )) && return    # 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 +  cat <<EOD -  # List of the absolute paths of all unique existing completion caches. -  local -aU zcompdump_files -  zcompdump_files=( "${ZSH_COMPDUMP}"(.) "${ZDOTDIR:-${HOME}}"/.zcompdump* ) +[oh-my-zsh] For safety, we will not load completions from these directories until +[oh-my-zsh] you fix their permissions and ownership and restart zsh. +[oh-my-zsh] See the above list for directories with group or other writability. -  # 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" +[oh-my-zsh] To fix your permissions you can do so by disabling +[oh-my-zsh] the write permission of "group" and "others" and making sure that the +[oh-my-zsh] owner of these directories is either root or your current user. +[oh-my-zsh] The following command may help: +[oh-my-zsh]     compaudit | xargs chmod g-w,o-w -    # List such files first. -    print "[oh-my-zsh] Insecure completion caches also detected:" -    ls -l "${(@)zcompdump_files}" +[oh-my-zsh] If the above didn't help or you want to skip the verification of +[oh-my-zsh] insecure directories you can set the variable ZSH_DISABLE_COMPFIX to +[oh-my-zsh] "true" before oh-my-zsh is sourced in your zshrc file. -    # 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 +EOD  } diff --git a/lib/completion.zsh b/lib/completion.zsh index f5b292471..c7db2eb7b 100644 --- a/lib/completion.zsh +++ b/lib/completion.zsh @@ -1,37 +1,37 @@  # fixme - the load process here seems a bit bizarre +zmodload -i zsh/complist + +WORDCHARS=''  unsetopt menu_complete   # do not autoselect the first completion entry  unsetopt flowcontrol -setopt auto_menu         # show completion menu on succesive tab press +setopt auto_menu         # show completion menu on successive tab press  setopt complete_in_word  setopt always_to_end -WORDCHARS='' - -zmodload -i zsh/complist +# should this be in keybindings? +bindkey -M menuselect '^o' accept-and-infer-next-history +zstyle ':completion:*:*:*:*:*' menu select -## 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 +# case insensitive (all), partial-word and substring completion +if [[ "$CASE_SENSITIVE" = true ]]; then +  zstyle ':completion:*' matcher-list 'r:|=*' 'l:|=* r:|=*'  else -  if [ "x$HYPHEN_INSENSITIVE" = "xtrue" ]; then -    zstyle ':completion:*' matcher-list 'm:{a-zA-Z-_}={A-Za-z_-}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' -    unset HYPHEN_INSENSITIVE +  if [[ "$HYPHEN_INSENSITIVE" = true ]]; then +    zstyle ':completion:*' matcher-list 'm:{a-zA-Z-_}={A-Za-z_-}' 'r:|=*' 'l:|=* r:|=*'    else -    zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' +    zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*'    fi  fi +unset CASE_SENSITIVE HYPHEN_INSENSITIVE -zstyle ':completion:*' list-colors '' - -# should this be in keybindings? -bindkey -M menuselect '^o' accept-and-infer-next-history +# Complete . and .. special directories +zstyle ':completion:*' special-dirs true -zstyle ':completion:*:*:*:*:*' menu select +zstyle ':completion:*' list-colors ''  zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01' -if [ "$OSTYPE[0,7]" = "solaris" ] -then + +if [[ "$OSTYPE" = 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" diff --git a/lib/correction.zsh b/lib/correction.zsh index 3e1415a0b..c635236b5 100644 --- a/lib/correction.zsh +++ b/lib/correction.zsh @@ -1,4 +1,5 @@  if [[ "$ENABLE_CORRECTION" == "true" ]]; then +  alias cp='nocorrect cp'    alias ebuild='nocorrect ebuild'    alias gist='nocorrect gist'    alias heroku='nocorrect heroku' diff --git a/lib/directories.zsh b/lib/directories.zsh index 3bffa9fd9..14064b86f 100644 --- a/lib/directories.zsh +++ b/lib/directories.zsh @@ -8,6 +8,7 @@ alias -g ....='../../..'  alias -g .....='../../../..'  alias -g ......='../../../../..' +alias -- -='cd -'  alias 1='cd -'  alias 2='cd -2'  alias 3='cd -3' @@ -27,7 +28,3 @@ 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 efb73a1bd..4ef8920f6 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -3,16 +3,15 @@ function zsh_stats() {  }  function uninstall_oh_my_zsh() { -  env ZSH=$ZSH /bin/sh $ZSH/tools/uninstall.sh +  env ZSH=$ZSH sh $ZSH/tools/uninstall.sh  }  function upgrade_oh_my_zsh() { -  env ZSH=$ZSH /bin/sh $ZSH/tools/upgrade.sh +  env ZSH=$ZSH sh $ZSH/tools/upgrade.sh  }  function take() { -  mkdir -p $1 -  cd $1 +  mkdir -p $@ && cd ${@:$#}  }  function open_command() { @@ -20,15 +19,24 @@ function open_command() {    # define the open command    case "$OSTYPE" in -    darwin*)  open_cmd="open" ;; -    cygwin*)  open_cmd="cygstart" ;; -    linux*)   open_cmd="xdg-open" ;; +    darwin*)  open_cmd='open' ;; +    cygwin*)  open_cmd='cygstart' ;; +    linux*)   ! [[ $(uname -a) =~ "Microsoft" ]] && open_cmd='xdg-open' || { +                open_cmd='cmd.exe /c start ""' +                [[ -e "$1" ]] && { 1="$(wslpath -w "${1:a}")" || return 1 } +              } ;; +    msys*)    open_cmd='start ""' ;;      *)        echo "Platform $OSTYPE not supported"                return 1                ;;    esac -  nohup $open_cmd "$@" &>/dev/null +  # don't use nohup on OSX +  if [[ "$OSTYPE" == darwin* ]]; then +    ${=open_cmd} "$@" &>/dev/null +  else +    nohup ${=open_cmd} "$@" &>/dev/null +  fi  }  # @@ -43,8 +51,7 @@ function open_command() {  #    1 if it does not exist  #  function alias_value() { -    alias "$1" | sed "s/^$1='\(.*\)'$/\1/" -    test $(alias "$1") +    (( $+aliases[$1] )) && echo $aliases[$1]  }  # @@ -67,7 +74,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  # @@ -77,16 +84,16 @@ function default() {  }  # -# Set enviroment variable "$1" to default value "$2" if "$1" is not yet defined. +# Set environment 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  +#    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  } @@ -101,7 +108,7 @@ zmodload zsh/langinfo  #  # 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  +# 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 @@ -111,8 +118,8 @@ zmodload zsh/langinfo  # Returns nonzero if encoding failed.  #  # Usage: -#  omz_urlencode [-r] [-m] <string> -#   +#  omz_urlencode [-r] [-m] [-P] <string> +#  #    -r causes reserved characters (;/?:@&=+$,) to be escaped  #  #    -m causes "mark" characters (_.!~*''()-) to be escaped @@ -177,8 +184,8 @@ function omz_urlencode() {  # 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  +# 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. @@ -196,7 +203,7 @@ function omz_urldecode {    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 @@ -220,4 +227,3 @@ function omz_urldecode {    echo -E "$decoded"  } - diff --git a/lib/git.zsh b/lib/git.zsh index 1e203c7c6..b92373153 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -1,5 +1,6 @@ -# get the name of the branch we are on +# Outputs current branch info in prompt format  function git_prompt_info() { +  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 0 @@ -7,11 +8,10 @@ function git_prompt_info() {    fi  } -  # Checks if working tree is dirty -parse_git_dirty() { +function parse_git_dirty() {    local STATUS='' -  local FLAGS +  local -a FLAGS    FLAGS=('--porcelain')    if [[ "$(command git config --get oh-my-zsh.hide-dirty)" != "1" ]]; then      if [[ $POST_1_7_2_GIT -gt 0 ]]; then @@ -29,32 +29,28 @@ parse_git_dirty() {    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 -eq 0 ] -        then -          	git_remote_status="$ZSH_THEME_GIT_PROMPT_EQUAL_REMOTE" -        elif [ $ahead -gt 0 ] && [ $behind -eq 0 ] -        then +        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 +        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 +        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 [ $ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_DETAILED ] -        then +        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 @@ -62,31 +58,59 @@ git_remote_status() {      fi  } +# 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 -    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" +  if command git rev-parse --git-dir &>/dev/null; then +    local commits="$(git rev-list --count @{upstream}..HEAD 2>/dev/null)" +    if [[ -n "$commits" && "$commits" != 0 ]]; then +      echo "$ZSH_THEME_GIT_COMMITS_AHEAD_PREFIX$commits$ZSH_THEME_GIT_COMMITS_AHEAD_SUFFIX" +    fi +  fi +} + +# Gets the number of commits behind remote +function git_commits_behind() { +  if command git rev-parse --git-dir &>/dev/null; then +    local commits="$(git rev-list --count HEAD..@{upstream} 2>/dev/null)" +    if [[ -n "$commits" && "$commits" != 0 ]]; then +      echo "$ZSH_THEME_GIT_COMMITS_BEHIND_PREFIX$commits$ZSH_THEME_GIT_COMMITS_BEHIND_SUFFIX" +    fi    fi  }  # Outputs if current branch is ahead of remote  function git_prompt_ahead() { -  if [[ -n "$(command git rev-list origin/$(current_branch)..HEAD 2> /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/$(current_branch) 2> /dev/null)" ]]; then +  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/$(current_branch) 2> /dev/null)" ]]; then +  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" @@ -95,16 +119,19 @@ function git_prompt_remote() {  # 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" | command grep -E '^\?\? ' &> /dev/null); then @@ -114,11 +141,15 @@ git_prompt_status() {      STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"    elif $(echo "$INDEX" | grep '^M  ' &> /dev/null); then      STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS" +  elif $(echo "$INDEX" | grep '^MM ' &> /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 '^MM ' &> /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 @@ -138,27 +169,26 @@ git_prompt_status() {    if $(echo "$INDEX" | grep '^UU ' &> /dev/null); then      STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS"    fi -  if $(echo "$INDEX" | grep '^## .*ahead' &> /dev/null); then +  if $(echo "$INDEX" | grep '^## [^ ]\+ .*ahead' &> /dev/null); then      STATUS="$ZSH_THEME_GIT_PROMPT_AHEAD$STATUS"    fi -  if $(echo "$INDEX" | grep '^## .*behind' &> /dev/null); then +  if $(echo "$INDEX" | grep '^## [^ ]\+ .*behind' &> /dev/null); then      STATUS="$ZSH_THEME_GIT_PROMPT_BEHIND$STATUS"    fi -  if $(echo "$INDEX" | grep '^## .*diverged' &> /dev/null); then +  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 +# 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 i +  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 @@ -173,7 +203,19 @@ function git_compare_version() {    echo 0  } -#this is unlikely to change so make it all statically assigned +# Outputs the name of the current user +# Usage example: $(git_current_user_name) +function git_current_user_name() { +  command git config user.name 2>/dev/null +} + +# Outputs the email of the current user +# Usage example: $(git_current_user_email) +function git_current_user_email() { +  command git config user.email 2>/dev/null +} + +# 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/history.zsh b/lib/history.zsh index 5de71c2d3..d8bbd41c4 100644 --- a/lib/history.zsh +++ b/lib/history.zsh @@ -1,24 +1,40 @@ -## Command history configuration -if [ -z "$HISTFILE" ]; then -    HISTFILE=$HOME/.zsh_history -fi +## History wrapper +function omz_history { +  local clear list +  zparseopts -E c=clear l=list -HISTSIZE=10000 -SAVEHIST=10000 +  if [[ -n "$clear" ]]; then +    # if -c provided, clobber the history file +    echo -n >| "$HISTFILE" +    echo >&2 History file deleted. Reload the session to see its effects. +  elif [[ -n "$list" ]]; then +    # if -l provided, run as if calling `fc' directly +    builtin fc "$@" +  else +    # unless a number is provided, show all history events (starting from 1) +    [[ ${@[-1]} = *[0-9]* ]] && builtin fc -l "$@" || builtin fc -l "$@" 1 +  fi +} -# Show history +# Timestamp format  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' ;; +  "mm/dd/yyyy") alias history='omz_history -f' ;; +  "dd.mm.yyyy") alias history='omz_history -E' ;; +  "yyyy-mm-dd") alias history='omz_history -i' ;; +  "") alias history='omz_history' ;; +  *) alias history="omz_history -t '$HIST_STAMPS'" ;;  esac -setopt append_history -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 +## History file configuration +[ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history" +HISTSIZE=50000 +SAVEHIST=10000 + +## History command configuration +setopt extended_history       # record timestamp of command in HISTFILE +setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE +setopt hist_ignore_dups       # ignore duplicated commands history list +setopt hist_ignore_space      # ignore commands that start with space +setopt hist_verify            # show command with history expansion to user before running it +setopt inc_append_history     # add commands to HISTFILE in order of execution +setopt share_history          # share command history data diff --git a/lib/key-bindings.zsh b/lib/key-bindings.zsh index eb2b58058..0e056dc72 100644 --- a/lib/key-bindings.zsh +++ b/lib/key-bindings.zsh @@ -27,11 +27,17 @@ 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 -  bindkey "${terminfo[kcuu1]}" up-line-or-search      # start typing + [Up-Arrow] - fuzzy find history forward +  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 -  bindkey "${terminfo[kcud1]}" down-line-or-search    # start typing + [Down-Arrow] - fuzzy find history backward +  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 diff --git a/lib/misc.zsh b/lib/misc.zsh index c81dab413..b30822b50 100644 --- a/lib/misc.zsh +++ b/lib/misc.zsh @@ -18,13 +18,11 @@ fi  ## jobs  setopt long_list_jobs -## pager -export PAGER="less" -export LESS="-R" +env_default 'PAGER' 'less' +env_default 'LESS' '-R'  ## super user alias  alias _='sudo' -alias please='sudo'  ## more intelligent acking for ubuntu users  if which ack-grep &> /dev/null; then diff --git a/lib/nvm.zsh b/lib/nvm.zsh index 61d997fc0..4a8b6811e 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 "$NVM_DIR/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 index 335c02a3d..1d5c23e41 100644 --- a/lib/prompt_info_functions.zsh +++ b/lib/prompt_info_functions.zsh @@ -12,7 +12,7 @@  # 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 { +  virtualenv_prompt_info jenv_prompt_info {    return 1  } diff --git a/lib/spectrum.zsh b/lib/spectrum.zsh index b683aca29..312ab2248 100644 --- a/lib/spectrum.zsh +++ b/lib/spectrum.zsh @@ -1,9 +1,9 @@  #! /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/ +# Copied from https://github.com/sykora/etc/blob/master/zsh/functions/spectrum/ -typeset -Ag FX FG BG +typeset -AHg FX FG BG  FX=(      reset     "%{[00m%}" @@ -25,13 +25,13 @@ ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab o  # 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" +    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 -    print -P -- "$BG[$code]$code: $ZSH_SPECTRUM_TEXT %{$reset_color%}" +    print -P -- "$code: %{$BG[$code]%}$ZSH_SPECTRUM_TEXT%{$reset_color%}"    done  } diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index 5f61fe8ef..87d55ee89 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -9,32 +9,50 @@  function title {    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} -  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 -  fi +  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 +if [[ "$TERM_PROGRAM" == Apple_Terminal ]]; then    ZSH_THEME_TERM_TITLE_IDLE="%n@%m"  fi  # Runs before showing the prompt  function omz_termsupport_precmd {    emulate -L zsh -  if [[ $DISABLE_AUTO_TITLE == true ]]; then + +  if [[ "$DISABLE_AUTO_TITLE" == true ]]; then      return    fi @@ -44,12 +62,12 @@ function omz_termsupport_precmd {  # Runs before executing the command  function omz_termsupport_preexec {    emulate -L zsh -  if [[ $DISABLE_AUTO_TITLE == true ]]; then +  setopt extended_glob + +  if [[ "$DISABLE_AUTO_TITLE" == true ]]; then      return    fi -  setopt extended_glob -    # 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/%/%%}" @@ -62,23 +80,22 @@ preexec_functions+=(omz_termsupport_preexec)  # Keep Apple Terminal.app's current working directory updated -# Based on this answer: http://superuser.com/a/315029 +# Based on this answer: https://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 -    # Identify the directory using a "file:" scheme URL, including -    # the host name to disambiguate local vs. remote paths.      # Percent-encode the pathname. -    local URL_PATH=$(omz_urlencode -P $PWD) +    local URL_PATH="$(omz_urlencode -P $PWD)"      [[ $? != 0 ]] && return 1 -    local PWD_URL="file://$HOST$URL_PATH" +      # Undocumented Terminal.app-specific control sequence -    printf '\e]7;%s\a' $PWD_URL +    printf '\e]7;%s\a' "file://$HOST$URL_PATH"    }    # Use a precmd hook instead of a chpwd hook to avoid contaminating output diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh index ebb11fb31..96f34aa81 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -1,38 +1,49 @@  # ls colors  autoload -U colors && colors -export LSCOLORS="Gxfxcxdxbxegedabagacad"  # 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 +export LSCOLORS="Gxfxcxdxbxegedabagacad" + +# TODO organise this chaotic logic + +if [[ "$DISABLE_LS_COLORS" != "true" ]]; then +  # Find the option for using colors in ls, depending on the version +  if [[ "$OSTYPE" == 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, "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  +    gls --color -d . &>/dev/null && alias ls='gls --color=tty' +  elif [[ "$OSTYPE" == openbsd* ]]; then +    # 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' +    gls --color -d . &>/dev/null && alias ls='gls --color=tty' +    colorls -G -d . &>/dev/null && alias ls='colorls -G' +  elif [[ "$OSTYPE" == darwin* ]]; then +    # this is a good alias, it works by default just using $LSCOLORS +    ls -G . &>/dev/null && alias ls='ls -G' + +    # only use coreutils ls if there is a dircolors customization present ($LS_COLORS or .dircolors file) +    # otherwise, gls will use the default color scheme which is ugly af +    [[ -n "$LS_COLORS" || -f "$HOME/.dircolors" ]] && gls --color -d . &>/dev/null && alias ls='gls --color=tty'    else -    ls --color -d . &>/dev/null 2>&1 && alias ls='ls --color=tty' || alias ls='ls -G' +    # For GNU ls, we use the default ls color theme. They can later be overwritten by themes. +    if [[ -z "$LS_COLORS" ]]; then +      (( $+commands[dircolors] )) && eval "$(dircolors -b)" +    fi + +    ls --color -d . &>/dev/null && alias ls='ls --color=tty' || { ls -G . &>/dev/null && alias ls='ls -G' } + +    # Take advantage of $LS_COLORS for completion as well. +    zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"    fi  fi -#setopt no_beep  setopt auto_cd  setopt multios -setopt cdablevars +setopt prompt_subst -if [[ x$WINDOW != x ]] -then -    SCREEN_NO="%B$WINDOW%b " -else -    SCREEN_NO="" -fi +[[ -n "$WINDOW" ]] && SCREEN_NO="%B$WINDOW%b " || SCREEN_NO=""  # Apply theming defaults  PS1="%n@%m:%~%# " @@ -42,6 +53,3 @@ ZSH_THEME_GIT_PROMPT_PREFIX="git:("         # Prefix at the very beginning of th  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 | 
