about summary refs log tree commit diff
path: root/Completion
diff options
context:
space:
mode:
authorJames Pike <jpike@chilon.net>2020-07-06 22:55:03 +0800
committerOliver Kiddle <okiddle@yahoo.co.uk>2020-07-08 17:20:10 +0200
commitdc8061ebe4d310492fee24412743db6c8afe4362 (patch)
tree86e4cd050b314c81be6ce112822e2ab4bf2305b9 /Completion
parent126a3158d5ba9b10bef23f7bdacdf910980dfbaa (diff)
downloadzsh-dc8061ebe4d310492fee24412743db6c8afe4362.tar.gz
zsh-dc8061ebe4d310492fee24412743db6c8afe4362.tar.xz
zsh-dc8061ebe4d310492fee24412743db6c8afe4362.zip
github #53: Allow specifying directory name for _remote_files
Diffstat (limited to 'Completion')
-rw-r--r--Completion/Unix/Type/_remote_files17
1 files changed, 12 insertions, 5 deletions
diff --git a/Completion/Unix/Type/_remote_files b/Completion/Unix/Type/_remote_files
index 3fa5779c8..b537406a0 100644
--- a/Completion/Unix/Type/_remote_files
+++ b/Completion/Unix/Type/_remote_files
@@ -4,13 +4,16 @@
 # key-based authentication with no passwords or a running ssh-agent to work.
 #
 # Usage:
-#   _remote_files [-/] [-g glob] [-h host] -- <cmd> [<cmd options>]
+#   _remote_files [-/] [-g glob] [-h host] [-W dir] -- <cmd> [<cmd options>]
 #
 # Options:
 # - -/: only complete directories
 # - -g: specify a pattern to match against files
 #       p, = and * glob qualifiers supported
 # - -h: specify the remote host, default is ${IPREFIX%:}
+# - -W: specify the parent directory to list files from,
+#       default is the home directory
+#
 #
 # Commands:
 # - ssh: Additional options for non-interactive use are automatically added
@@ -30,12 +33,12 @@
 # There should be coloring based on all the different ls -F classifiers.
 local expl rempat remfiles remdispf remdispd args cmd suf ret=1
 local -a args cmd_args
-local glob host
+local glob host dir dirprefix
 
 if zstyle -T ":completion:${curcontext}:files" remote-access; then
 
   # Parse options to _remote_files. Stops at the first "--".
-  zparseopts -D -E -a args / g:=glob h:=host
+  zparseopts -D -E -a args / g:=glob h:=host W:=dir
   (( $#host)) && shift host || host="${IPREFIX%:}"
 
   args=( ${argv[1,(i)--]} )
@@ -53,9 +56,13 @@ if zstyle -T ":completion:${curcontext}:files" remote-access; then
     cmd_args=( "$@" )
   fi
 
+  if (( $#dir )); then
+    dirprefix=${dir}/
+  fi
+
   if [[ -z $QIPREFIX ]]
-    then rempat="${PREFIX%%[^./][^/]#}\*"
-    else rempat="${(q)PREFIX%%[^./][^/]#}\*"
+    then rempat="${dirprefix}${PREFIX%%[^./][^/]#}\*"
+    else rempat="${dirprefix}${(q)PREFIX%%[^./][^/]#}\*"
   fi
 
   # remote filenames