about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--Completion/Unix/Type/_remote_files17
2 files changed, 17 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 980dc81f0..529526f38 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2020-07-08  Oliver Kiddle  <okiddle@yahoo.co.uk>
+
+	* github #53: James Pike: Completion/Unix/Type/_remote_files:
+	allow specifying directory name.
+
 2020-07-07  Bart Schaefer  <schaefer@brasslantern.com>
 
 	* 46189: Test/comptest: Ignore exit status of final zpty_flush
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