summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Janke <andrew@apjanke.net>2015-08-17 20:59:39 -0400
committerAndrew Janke <andrew@apjanke.net>2015-08-17 20:59:39 -0400
commit00eb4658304b010afdfa87f74be673c8aced4961 (patch)
tree3d9e7f95f21265c3c60f10cdca720308bb2421c6 /lib
parent47d19cc56425aa7c550d845726111ee8bd9520d1 (diff)
parent192de6bcffb0294e19f4203f6f7dc1a7f3e427be (diff)
downloadzsh-00eb4658304b010afdfa87f74be673c8aced4961.tar.gz
zsh-00eb4658304b010afdfa87f74be673c8aced4961.tar.bz2
zsh-00eb4658304b010afdfa87f74be673c8aced4961.zip
Merge branch 'master' into fold-terminalapp-plugin-into-termsupport
Diffstat (limited to 'lib')
-rw-r--r--lib/completion.zsh8
-rw-r--r--lib/directories.zsh6
-rw-r--r--lib/functions.zsh16
-rw-r--r--lib/git.zsh50
-rw-r--r--lib/grep.zsh6
-rw-r--r--lib/misc.zsh13
-rw-r--r--lib/termsupport.zsh8
7 files changed, 85 insertions, 22 deletions
diff --git a/lib/completion.zsh b/lib/completion.zsh
index ea6139fde..452c0dfe7 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 ''
@@ -34,7 +39,6 @@ fi
# disable named-directories autocompletion
zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories
-cdpath=(.)
# Use caching so that commands like apt and dpkg complete are useable
zstyle ':completion::complete:*' use-cache 1
diff --git a/lib/directories.zsh b/lib/directories.zsh
index 1a9698544..3bffa9fd9 100644
--- a/lib/directories.zsh
+++ b/lib/directories.zsh
@@ -24,9 +24,9 @@ alias d='dirs -v | head -10'
# List directory contents
alias lsa='ls -lah'
-alias l='ls -la'
-alias ll='ls -l'
-alias la='ls -lA'
+alias l='ls -lah'
+alias ll='ls -lh'
+alias la='ls -lAh'
# Push and pop directories on directory stack
alias pu='pushd'
diff --git a/lib/functions.zsh b/lib/functions.zsh
index 2a962669c..efb73a1bd 100644
--- a/lib/functions.zsh
+++ b/lib/functions.zsh
@@ -15,6 +15,22 @@ function take() {
cd $1
}
+function open_command() {
+ local open_cmd
+
+ # define the open command
+ case "$OSTYPE" in
+ darwin*) open_cmd="open" ;;
+ cygwin*) open_cmd="cygstart" ;;
+ linux*) open_cmd="xdg-open" ;;
+ *) echo "Platform $OSTYPE not supported"
+ return 1
+ ;;
+ esac
+
+ nohup $open_cmd "$@" &>/dev/null
+}
+
#
# Get the value of an alias.
#
diff --git a/lib/git.zsh b/lib/git.zsh
index 118841f06..caa7e6329 100644
--- a/lib/git.zsh
+++ b/lib/git.zsh
@@ -36,24 +36,27 @@ git_remote_status() {
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 ]
+ if [ $ahead -gt 0 ] && [ $behind -eq 0 ]
then
- echo "$ZSH_THEME_GIT_PROMPT_BEHIND_REMOTE"
- elif [ $ahead -gt 0 ] && [ $behind -eq 0 ]
+ 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
- echo "$ZSH_THEME_GIT_PROMPT_AHEAD_REMOTE"
+ 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
- echo "$ZSH_THEME_GIT_PROMPT_DIVERGED_REMOTE"
+ 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
- fi
-}
-# Checks if there are commits ahead from remote
-function git_prompt_ahead() {
- if $(echo "$(command git log @{upstream}..HEAD 2> /dev/null)" | grep '^commit' &> /dev/null); then
- echo "$ZSH_THEME_GIT_PROMPT_AHEAD"
- fi
+ if [ $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
}
# Gets the number of commits ahead from remote
@@ -64,6 +67,29 @@ function git_commits_ahead() {
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
+ 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
+ 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
+ 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() {
SHA=$(command git rev-parse --short HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
diff --git a/lib/grep.zsh b/lib/grep.zsh
index 348ebe623..3fa103d19 100644
--- a/lib/grep.zsh
+++ b/lib/grep.zsh
@@ -3,8 +3,12 @@ grep-flag-available() {
echo | grep $1 "" >/dev/null 2>&1
}
+GREP_OPTIONS=""
+
# color grep results
-GREP_OPTIONS="--color=auto"
+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}"
diff --git a/lib/misc.zsh b/lib/misc.zsh
index 0b7cb2696..6d1a64e8d 100644
--- a/lib/misc.zsh
+++ b/lib/misc.zsh
@@ -1,6 +1,10 @@
-## smart urls
-autoload -U url-quote-magic
-zle -N self-insert url-quote-magic
+## Load smart urls if available
+for d in $fpath; do
+ if [[ -e "$d/url-quote-magic" ]]; then
+ autoload -U url-quote-magic
+ zle -N self-insert url-quote-magic
+ fi
+done
## jobs
setopt long_list_jobs
@@ -20,3 +24,6 @@ alias afind='ack-grep -il'
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/termsupport.zsh b/lib/termsupport.zsh
index ff61d5329..5f61fe8ef 100644
--- a/lib/termsupport.zsh
+++ b/lib/termsupport.zsh
@@ -8,6 +8,8 @@
# Limited support for Apple Terminal (Terminal can't set window and tab separately)
function title {
emulate -L zsh
+ setopt prompt_subst
+
[[ "$EMACS" == *term* ]] && return
# if $2 is unset use $1 as default
@@ -24,6 +26,10 @@ function title {
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
# Runs before showing the prompt
function omz_termsupport_precmd {
@@ -45,7 +51,7 @@ function omz_termsupport_preexec {
setopt extended_glob
# cmd name only, or if this is sudo or ssh, the next cmd
- local CMD=${1[(wr)^(*=*|sudo|ssh|rake|-*)]:gs/%/%%}
+ local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%}
local LINE="${2:gs/%/%%}"
title '$CMD' '%100>...>$LINE%<<'