summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/clipboard.zsh86
-rw-r--r--lib/diagnostics.zsh30
-rw-r--r--lib/directories.zsh1
-rw-r--r--lib/functions.zsh36
-rw-r--r--lib/key-bindings.zsh10
-rw-r--r--lib/misc.zsh31
-rw-r--r--lib/spectrum.zsh6
-rw-r--r--lib/termsupport.zsh53
8 files changed, 199 insertions, 54 deletions
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/diagnostics.zsh b/lib/diagnostics.zsh
index afc33829b..9c9905e4d 100644
--- a/lib/diagnostics.zsh
+++ b/lib/diagnostics.zsh
@@ -52,6 +52,9 @@
# * 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
@@ -247,7 +250,7 @@ function _omz_diag_dump_one_big_text() {
function _omz_diag_dump_check_core_commands() {
builtin echo "Core command check:"
- local redefined name builtins externals
+ 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
@@ -255,17 +258,32 @@ function _omz_diag_dump_check_core_commands() {
# (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 declare dirs disable disown echo echotc echoti emulate
- enable eval exec exit export false fc fg float functions getln getopts hash
- integer jobs kill let limit local log logout noglob popd print printf
- pushd pushln pwd r read readonly rehash return sched set setopt shift
- source suspend test times trap true ttyctl type typeset ulimit umask unalias
+ 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"
diff --git a/lib/directories.zsh b/lib/directories.zsh
index 3bffa9fd9..a50a692c8 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'
diff --git a/lib/functions.zsh b/lib/functions.zsh
index efb73a1bd..f9d4a9717 100644
--- a/lib/functions.zsh
+++ b/lib/functions.zsh
@@ -16,19 +16,28 @@ function take() {
}
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" ;;
+ 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
- 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
}
#
@@ -67,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
#
@@ -81,12 +90,12 @@ 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
}
@@ -101,7 +110,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 +120,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 +186,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 +205,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 +229,3 @@ function omz_urldecode {
echo -E "$decoded"
}
-
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 bdb884046..c81dab413 100644
--- a/lib/misc.zsh
+++ b/lib/misc.zsh
@@ -1,14 +1,19 @@
## Load smart urls if available
-for d in $fpath; do
- if [[ -e "$d/url-quote-magic" ]]; then
- if [[ -e "$d/bracketed-paste-magic" ]]; then
- autoload -Uz bracketed-paste-magic
- zle -N bracketed-paste bracketed-paste-magic
- fi
- autoload -U url-quote-magic
- zle -N self-insert url-quote-magic
- fi
-done
+# 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
@@ -22,7 +27,11 @@ alias _='sudo'
alias please='sudo'
## more intelligent acking for ubuntu users
-alias afind='ack-grep -il'
+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
diff --git a/lib/spectrum.zsh b/lib/spectrum.zsh
index b683aca29..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 "%{%}"
@@ -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..871ab28df 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/%/%%}"
@@ -66,19 +84,18 @@ preexec_functions+=(omz_termsupport_preexec)
# 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