about summary refs log tree commit diff
path: root/Functions/Zle/insert-files
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/Zle/insert-files
parentb346c4796b3abdadd31cb0999d2f099ce9aa79af (diff)
downloadzsh-59c3d242d546059cad473f1155ad0e350fe45260.tar.gz
zsh-59c3d242d546059cad473f1155ad0e350fe45260.tar.xz
zsh-59c3d242d546059cad473f1155ad0e350fe45260.zip
Initial revision
Diffstat (limited to 'Functions/Zle/insert-files')
-rw-r--r--Functions/Zle/insert-files42
1 files changed, 42 insertions, 0 deletions
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
+# }