summaryrefslogtreecommitdiff
path: root/Functions
diff options
context:
space:
mode:
Diffstat (limited to 'Functions')
-rw-r--r--Functions/Calendar/age14
-rw-r--r--Functions/MIME/zsh-mime-handler15
-rw-r--r--Functions/Misc/run-help4
-rw-r--r--Functions/Misc/zcalc28
-rw-r--r--Functions/Misc/zmv15
-rw-r--r--Functions/VCS_Info/Backends/VCS_INFO_get_data_git34
-rw-r--r--Functions/Zle/down-line-or-beginning-search2
-rw-r--r--Functions/Zle/keeper27
-rw-r--r--Functions/Zle/modify-current-argument35
-rw-r--r--Functions/Zle/up-line-or-beginning-search2
10 files changed, 126 insertions, 50 deletions
diff --git a/Functions/Calendar/age b/Functions/Calendar/age
index 8f6278fa2..17cf4d13e 100644
--- a/Functions/Calendar/age
+++ b/Functions/Calendar/age
@@ -18,7 +18,7 @@
# are allowed, but whitespace must be quoted to ensure age receives
# the correct arguments.
#
-# AGEREF1=2006/10/04:10:15
+# AGEREF=2006/10/04:10:15
# AGEREF2=2006/10/04:10:45
# print *(+age)
#
@@ -33,21 +33,27 @@ zmodload -i zsh/parameter
autoload -Uz calendar_scandate
+local timefmt
local -a vals tmp
[[ -e $REPLY ]] || return 1
-zstat -A vals +mtime $REPLY || return 1
+zstat -A vals +mtime -- $REPLY || return 1
if (( $# >= 1 )); then
if [[ $1 = :* ]]; then
- zstat -A tmp -F "%Y/%m/%d" +mtime ${1[2,-1]} || return 1
+ if (( $# > 1 )); then
+ timefmt="%Y/%m/%d:%H:%M:%S"
+ else
+ timefmt="%Y/%m/%d"
+ fi
+ zstat -A tmp -F $timefmt +mtime -- ${1#:} || return 1
local AGEREF=$tmp[1]
else
local AGEREF=$1
fi
# if 1 argument given, never use globally defined AGEREF2
if [[ $2 = :* ]]; then
- zstat -A tmp -F "%Y/%m/%d" +mtime ${2[2,-1]} || return 1
+ zstat -A tmp -F "%Y/%m/%d:%H:%M:%S" +mtime -- ${2#:} || return 1
local AGEREF2=$tmp[1]
else
local AGEREF2=$2
diff --git a/Functions/MIME/zsh-mime-handler b/Functions/MIME/zsh-mime-handler
index abaf0b6e3..24e5184fc 100644
--- a/Functions/MIME/zsh-mime-handler
+++ b/Functions/MIME/zsh-mime-handler
@@ -74,21 +74,25 @@ if [[ $suffix != *.* ]]; then
fi
suffix=${suffix#*.}
-local handler flags no_sh no_bg arg
+local handler flags no_sh no_bg arg bg_flag="&"
integer i
-local -a exec_asis hand_nonex
+local -a exec_asis hand_nonex exec_never
# Set to a list of patterns which are ignored and executed as they are,
# despite being called for interpretation by the mime handler.
# Defaults to executable files, which ensures that they are executed as
# they are, even if they have a suffix.
zsh-mime-contexts -a $suffix execute-as-is exec_asis || exec_asis=('*(*)' '*(/)')
+zsh-mime-contexts -a $suffix execute-never exec_never
# Set to a list of patterns for which the handler will be used even
# if the file doesn't exist on the disk.
zsh-mime-contexts -a $suffix handle-nonexistent hand_nonex ||
hand_nonex=('[[:alpha:]]#:/*')
+# Set to true if the job should be disowned.
+zsh-mime-contexts -t $suffix disown && bg_flag="&!"
+
local pattern
local -a files
@@ -122,6 +126,9 @@ fi
for pattern in $exec_asis; do
files=(${dirpref}${~pattern})
if [[ -n ${files[(r)$1]} ]]; then
+ for pattern in $exec_never; do
+ [[ ${1:A} = ${~pattern} ]] && break 2
+ done
if (( list )); then
for (( i = 1; i <= $#; i++ )); do
(( i == 1 )) || print -n " "
@@ -309,8 +316,8 @@ else
# Otherwise it's equivalent to removing the eval and all the quotes,
# including the (q) flags.
if [[ -n $stdin ]]; then
- eval cat ${(q)argv} "|" ${(q)execargs} "&"
+ eval cat ${(q)argv} "|" ${(q)execargs} $bg_flag
else
- eval ${(q)execargs} "&"
+ eval ${(q)execargs} $bg_flag
fi
fi
diff --git a/Functions/Misc/run-help b/Functions/Misc/run-help
index 6a9abb3cf..c817b67d6 100644
--- a/Functions/Misc/run-help
+++ b/Functions/Misc/run-help
@@ -56,6 +56,10 @@ do
[[ -n $noalias && $what = *" is an alias "* ]] && continue
builtin print -r $what
case $what in
+ (*( is an alias for (noglob|nocorrect))*)
+ [[ ${what[(w)7]:t} != ${what[(w)1]} ]] &&
+ run_help_orig_cmd=${what[(w)1]} run-help ${what[(w)7]:t}
+ ;;
(*( is an alias)*)
[[ ${what[(w)6]:t} != ${what[(w)1]} ]] &&
run_help_orig_cmd=${what[(w)1]} run-help ${what[(w)6]:t}
diff --git a/Functions/Misc/zcalc b/Functions/Misc/zcalc
index 2d0cf5d40..e9dcc78b9 100644
--- a/Functions/Misc/zcalc
+++ b/Functions/Misc/zcalc
@@ -114,7 +114,7 @@ float PI E
(( PI = 4 * atan(1), E = exp(1) ))
# Process command line
-while [[ -n $1 && $1 = -(|[#-]*) ]]; do
+while [[ -n $1 && $1 = -(|[#-]*|f) ]]; do
optlist=${1[2,-1]}
shift
[[ $optlist = (|-) ]] && break
@@ -139,6 +139,9 @@ while [[ -n $1 && $1 = -(|[#-]*) ]]; do
fi
defbase="[#${arg}]"
;;
+ (f) # Force floating point operation
+ setopt forcefloat
+ ;;
esac
done
done
@@ -152,7 +155,25 @@ for (( num = 1; num <= $#; num++ )); do
done
psvar[1]=$num
-while vared -cehp "${ZCALCPROMPT}" line; do
+local prev_line cont_prompt
+while vared -cehp "${cont_prompt}${ZCALCPROMPT}" line; do
+ if [[ $line = (|*[^\\])('\\')#'\' ]]; then
+ prev_line+=$line[1,-2]
+ cont_prompt="..."
+ line=
+ continue
+ fi
+ line="$prev_line$line"
+ prev_line=
+ cont_prompt=
+ # Test whether there are as many open as close
+ # parentheses in the line so far.
+ if [[ ${#line//[^\(]} -gt ${#line//[^\)]} ]]; then
+ prev_line+=$line
+ cont_prompt="..."
+ line=
+ continue
+ fi
[[ -z $line ]] && break
# special cases
# Set default base if `[#16]' or `[##16]' etc. on its own.
@@ -165,6 +186,7 @@ while vared -cehp "${ZCALCPROMPT}" line; do
defbase=$match[1]
fi
print -s -- $line
+ print -- $(( ${defbase} ans ))
line=
continue
else
@@ -220,7 +242,7 @@ while vared -cehp "${ZCALCPROMPT}" line; do
continue
;;
- ((:|)function[[:blank:]]##(#b)([^[:blank:]]##)(|[[:blank:]]##([^[:blank:]]*)))
+ ((function|:f(unc(tion|)|))[[:blank:]]##(#b)([^[:blank:]]##)(|[[:blank:]]##([^[:blank:]]*)))
zmathfuncdef $match[1] $match[3]
line=
continue
diff --git a/Functions/Misc/zmv b/Functions/Misc/zmv
index 4ba664e6d..269fe5ba5 100644
--- a/Functions/Misc/zmv
+++ b/Functions/Misc/zmv
@@ -93,7 +93,11 @@
# -p <program>
# Call <program> instead of cp, ln or mv. Whatever it does, it should
# at least understand the form '<program> -- <oldname> <newname>',
-# where <oldname> and <newname> are filenames generated.
+# where <oldname> and <newname> are filenames generated. <program>
+# will be split into words.
+# -P <program>
+# As -p, but the program doesn't understand the "--" convention.
+# In this case the file names must already be sane.
# -w Pick out wildcard parts of the pattern, as described above, and
# implicitly add parentheses for referring to them.
# -W Just like -w, with the addition of turning wildcards in the
@@ -123,14 +127,16 @@ setopt extendedglob
local f g args match mbegin mend files action myname tmpf opt exec
local opt_f opt_i opt_n opt_q opt_Q opt_s opt_M opt_C opt_L
-local opt_o opt_p opt_v opt_w opt_W MATCH MBEGIN MEND
+local opt_o opt_p opt_P opt_v opt_w opt_W MATCH MBEGIN MEND
local pat repl errstr fpat hasglobqual opat
typeset -A from to
integer stat
+local dashes=--
+
myname=${(%):-%N}
-while getopts ":o:p:MCLfinqQsvwW" opt; do
+while getopts ":o:p:P:MCLfinqQsvwW" opt; do
if [[ $opt = "?" ]]; then
print -r -- "$myname: unrecognized option: -$OPTARG" >&2
return 1
@@ -144,6 +150,7 @@ done
[[ -n $opt_C ]] && action=cp
[[ -n $opt_L ]] && action=ln
[[ -n $opt_p ]] && action=$opt_p
+[[ -n $opt_P ]] && action=$opt_P dashes=
if [[ -z $action ]]; then
action=$myname[-2,-1]
@@ -278,7 +285,7 @@ fi
for f in $files; do
[[ -z $to[$f] ]] && continue
- exec=($action ${=opt_o} $opt_s -- $f $to[$f])
+ exec=(${=action} ${=opt_o} $opt_s $dashes $f $to[$f])
[[ -n $opt_i$opt_n$opt_v ]] && print -r -- ${(q-)exec}
if [[ -n $opt_i ]]; then
read -q 'opt?Execute? ' || continue
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index e40571a0e..c44be398e 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -5,10 +5,10 @@
setopt localoptions extendedglob NO_shwordsplit
local gitdir gitbase gitbranch gitaction gitunstaged gitstaged gitsha1
local stgitpatch stgitunapplied
-local -xA hook_com
+local -A hook_com
VCS_INFO_git_getaction () {
- local gitaction='' gitdir=$1
+ local gitdir=$1
local tmp
for tmp in "${gitdir}/rebase-apply" \
@@ -22,7 +22,6 @@ VCS_INFO_git_getaction () {
else
gitaction="am/rebase"
fi
- printf '%s' ${gitaction}
return 0
fi
done
@@ -30,7 +29,7 @@ VCS_INFO_git_getaction () {
for tmp in "${gitdir}/rebase-merge/interactive" \
"${gitdir}/.dotest-merge/interactive" ; do
if [[ -f "${tmp}" ]] ; then
- printf '%s' "rebase-i"
+ gitaction="rebase-i"
return 0
fi
done
@@ -38,25 +37,35 @@ VCS_INFO_git_getaction () {
for tmp in "${gitdir}/rebase-merge" \
"${gitdir}/.dotest-merge" ; do
if [[ -d "${tmp}" ]] ; then
- printf '%s' "rebase-m"
+ gitaction="rebase-m"
return 0
fi
done
if [[ -f "${gitdir}/MERGE_HEAD" ]] ; then
- printf '%s' "merge"
+ gitaction="merge"
return 0
fi
if [[ -f "${gitdir}/BISECT_LOG" ]] ; then
- printf '%s' "bisect"
+ gitaction="bisect"
return 0
fi
+
+ if [[ -f "${gitdir}/CHERRY_PICK_HEAD" ]] ; then
+ if [[ -d "${gitdir}/sequencer" ]] ; then
+ gitaction=cherry-seq
+ else
+ gitaction=cherry
+ fi
+ return 0
+ fi
+
return 1
}
VCS_INFO_git_getbranch () {
- local gitbranch gitdir=$1 tmp actiondir
+ local gitdir=$1 tmp actiondir
local gitsymref="${vcs_comm[cmd]} symbolic-ref HEAD"
actiondir=''
@@ -95,12 +104,11 @@ VCS_INFO_git_getbranch () {
fi
fi
- printf '%s' "${gitbranch}"
return 0
}
gitdir=${vcs_comm[gitdir]}
-gitbranch="$(VCS_INFO_git_getbranch ${gitdir})"
+VCS_INFO_git_getbranch ${gitdir}
if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" get-revision ; then
gitsha1=$(${vcs_comm[cmd]} rev-parse --quiet --verify HEAD)
else
@@ -123,12 +131,14 @@ if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-changes" && \
fi
VCS_INFO_adjust
-gitaction="$(VCS_INFO_git_getaction ${gitdir})"
+VCS_INFO_git_getaction ${gitdir}
gitbase=${PWD%/${$( ${vcs_comm[cmd]} rev-parse --show-prefix )%/##}}
rrn=${gitbase:t}
local patchdir=${gitdir}/patches/${gitbranch}
-if [[ -d $patchdir ]] ; then
+if [[ -d $patchdir ]] && [[ -f $patchdir/applied ]] \
+ && [[ -f $patchdir/unapplied ]]
+then
local -a stgit_applied stgit_unapplied stgit_all
stgit_applied=(${(f)"$(< "${patchdir}/applied")"})
diff --git a/Functions/Zle/down-line-or-beginning-search b/Functions/Zle/down-line-or-beginning-search
index fbd2c3341..4c713f197 100644
--- a/Functions/Zle/down-line-or-beginning-search
+++ b/Functions/Zle/down-line-or-beginning-search
@@ -3,6 +3,8 @@
emulate -L zsh
+typeset -g __searching __savecursor
+
if [[ ${+NUMERIC} -eq 0 &&
( $LASTWIDGET = $__searching || $RBUFFER != *$'\n'* ) ]]
then
diff --git a/Functions/Zle/keeper b/Functions/Zle/keeper
index c29b22d6f..a40125771 100644
--- a/Functions/Zle/keeper
+++ b/Functions/Zle/keeper
@@ -4,6 +4,9 @@
# Shell Corner column on UnixReview.com in January 2005 at the URL
# <http://www.unixreview.com/documents/s=9513/ur0501a/ur0501a.htm>
#
+# Article still available on the Wayback Machine:
+# <http://web.archive.org/web/20050207041146/http://www.unixreview.com/documents/s=9513/ur0501a/ur0501a.htm>
+#
# A few minor edits have been made to those functions for this file. Key
# bindings are commented out to avoid clashes with any existing bindings.
##
@@ -69,17 +72,21 @@ zstyle ':completion:expand-kept-result:*' completer _insert_kept
# "_insert_kept".
_expand_word_and_keep() {
- function compadd() {
- local -A args
- zparseopts -E -A args J:
- if [[ $args[-J] == all-expansions ]]
- then
- builtin compadd -A kept "$@"
- kept=( ${(Q)${(z)kept}} )
- fi
- builtin compadd "$@"
+ {
+ function compadd {
+ local -A args
+ zparseopts -E -A args J:
+ if [[ $args[-J] == all-expansions ]]
+ then
+ builtin compadd -A kept "$@"
+ kept=( ${(Q)${(z)kept}} )
+ fi
+ builtin compadd "$@"
+ }
+ _expand_word
+ } always {
+ unfunction compadd
}
- { _expand_word } always { unfunction compadd }
}
zle -C _expand_word complete-word _expand_word_and_keep
diff --git a/Functions/Zle/modify-current-argument b/Functions/Zle/modify-current-argument
index 92851d600..941eb80af 100644
--- a/Functions/Zle/modify-current-argument
+++ b/Functions/Zle/modify-current-argument
@@ -14,24 +14,27 @@
setopt localoptions noksharrays multibyte
local -a reply
-integer REPLY REPLY2 fromend endoffset
+integer posword poschar fromend endoffset
+local REPLY REPLY2
autoload -Uz split-shell-arguments
split-shell-arguments
+(( posword = REPLY, poschar = REPLY2 ))
+
# Can't do this unless there's some text under or left of us.
-(( REPLY < 2 )) && return 1
+(( posword < 2 )) && return 1
# Get the index of the word we want.
-if (( REPLY & 1 )); then
+if (( posword & 1 )); then
# Odd position; need previous word.
- (( REPLY-- ))
+ (( posword-- ))
# Pretend position was just after the end of it.
- (( REPLY2 = ${#reply[REPLY]} + 1 ))
+ (( poschar = ${#reply[posword]} + 1 ))
fi
# Work out offset from end of string
-(( fromend = $REPLY2 - ${#reply[REPLY]} - 1 ))
+(( fromend = $poschar - ${#reply[posword]} - 1 ))
if (( fromend >= -1 )); then
# Cursor is near the end of the word, we'll try to keep it there.
endoffset=1
@@ -39,11 +42,17 @@ fi
# Length of all characters before current.
# Force use of character (not index) counting and join without IFS.
-integer wordoff="${(cj..)#reply[1,REPLY-1]}"
+integer wordoff="${(cj..)#reply[1,posword-1]}"
-# Replacement for current word. This could do anything to ${reply[REPLY]}.
-local ARG="${reply[REPLY]}" repl
-eval repl=\"$1\"
+# Replacement for current word. This could do anything to ${reply[posword]}.
+local ARG="${reply[posword]}" repl
+if [[ $1 != *ARG* ]]; then
+ REPLY=
+ $1 $ARG || return 1
+ repl=$REPLY
+else
+ eval repl=\"$1\"
+fi
if (( !endoffset )) && [[ ${repl[fromend,-1]} = ${ARG[fromend,-1]} ]]; then
# If the part of the string from here to the end hasn't changed,
@@ -54,8 +63,8 @@ fi
# New line: all words before and after current word, with
# no additional spaces since we've already got the whitespace
# and the replacement word in the middle.
-local left="${(j..)reply[1,REPLY-1]}${repl}"
-local right="${(j..)reply[REPLY+1,-1]}"
+local left="${(j..)reply[1,posword-1]}${repl}"
+local right="${(j..)reply[posword+1,-1]}"
if [[ endoffset -ne 0 && ${#repl} -ne 0 ]]; then
# Place cursor relative to end.
@@ -71,5 +80,5 @@ else
integer repmax=$(( ${#repl} + 1 ))
# Remember CURSOR starts from offset 0 for some reason, so
# subtract 1 from positions.
- (( CURSOR = wordoff + (REPLY2 > repmax ? repmax : REPLY2) - 1 ))
+ (( CURSOR = wordoff + (poschar > repmax ? repmax : poschar) - 1 ))
fi
diff --git a/Functions/Zle/up-line-or-beginning-search b/Functions/Zle/up-line-or-beginning-search
index 5348e7ad3..bdc39335a 100644
--- a/Functions/Zle/up-line-or-beginning-search
+++ b/Functions/Zle/up-line-or-beginning-search
@@ -3,6 +3,8 @@
emulate -L zsh
+typeset -g __searching __savecursor
+
if [[ $LBUFFER == *$'\n'* ]]; then
zle .up-line-or-history
__searching=''