aboutsummaryrefslogtreecommitdiff
path: root/Functions
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-07-12 17:02:52 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-07-12 17:02:52 +0000
commit59c3d242d546059cad473f1155ad0e350fe45260 (patch)
treeaea57772a784915c5cd8e7bd485948f28842976a /Functions
parentb346c4796b3abdadd31cb0999d2f099ce9aa79af (diff)
downloadzsh-59c3d242d546059cad473f1155ad0e350fe45260.tar.gz
zsh-59c3d242d546059cad473f1155ad0e350fe45260.tar.xz
zsh-59c3d242d546059cad473f1155ad0e350fe45260.zip
Initial revision
Diffstat (limited to 'Functions')
-rw-r--r--Functions/Zle/.distfiles3
-rw-r--r--Functions/Zle/incremental-complete-word89
-rw-r--r--Functions/Zle/insert-files42
3 files changed, 134 insertions, 0 deletions
diff --git a/Functions/Zle/.distfiles b/Functions/Zle/.distfiles
new file mode 100644
index 000000000..429c133a0
--- /dev/null
+++ b/Functions/Zle/.distfiles
@@ -0,0 +1,3 @@
+DISTFILES_SRC='
+ .distfiles incremental-complete-word insert-files
+'
diff --git a/Functions/Zle/incremental-complete-word b/Functions/Zle/incremental-complete-word
new file mode 100644
index 000000000..2a9c1aff2
--- /dev/null
+++ b/Functions/Zle/incremental-complete-word
@@ -0,0 +1,89 @@
+# incremental-complete-word() {
+
+# Autoload this function, run `zle -N <func-name>' and bind <func-name>
+# to a key.
+
+# This allows incremental completion of a word. After starting this
+# command, a list of completion choices is shown after every character you
+# type, which you can delete with ^h or DEL. RET will accept the
+# completion so far. You can hit TAB to do normal completion and ^g to
+# abort back to the state when you started.
+#
+# Completion keys:
+# incremental_prompt Prompt to show in status line during icompletion;
+# the sequence `%u' is replaced by the unambiguous
+# part of all matches if there is any and it is
+# different from the word on the line
+# incremental_stop Pattern matching keys which will cause icompletion
+# to stop and the key to be re-executed
+# incremental_break Pattern matching keys which will cause icompletion
+# to stop and the key to be discarded
+# incremental_completer Set of completers, like the `completer' key
+# incremental_list If set to a non-empty string, the matches will be
+# listed on every key-press
+
+emulate -L zsh
+unsetopt autolist menucomplete automenu # doesn't work well
+
+local key lbuf="$LBUFFER" rbuf="$RBUFFER" pmpt word lastl lastr wid twid
+
+[[ -n "$compconfig[incremental_completer]" ]] &&
+set ${(s.:.)compconfig[incremental_completer]}
+pmpt="${compconfig[incremental_prompt]-incremental completion...}"
+
+if [[ -n "$compconfig[incremental_list]" ]]; then
+ wid=list-choices
+else
+ wid=complete-word
+fi
+
+zle $wid "$@"
+LBUFFER="$lbuf"
+RBUFFER="$rbuf"
+if [[ "${LBUFFER}${RBUFFER}" = *${_lastcomp[unambiguous]}* ]]; then
+ word=''
+else
+ word="${_lastcomp[unambiguous]}"
+fi
+zle -R "${pmpt//\\%u/$word}"
+read -k key
+
+while [[ '#key' -ne '#\\r' && '#key' -ne '#\\n' &&
+ '#key' -ne '#\\C-g' ]]; do
+ twid=$wid
+ if [[ "$key" = ${~compconfig[incremental_stop]} ]]; then
+ zle -U "$key"
+ return
+ elif [[ "$key" = ${~compconfig[incremental_break]} ]]; then
+ return
+ elif [[ '#key' -eq '#\\C-h' || '#key' -eq '#\\C-?' ]]; then
+ [[ $#LBUFFER -gt $#l ]] && LBUFFER="$LBUFFER[1,-2]"
+ elif [[ '#key' -eq '#\\t' ]]; then
+ zle complete-word "$@"
+ lbuf="$LBUFFER"
+ rbuf="$RBUFFER"
+ elif [[ '#key' -eq '#\\C-d' ]]; then
+ twid=list-choices
+ else
+ LBUFFER="$LBUFFER$key"
+ fi
+ lastl="$LBUFFER"
+ lastr="$RBUFFER"
+ zle $twid "$@"
+ LBUFFER="$lastl"
+ RBUFFER="$lastr"
+ if [[ "${LBUFFER}${RBUFFER}" = *${_lastcomp[unambiguous]}* ]]; then
+ word=''
+ else
+ word="${_lastcomp[unambiguous]}"
+ fi
+ zle -R "${pmpt//\\%u/$word}"
+ read -k key
+done
+
+if [[ '#key' -eq '#\\C-g' ]]; then
+ LBUFFER="$lbuf"
+ RBUFFER="$rbuf"
+fi
+zle -Rc
+# }
diff --git a/Functions/Zle/insert-files b/Functions/Zle/insert-files
new file mode 100644
index 000000000..10f90ed4a
--- /dev/null
+++ b/Functions/Zle/insert-files
@@ -0,0 +1,42 @@
+# insert-files() {
+
+# Autoload this function, run `zle -N <func-name>' and bind <func-name>
+# to a key.
+
+# This function allows you type a file pattern, and see the results of the
+# expansion at each step. When you hit return, they will be inserted into
+# the command line.
+
+emulate -L zsh
+setopt nobadpattern
+
+local key str files
+
+files=( *(N) )
+if (( $#files )); then
+ zle -R "files: ${str}_" "$files[@]"
+else
+ zle -R "files: ${str}_ (failed)"
+fi
+read -k key
+while [[ '#key' -ne '#\\r' && '#key' -ne '#\\n' &&
+ '#key' -ne '#\\C-g' ]]; do
+ if [[ '#key' -eq '#\\C-h' || '#key' -eq '#\\C-?' ]]; then
+ [[ -n "$str" ]] && str="$str[1,-2]"
+ else
+ str="$str$key"
+ fi
+ eval "files=( \${~str}*(N) )"
+ if (( $#files )); then
+ zle -R "files: ${str}_" "$files[@]"
+ else
+ zle -R "files: ${str}_ (failed)"
+ fi
+ read -k key
+done
+zle -Rc
+if [[ '#key' -ne '#\\C-g' && $#files -gt 0 ]]; then
+ [[ "$LBUFFER[-1]" = ' ' ]] || files=('' "$files[@]")
+ LBUFFER="$LBUFFER$files "
+fi
+# }