summaryrefslogtreecommitdiff
path: root/Functions
diff options
context:
space:
mode:
Diffstat (limited to 'Functions')
-rw-r--r--Functions/Misc/zcalc7
-rw-r--r--Functions/TCP/tcp_output3
-rw-r--r--Functions/VCS_Info/Backends/VCS_INFO_detect_hg2
-rw-r--r--Functions/VCS_Info/Backends/VCS_INFO_get_data_git33
-rw-r--r--Functions/VCS_Info/Backends/VCS_INFO_get_data_svn30
-rw-r--r--Functions/Zle/.distfiles3
-rw-r--r--Functions/Zle/expand-absolute-path19
-rw-r--r--Functions/Zle/read-from-minibuffer9
-rw-r--r--Functions/Zle/replace-argument48
-rw-r--r--Functions/Zle/zcalc-auto-insert8
10 files changed, 141 insertions, 21 deletions
diff --git a/Functions/Misc/zcalc b/Functions/Misc/zcalc
index 1f3392d92..63f67adb0 100644
--- a/Functions/Misc/zcalc
+++ b/Functions/Misc/zcalc
@@ -96,6 +96,9 @@
emulate -L zsh
setopt extendedglob
+# For testing in ZLE functions.
+local ZCALC_ACTIVE=1
+
# TODO: make local variables that shouldn't be visible in expressions
# begin with _.
local line ans base defbase forms match mbegin mend psvar optlist opt arg
@@ -196,8 +199,8 @@ while (( expression_mode )) ||
# special cases
# Set default base if `[#16]' or `[##16]' etc. on its own.
# Unset it if `[#]' or `[##]'.
- if [[ $line = (#b)[[:blank:]]#('[#'(\#|)(<->|)']')[[:blank:]]#(*) ]]; then
- if [[ -z $match[4] ]]; then
+ if [[ $line = (#b)[[:blank:]]#('[#'(\#|)((<->|)(|_|_<->))']')[[:blank:]]#(*) ]]; then
+ if [[ -z $match[6] ]]; then
if [[ -z $match[3] ]]; then
defbase=
else
diff --git a/Functions/TCP/tcp_output b/Functions/TCP/tcp_output
index 781c46c33..22e818e17 100644
--- a/Functions/TCP/tcp_output
+++ b/Functions/TCP/tcp_output
@@ -35,6 +35,9 @@ if [[ -n $tprompt ]]; then
cursess="c:0"
fi
zformat -f REPLY $tprompt "s:$sess" "f:$read_fd" $cursess
+ if [[ $REPLY = %P* ]]; then
+ REPLY=${(%)${REPLY##%P}}
+ fi
# We will pass this back up.
REPLY="$REPLY$*"
else
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_detect_hg b/Functions/VCS_Info/Backends/VCS_INFO_detect_hg
index a22c1ee0f..d7b1d0d36 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_detect_hg
+++ b/Functions/VCS_Info/Backends/VCS_INFO_detect_hg
@@ -7,7 +7,7 @@ setopt localoptions NO_shwordsplit
[[ $1 == '--flavours' ]] && { print -l hg-git hg-hgsubversion hg-hgsvn; return 0 }
VCS_INFO_check_com ${vcs_comm[cmd]} || return 1
-vcs_comm[detect_need_file]="store data"
+vcs_comm[detect_need_file]="store data sharedpath"
VCS_INFO_bydir_detect '.hg' || return 1
if [[ -d ${vcs_comm[basedir]}/.hg/svn ]] ; then
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
index e6791cb7a..76ab92f33 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git
@@ -5,6 +5,7 @@
setopt localoptions extendedglob NO_shwordsplit
local gitdir gitbase gitbranch gitaction gitunstaged gitstaged gitsha1
local stgitpatch stgitunapplied
+local -i querystaged queryunstaged
local -A hook_com
VCS_INFO_git_getaction () {
@@ -96,7 +97,7 @@ VCS_INFO_git_getbranch () {
gitbranch="$(${(z)gitsymref} 2> /dev/null)"
if [[ $? -ne 0 ]] ; then
- gitbranch="refs/tags/$(${vcs_comm[cmd]} describe --exact-match HEAD 2>/dev/null)"
+ gitbranch="refs/tags/$(${vcs_comm[cmd]} describe --all --exact-match HEAD 2>/dev/null)"
if [[ $? -ne 0 ]] ; then
gitbranch="${${"$(< $gitdir/HEAD)"}[1,7]}..."
@@ -120,14 +121,30 @@ if [[ -z ${gitdir} ]] || [[ -z ${gitbranch} ]] ; then
return 1
fi
-if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-changes" && \
- [[ "$(${vcs_comm[cmd]} rev-parse --is-inside-git-dir 2> /dev/null)" != 'true' ]] && \
- ${vcs_comm[cmd]} rev-parse --quiet --verify HEAD &> /dev/null ; then
+if zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-changes" ; then
+ querystaged=1
+ queryunstaged=1
+elif zstyle -t ":vcs_info:${vcs}:${usercontext}:${rrn}" "check-for-staged-changes" ; then
+ querystaged=1
+fi
+if (( querystaged || queryunstaged )) && \
+ [[ "$(${vcs_comm[cmd]} rev-parse --is-inside-work-tree 2> /dev/null)" == 'true' ]] ; then
# Default: off - these are potentially expensive on big repositories
- ${vcs_comm[cmd]} diff --no-ext-diff --ignore-submodules --quiet --exit-code ||
- gitunstaged=1
- ${vcs_comm[cmd]} diff-index --cached --quiet --ignore-submodules HEAD 2> /dev/null
- (( $? && $? != 128 )) && gitstaged=1
+ if (( queryunstaged )) ; then
+ ${vcs_comm[cmd]} diff --no-ext-diff --ignore-submodules --quiet --exit-code ||
+ gitunstaged=1
+ fi
+ if (( querystaged )) ; then
+ if ${vcs_comm[cmd]} rev-parse --quiet --verify HEAD &> /dev/null ; then
+ ${vcs_comm[cmd]} diff-index --cached --quiet --ignore-submodules HEAD 2> /dev/null
+ (( $? && $? != 128 )) && gitstaged=1
+ else
+ # empty repository (no commits yet)
+ # 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is the git empty tree.
+ ${vcs_comm[cmd]} diff-index --cached --quiet --ignore-submodules 4b825dc642cb6eb9a060e54bf8d69288fbee4904 2>/dev/null
+ (( $? && $? != 128 )) && gitstaged=1
+ fi
+ fi
fi
VCS_INFO_adjust
diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
index 41cc3e783..e56afee02 100644
--- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
+++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_svn
@@ -7,7 +7,7 @@
setopt localoptions noksharrays extendedglob NO_shwordsplit
local svnbase svnbranch a b rrn
local -i rc
-local -A svninfo parentinfo
+local -A svninfo parentinfo cwdinfo
local -xA hook_com
svnbase=".";
@@ -28,24 +28,34 @@ done
#rc=${pipestatus[1]}
#(( rc != 0 )) && return 1
-while [[ -d "${svnbase}/../.svn" ]]; do
- parentinfo=()
- ${vcs_comm[cmd]} info --non-interactive "${svnbase}/.." | while IFS=: read a b; do parentinfo[${a// /_}]="${b## #}"; done
- [[ ${parentinfo[Repository_UUID]} != ${svninfo[Repository_UUID]} ]] && break
- svninfo=(${(kv)parentinfo})
- svnbase="${svnbase}/.."
-done
+cwdinfo=(${(kv)svninfo})
+
+# Set svnbase to the wcroot path and svninfo to its `svn info`.
+if (( ${+svninfo[Working_Copy_Root_Path]} )); then
+ # svn 1.7+
+ svnbase=${svninfo[Working_Copy_Root_Path]}
+ ${vcs_comm[cmd]} info --non-interactive -- "${svnbase}" | while IFS=: read a b; do svninfo[${a// /_}]="${b## #}"; done
+else
+ # svn 1.0-1.6
+ while [[ -d "${svnbase}/../.svn" ]]; do
+ parentinfo=()
+ ${vcs_comm[cmd]} info --non-interactive -- "${svnbase}/.." | while IFS=: read a b; do parentinfo[${a// /_}]="${b## #}"; done
+ [[ ${parentinfo[Repository_UUID]} != ${svninfo[Repository_UUID]} ]] && break
+ svninfo=(${(kv)parentinfo})
+ svnbase="${svnbase}/.."
+ done
+fi
svnbase="$(VCS_INFO_realpath ${svnbase})"
rrn=${svnbase:t}
zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" branchformat svnbranch || svnbranch="%b:%r"
-hook_com=( branch "${svninfo[URL]##*/}" revision "${svninfo[Revision]}" )
+hook_com=( branch "${svninfo[URL]##*/}" revision "${cwdinfo[Revision]}" )
if VCS_INFO_hook 'set-branch-format' "${svnbranch}"; then
zformat -f svnbranch "${svnbranch}" "b:${hook_com[branch]}" "r:${hook_com[revision]}"
else
svnbranch=${hook_com[branch-replace]}
fi
hook_com=()
-VCS_INFO_formats '' "${svnbranch}" "${svnbase}" '' '' "${svninfo[Revision]}" ''
+VCS_INFO_formats '' "${svnbranch}" "${svnbase}" '' '' "${cwdinfo[Revision]}" ''
return 0
diff --git a/Functions/Zle/.distfiles b/Functions/Zle/.distfiles
index 256044fa5..90a07690b 100644
--- a/Functions/Zle/.distfiles
+++ b/Functions/Zle/.distfiles
@@ -10,6 +10,7 @@ delete-whole-word-match
down-case-word-match
down-line-or-beginning-search
edit-command-line
+expand-absolute-path
forward-word-match
history-beginning-search-menu
history-pattern-search
@@ -31,6 +32,7 @@ narrow-to-region-invisible
predict-on
quote-and-complete-word
read-from-minibuffer
+replace-argument
replace-string
replace-string-again
select-word-style
@@ -43,5 +45,6 @@ up-case-word-match
up-line-or-beginning-search
url-quote-magic
which-command
+zcalc-auto-insert
zed-set-file-name
'
diff --git a/Functions/Zle/expand-absolute-path b/Functions/Zle/expand-absolute-path
new file mode 100644
index 000000000..b85757600
--- /dev/null
+++ b/Functions/Zle/expand-absolute-path
@@ -0,0 +1,19 @@
+# expand-absolute-path
+# This is a ZLE widget to expand the absolute path to a file,
+# using directory naming to shorten the path where possible.
+
+emulate -L zsh
+setopt extendedglob cbases
+
+autoload -Uz modify-current-argument
+
+if (( ! ${+functions[glob-expand-absolute-path]} )); then
+ glob-expand-absolute-path() {
+ local -a files
+ files=(${~1}(N:A))
+ (( ${#files} )) || return
+ REPLY=${(D)files[1]}
+ }
+fi
+
+modify-current-argument glob-expand-absolute-path
diff --git a/Functions/Zle/read-from-minibuffer b/Functions/Zle/read-from-minibuffer
index 57e926884..8fec1105e 100644
--- a/Functions/Zle/read-from-minibuffer
+++ b/Functions/Zle/read-from-minibuffer
@@ -20,7 +20,9 @@ done
(( OPTIND > 1 )) && shift $(( OPTIND - 1 ))
local readprompt="$1" lbuf_init="$2" rbuf_init="$3"
+integer changeno=$UNDO_CHANGE_NO
+{
# Use anonymous function to make sure special values get restored,
# even if this function is called as a widget.
# local +h ensures special parameters stay special.
@@ -39,10 +41,17 @@ local readprompt="$1" lbuf_init="$2" rbuf_init="$3"
read -k $keys
stat=$?
else
+ local NUMERIC
+ unset NUMERIC
zle recursive-edit -K main
stat=$?
(( stat )) || REPLY=$BUFFER
fi
}
+} always {
+ # This removes the edits relating to the read from the undo history.
+ # These aren't useful once we get back to the main editing buffer.
+ zle undo $changeno
+}
return $stat
diff --git a/Functions/Zle/replace-argument b/Functions/Zle/replace-argument
new file mode 100644
index 000000000..0ef3de7b5
--- /dev/null
+++ b/Functions/Zle/replace-argument
@@ -0,0 +1,48 @@
+# Replace an argument to a command, delimited by normal shell syntax.
+# Prompts for the replacement.
+# With no numeric argument, replace the current argument.
+# With a numeric argument, replace that argument: 0 = command word,
+# as in history expansion.
+# If editing buffer is empty, use previous history line.
+
+autoload -Uz split-shell-arguments read-from-minibuffer
+
+if (( ${#BUFFER} == 0 )); then
+ (( HISTNO-- ))
+ CURSOR=${#BUFFER}
+fi
+
+local widget=$WIDGET numeric
+integer cursor=CURSOR
+if (( ${+NUMERIC} )); then
+ numeric=$NUMERIC
+fi
+local reply REPLY REPLY2
+integer index
+split-shell-arguments
+
+if [[ -n $numeric ]]; then
+ if (( numeric < 0 )); then
+ (( index = ${#reply} - 1 + 2*(numeric+1) ))
+ else
+ (( index = 2 + 2*numeric ))
+ fi
+else
+ (( index = REPLY & ~1 ))
+fi
+
+local edit
+if [[ $widget = *edit* ]]; then
+ edit=$reply[$index]
+fi
+read-from-minibuffer "Replace $reply[$index] with: " $edit || return 1
+
+integer diff=$(( ${#REPLY} - ${#reply[$index]} ))
+reply[$index]=$REPLY
+
+BUFFER=${(j..)reply}
+if (( cursor > REPLY2 )); then
+ (( CURSOR = cursor + diff ))
+else
+ (( CURSOR = REPLY2 ))
+fi
diff --git a/Functions/Zle/zcalc-auto-insert b/Functions/Zle/zcalc-auto-insert
new file mode 100644
index 000000000..c9a5c8867
--- /dev/null
+++ b/Functions/Zle/zcalc-auto-insert
@@ -0,0 +1,8 @@
+# Bind to a binary operator keystroke for use with zcalc
+
+if [[ -n $ZCALC_ACTIVE ]]; then
+ if [[ $CURSOR -eq 0 || $LBUFFER[-1] = "(" ]]; then
+ LBUFFER+=${ZCALC_AUTO_INSERT_PREFIX:-"ans "}
+ fi
+fi
+zle .self-insert