diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/clipboard.zsh | 2 | ||||
-rw-r--r-- | lib/completion.zsh | 2 | ||||
-rw-r--r-- | lib/functions.zsh | 4 | ||||
-rw-r--r-- | lib/grep.zsh | 57 | ||||
-rw-r--r-- | lib/misc.zsh | 20 | ||||
-rw-r--r-- | lib/spectrum.zsh | 26 | ||||
-rw-r--r-- | lib/termsupport.zsh | 65 |
7 files changed, 109 insertions, 67 deletions
diff --git a/lib/clipboard.zsh b/lib/clipboard.zsh index 808f2ea2d..122145f15 100644 --- a/lib/clipboard.zsh +++ b/lib/clipboard.zsh @@ -83,7 +83,7 @@ function detect-clipboard() { function clippaste() { tmux save-buffer -; } elif [[ $(uname -r) = *icrosoft* ]]; then function clipcopy() { clip.exe < "${1:-/dev/stdin}"; } - function clippaste() { _retry_clipboard_detection_or_fail clippaste "$@"; } + function clippaste() { powershell.exe -noprofile -command Get-Clipboard; } else function _retry_clipboard_detection_or_fail() { local clipcmd="${1}"; shift diff --git a/lib/completion.zsh b/lib/completion.zsh index c932bc925..8b87557a2 100644 --- a/lib/completion.zsh +++ b/lib/completion.zsh @@ -73,4 +73,4 @@ if [[ $COMPLETION_WAITING_DOTS = true ]]; then fi # automatically load bash completion functions -autoload -Uz bashcompinit && bashcompinit +autoload -U +X bashcompinit && bashcompinit diff --git a/lib/functions.zsh b/lib/functions.zsh index 91e9cf895..678e29ce7 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -8,7 +8,7 @@ function uninstall_oh_my_zsh() { function upgrade_oh_my_zsh() { env ZSH="$ZSH" sh "$ZSH/tools/upgrade.sh" - rm -rf "$ZSH/log/update.lock" + command rm -rf "$ZSH/log/update.lock" } function take() { @@ -89,7 +89,7 @@ function default() { # 0 if the env variable exists, 3 if it was set # function env_default() { - (( ${${(@f):-$(typeset +xg)}[(I)$1]} )) && return 0 + [[ ${parameters[$1]} = *-export* ]] && return 0 export "$1=$2" && return 3 } diff --git a/lib/grep.zsh b/lib/grep.zsh index abc1650a1..a725e0f26 100644 --- a/lib/grep.zsh +++ b/lib/grep.zsh @@ -1,28 +1,41 @@ -# is x grep argument available? -grep-flag-available() { - echo | grep $1 "" >/dev/null 2>&1 -} +__GREP_CACHE_FILE="$ZSH_CACHE_DIR"/grep-alias -GREP_OPTIONS="" +# See if there's a cache file modified in the last day +__GREP_ALIAS_CACHES=("$__GREP_CACHE_FILE"(Nm-1)) +if [[ -n "$__GREP_ALIAS_CACHES" ]]; then + source "$__GREP_CACHE_FILE" +else + grep-flags-available() { + command grep "$@" "" &>/dev/null <<< "" + } -# color grep results -if grep-flag-available --color=auto; then - GREP_OPTIONS+=" --color=auto" -fi + # Ignore these folders (if the necessary grep flags are available) + EXC_FOLDERS="{.bzr,CVS,.git,.hg,.svn,.idea,.tox}" -# ignore VCS folders (if the necessary grep flags are available) -VCS_FOLDERS="{.bzr,CVS,.git,.hg,.svn}" + # Check for --exclude-dir, otherwise check for --exclude. If --exclude + # isn't available, --color won't be either (they were released at the same + # time (v2.5): https://git.savannah.gnu.org/cgit/grep.git/tree/NEWS?id=1236f007 + if grep-flags-available --color=auto --exclude-dir=.cvs; then + GREP_OPTIONS="--color=auto --exclude-dir=$EXC_FOLDERS" + elif grep-flags-available --color=auto --exclude=.cvs; then + GREP_OPTIONS="--color=auto --exclude=$EXC_FOLDERS" + fi -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 + if [[ -n "$GREP_OPTIONS" ]]; then + # export grep, egrep and fgrep settings + alias grep="grep $GREP_OPTIONS" + alias egrep="egrep $GREP_OPTIONS" + alias fgrep="fgrep $GREP_OPTIONS" -# export grep settings -alias grep="grep $GREP_OPTIONS" + # write to cache file if cache directory is writable + if [[ -w "$ZSH_CACHE_DIR" ]]; then + alias -L grep egrep fgrep >| "$__GREP_CACHE_FILE" + fi + fi + + # Clean up + unset GREP_OPTIONS EXC_FOLDERS + unfunction grep-flags-available +fi -# clean up -unset GREP_OPTIONS -unset VCS_FOLDERS -unfunction grep-flag-available +unset __GREP_CACHE_FILE __GREP_ALIAS_CACHES diff --git a/lib/misc.zsh b/lib/misc.zsh index 61571afc9..a5d3af998 100644 --- a/lib/misc.zsh +++ b/lib/misc.zsh @@ -3,15 +3,15 @@ autoload -Uz is-at-least # *-magic is known buggy in some versions; disable if so if [[ $DISABLE_MAGIC_FUNCTIONS != true ]]; 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 + 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 @@ -25,7 +25,7 @@ env_default 'LESS' '-R' alias _='sudo ' ## more intelligent acking for ubuntu users -if which ack-grep &> /dev/null; then +if (( $+commands[ack-grep] )); then alias afind='ack-grep -il' else alias afind='ack -il' diff --git a/lib/spectrum.zsh b/lib/spectrum.zsh index 312ab2248..d5c22a8c5 100644 --- a/lib/spectrum.zsh +++ b/lib/spectrum.zsh @@ -1,4 +1,3 @@ -#! /bin/zsh # A script to make using 256 colors in zsh less painful. # P.C. Shyamshankar <sykora@lucentbeing.com> # Copied from https://github.com/sykora/etc/blob/master/zsh/functions/spectrum/ @@ -6,32 +5,31 @@ typeset -AHg FX FG BG FX=( - reset "%{[00m%}" - bold "%{[01m%}" no-bold "%{[22m%}" - italic "%{[03m%}" no-italic "%{[23m%}" - underline "%{[04m%}" no-underline "%{[24m%}" - blink "%{[05m%}" no-blink "%{[25m%}" - reverse "%{[07m%}" no-reverse "%{[27m%}" + reset "%{[00m%}" + bold "%{[01m%}" no-bold "%{[22m%}" + italic "%{[03m%}" no-italic "%{[23m%}" + underline "%{[04m%}" no-underline "%{[24m%}" + blink "%{[05m%}" no-blink "%{[25m%}" + reverse "%{[07m%}" no-reverse "%{[27m%}" ) for color in {000..255}; do - FG[$color]="%{[38;5;${color}m%}" - BG[$color]="%{[48;5;${color}m%}" + FG[$color]="%{[38;5;${color}m%}" + 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() { + local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris} for code in {000..255}; do - print -P -- "$code: %{$FG[$code]%}$ZSH_SPECTRUM_TEXT%{$reset_color%}" + 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() { + local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris} for code in {000..255}; do - print -P -- "$code: %{$BG[$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 f5e367fcb..3f71eb06a 100644 --- a/lib/termsupport.zsh +++ b/lib/termsupport.zsh @@ -17,7 +17,7 @@ function title { : ${2=$1} case "$TERM" in - cygwin|xterm*|putty*|rxvt*|ansi) + cygwin|xterm*|putty*|rxvt*|konsole*|ansi) print -Pn "\e]2;$2:q\a" # set window name print -Pn "\e]1;$1:q\a" # set tab name ;; @@ -32,10 +32,10 @@ function title { # 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 + echoti tsl + print -Pn "$1" + echoti fsl + fi fi ;; esac @@ -50,22 +50,52 @@ fi # Runs before showing the prompt function omz_termsupport_precmd { - emulate -L zsh - - if [[ "$DISABLE_AUTO_TITLE" == true ]]; then - return - fi - + [[ "$DISABLE_AUTO_TITLE" == true ]] && return title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE } # Runs before executing the command function omz_termsupport_preexec { + [[ "$DISABLE_AUTO_TITLE" == true ]] && return + emulate -L zsh setopt extended_glob - if [[ "$DISABLE_AUTO_TITLE" == true ]]; then - return + # split command into array of arguments + local -a cmdargs + cmdargs=("${(z)2}") + # if running fg, extract the command from the job description + if [[ "${cmdargs[1]}" = fg ]]; then + # get the job id from the first argument passed to the fg command + local job_id jobspec="${cmdargs[2]#%}" + # logic based on jobs arguments: + # http://zsh.sourceforge.net/Doc/Release/Jobs-_0026-Signals.html#Jobs + # https://www.zsh.org/mla/users/2007/msg00704.html + case "$jobspec" in + <->) # %number argument: + # use the same <number> passed as an argument + job_id=${jobspec} ;; + ""|%|+) # empty, %% or %+ argument: + # use the current job, which appears with a + in $jobstates: + # suspended:+:5071=suspended (tty output) + job_id=${(k)jobstates[(r)*:+:*]} ;; + -) # %- argument: + # use the previous job, which appears with a - in $jobstates: + # suspended:-:6493=suspended (signal) + job_id=${(k)jobstates[(r)*:-:*]} ;; + [?]*) # %?string argument: + # use $jobtexts to match for a job whose command *contains* <string> + job_id=${(k)jobtexts[(r)*${(Q)jobspec}*]} ;; + *) # %string argument: + # use $jobtexts to match for a job whose command *starts with* <string> + job_id=${(k)jobtexts[(r)${(Q)jobspec}*]} ;; + esac + + # override preexec function arguments with job command + if [[ -n "${jobtexts[$job_id]}" ]]; then + 1="${jobtexts[$job_id]}" + 2="${jobtexts[$job_id]}" + fi fi # cmd name only, or if this is sudo or ssh, the next cmd @@ -91,12 +121,13 @@ if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then function update_terminalapp_cwd() { emulate -L zsh - # Percent-encode the pathname. - local URL_PATH="$(omz_urlencode -P $PWD)" - [[ $? != 0 ]] && return 1 + # Percent-encode the host and path names. + local URL_HOST URL_PATH + URL_HOST="$(omz_urlencode -P $HOST)" || return 1 + URL_PATH="$(omz_urlencode -P $PWD)" || return 1 # Undocumented Terminal.app-specific control sequence - printf '\e]7;%s\a' "file://$HOST$URL_PATH" + printf '\e]7;%s\a' "file://$URL_HOST$URL_PATH" } # Use a precmd hook instead of a chpwd hook to avoid contaminating output |