diff options
| author | Marc Cornellà <marc.cornella@live.com> | 2019-05-08 20:40:36 +0200 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-08 20:40:36 +0200 | 
| commit | 0232ac4bb1cb64b5bfaa7e5fc979d6f7ab23e534 (patch) | |
| tree | 946d9f8b758ebdd63da96152ca56b154c99068da /lib | |
| parent | afb028763cf40fc339e49011b2cba124dc108fcb (diff) | |
| parent | ebc700be9b2fa7ae770a644093a5c46a8e323726 (diff) | |
| download | zsh-0232ac4bb1cb64b5bfaa7e5fc979d6f7ab23e534.tar.gz zsh-0232ac4bb1cb64b5bfaa7e5fc979d6f7ab23e534.tar.bz2 zsh-0232ac4bb1cb64b5bfaa7e5fc979d6f7ab23e534.zip | |
Merge branch 'master' into master
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/compfix.zsh | 44 | ||||
| -rw-r--r-- | lib/completion.zsh | 3 | ||||
| -rw-r--r-- | lib/correction.zsh | 1 | ||||
| -rw-r--r-- | lib/directories.zsh | 14 | ||||
| -rw-r--r-- | lib/functions.zsh | 24 | ||||
| -rw-r--r-- | lib/git.zsh | 42 | ||||
| -rw-r--r-- | lib/history.zsh | 56 | ||||
| -rw-r--r-- | lib/misc.zsh | 6 | ||||
| -rw-r--r-- | lib/prompt_info_functions.zsh | 19 | ||||
| -rw-r--r-- | lib/spectrum.zsh | 2 | ||||
| -rw-r--r-- | lib/termsupport.zsh | 4 | ||||
| -rw-r--r-- | lib/theme-and-appearance.zsh | 7 | 
12 files changed, 102 insertions, 120 deletions
| diff --git a/lib/compfix.zsh b/lib/compfix.zsh index 208aaadb1..b09b283f2 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 +  [[ -z "${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 a1e934315..c7db2eb7b 100644 --- a/lib/completion.zsh +++ b/lib/completion.zsh @@ -25,6 +25,9 @@ else  fi  unset CASE_SENSITIVE HYPHEN_INSENSITIVE +# Complete . and .. special directories +zstyle ':completion:*' special-dirs true +  zstyle ':completion:*' list-colors ''  zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01' 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 a50a692c8..cf87bd7e4 100644 --- a/lib/directories.zsh +++ b/lib/directories.zsh @@ -21,14 +21,18 @@ alias 9='cd -9'  alias md='mkdir -p'  alias rd=rmdir -alias d='dirs -v | head -10' + +function d () { +  if [[ -n $1 ]]; then +    dirs "$@" +  else +    dirs -v | head -10 +  fi +} +compdef _dirs d  # 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 f30653784..9f8736bd7 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -11,21 +11,20 @@ function upgrade_oh_my_zsh() {  }  function take() { -  mkdir -p $1 -  cd $1 +  mkdir -p $@ && cd ${@:$#}  }  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' ;; +    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 @@ -34,9 +33,9 @@ function open_command() {    # don't use nohup on OSX    if [[ "$OSTYPE" == darwin* ]]; then -    $open_cmd "$@" &>/dev/null +    ${=open_cmd} "$@" &>/dev/null    else -    nohup $open_cmd "$@" &>/dev/null +    nohup ${=open_cmd} "$@" &>/dev/null    fi  } @@ -52,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]  }  # @@ -81,7 +79,7 @@ function try_alias_value() {  #    0 if the variable exists, 3 if it was set  #  function default() { -    test `typeset +m "$1"` && return 0 +    (( $+parameters[$1] )) && return 0      typeset -g "$1"="$2"   && return 3  } @@ -95,8 +93,8 @@ function default() {  #    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 +    (( ${${(@f):-$(typeset +xg)}[(I)$1]} )) && return 0 +    export "$1=$2" && return 3  } diff --git a/lib/git.zsh b/lib/git.zsh index 9b0f6e36f..640561e97 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -10,13 +10,10 @@ function git_prompt_info() {  # Checks if working tree is dirty  function parse_git_dirty() { -  local STATUS='' +  local STATUS    local -a FLAGS -  FLAGS=('--porcelain') +  FLAGS=('--porcelain' '--ignore-submodules=dirty')    if [[ "$(command git config --get oh-my-zsh.hide-dirty)" != "1" ]]; then -    if [[ $POST_1_7_2_GIT -gt 0 ]]; then -      FLAGS+='--ignore-submodules=dirty' -    fi      if [[ "$DISABLE_UNTRACKED_FILES_DIRTY" == "true" ]]; then        FLAGS+='--untracked-files=no'      fi @@ -77,8 +74,8 @@ function git_current_branch() {  # Gets the number of commits ahead from remote  function git_commits_ahead() {    if command git rev-parse --git-dir &>/dev/null; then -    local commits="$(git rev-list --count @{upstream}..HEAD)" -    if [[ "$commits" != 0 ]]; 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 @@ -87,8 +84,8 @@ function git_commits_ahead() {  # 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})" -    if [[ "$commits" != 0 ]]; 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 @@ -181,28 +178,6 @@ function git_prompt_status() {    echo $STATUS  } -# 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 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 0 -} -  # Outputs the name of the current user  # Usage example: $(git_current_user_name)  function git_current_user_name() { @@ -214,8 +189,3 @@ function git_current_user_name() {  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 -unfunction git_compare_version diff --git a/lib/history.zsh b/lib/history.zsh index 5de71c2d3..52e45bf4c 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 -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' ;; +# Timestamp format +case ${HIST_STAMPS-} in +  "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/misc.zsh b/lib/misc.zsh index 3052b7710..b30822b50 100644 --- a/lib/misc.zsh +++ b/lib/misc.zsh @@ -18,13 +18,11 @@ fi  ## jobs  setopt long_list_jobs -## pager -env_default PAGER 'less' -env_default 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/prompt_info_functions.zsh b/lib/prompt_info_functions.zsh index 335c02a3d..5069c4b21 100644 --- a/lib/prompt_info_functions.zsh +++ b/lib/prompt_info_functions.zsh @@ -10,9 +10,15 @@  # 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 { +function chruby_prompt_info \ +  rbenv_prompt_info \ +  hg_prompt_info \ +  pyenv_prompt_info \ +  svn_prompt_info \ +  vi_mode_prompt_info \ +  virtualenv_prompt_info \ +  jenv_prompt_info \ +{    return 1  } @@ -22,10 +28,13 @@ 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:=)}" +  [[ -z "${rvm_prompt}" ]] && return 1 +  echo "${ZSH_THEME_RUBY_PROMPT_PREFIX}${rvm_prompt}${ZSH_THEME_RUBY_PROMPT_SUFFIX}"  } +ZSH_THEME_RVM_PROMPT_OPTIONS="i v g" + +  # use this to enable users to see their ruby version, no matter which  # version management system they use  function ruby_prompt_info() { diff --git a/lib/spectrum.zsh b/lib/spectrum.zsh index 87092d8ae..312ab2248 100644 --- a/lib/spectrum.zsh +++ b/lib/spectrum.zsh @@ -1,7 +1,7 @@  #! /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 -AHg FX FG BG diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh index 871ab28df..aa14f3f07 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -21,7 +21,7 @@ function title {        print -Pn "\e]2;$2:q\a" # set window name        print -Pn "\e]1;$1:q\a" # set tab name        ;; -    screen*) +    screen*|tmux*)        print -Pn "\ek$1:q\e\\" # set screen hardstatus        ;;      *) @@ -80,7 +80,7 @@ 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 diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh index 96f34aa81..5016d86ca 100644 --- a/lib/theme-and-appearance.zsh +++ b/lib/theme-and-appearance.zsh @@ -19,7 +19,7 @@ if [[ "$DISABLE_LS_COLORS" != "true" ]]; then      # coreutils, so prefer it to "gls".      gls --color -d . &>/dev/null && alias ls='gls --color=tty'      colorls -G -d . &>/dev/null && alias ls='colorls -G' -  elif [[ "$OSTYPE" == darwin* ]]; then +  elif [[ "$OSTYPE" == (darwin|freebsd)* ]]; then      # this is a good alias, it works by default just using $LSCOLORS      ls -G . &>/dev/null && alias ls='ls -G' @@ -45,11 +45,10 @@ setopt prompt_subst  [[ -n "$WINDOW" ]] && SCREEN_NO="%B$WINDOW%b " || SCREEN_NO="" -# 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 +ZSH_THEME_RUBY_PROMPT_PREFIX="(" +ZSH_THEME_RUBY_PROMPT_SUFFIX=")" | 
