about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--Completion/Core/_path_files2
-rw-r--r--Completion/User/.distfiles4
-rw-r--r--Completion/User/_dd4
-rw-r--r--Completion/User/_tilde_files38
-rw-r--r--Src/Zle/compresult.c7
5 files changed, 46 insertions, 9 deletions
diff --git a/Completion/Core/_path_files b/Completion/Core/_path_files
index 892450f53..60a266482 100644
--- a/Completion/Core/_path_files
+++ b/Completion/Core/_path_files
@@ -36,7 +36,7 @@ if (( $#prepaths )); then
   if [[ "$tmp1[1]" = '(' ]]; then
     prepaths=( ${^=tmp1[2,-2]%/}/ )
   elif [[ "$tmp1[1]" = '/' ]]; then
-    prepaths=( "$tmp1/" )
+    prepaths=( "${tmp1%/}/" )
   else
     prepaths=( ${(P)^tmp1%/}/ )
     (( ! $#prepaths )) && prepaths=( ${tmp1%/}/ )
diff --git a/Completion/User/.distfiles b/Completion/User/.distfiles
index 4550b9c4d..7dafbfbca 100644
--- a/Completion/User/.distfiles
+++ b/Completion/User/.distfiles
@@ -9,7 +9,7 @@ DISTFILES_SRC='
     _perl_basepods _perl_builtin_funcs _perl_modules _perldoc
     _ports _prcs _prompt _ps _pspdf _psutils _rcs _rlogin _sh _socket
     _ssh _strip _stty _su _sudo _tar _tar_archive _telnet _tex _texi
-    _tiff _uncompress _unpack _urls _use_lo _user_at_host _users
-    _users_on _webbrowser _wget _whereis _whois _xargs _yodl _yp
+    _tiff _tilde_files _uncompress _unpack _urls _use_lo _user_at_host
+    _users _users_on _webbrowser _wget _whereis _whois _xargs _yodl _yp
     _zdump
 '
diff --git a/Completion/User/_dd b/Completion/User/_dd
index 3ae0a8417..fa322d791 100644
--- a/Completion/User/_dd
+++ b/Completion/User/_dd
@@ -11,10 +11,10 @@ if compset -P 1 'conv='; then
               ascii ebcdic ibm block unblock lcase ucase swab noerror sync
 elif compset -P 1 'if='; then
   _description files expl 'input file'
-  _files "$expl[@]"
+  _tilde_files "$expl[@]"
 elif compset -P 1 'of='; then
   _description files expl 'output file'
-  _files "$expl[@]"
+  _tilde_files "$expl[@]"
 else
   _wanted values expl option &&
       compadd "$expl[@]" -S '=' if of ibs obs bs cbs skip files seek count conv
diff --git a/Completion/User/_tilde_files b/Completion/User/_tilde_files
new file mode 100644
index 000000000..6fb393dc5
--- /dev/null
+++ b/Completion/User/_tilde_files
@@ -0,0 +1,38 @@
+#autoload
+
+# Complete files and expand tilde expansions in it.
+
+if (( $argv[(I)-W*] )); then
+  _files "$@"
+  return
+fi
+
+case "$PREFIX" in
+\~/*)
+  IPREFIX="${IPREFIX}${HOME}/"
+  PREFIX="${PREFIX[3,-1]}"
+  _files "$@" -W "${HOME}"
+  ;;
+\~*/*)
+  local user="${PREFIX[2,-1]%%/*}"
+
+  if (( $+userdirs[$user] )); then
+    user="$userdirs[$user]"
+  elif (( $+nameddirs[$user] )); then
+    user="$nameddirs[$user]"
+  else
+    _message "unknown user \`$user'"
+    return 1
+  fi
+  IPREFIX="${IPREFIX}${user%/}/"
+  PREFIX="${PREFIX#*/}"
+  _files "$@" -W "$user"
+  ;;
+\~*)
+  compset -P '?'
+  _users "$@"
+  ;;
+*)
+  _files "$@"
+  ;;
+esac
diff --git a/Src/Zle/compresult.c b/Src/Zle/compresult.c
index 64de5c744..d49c7b811 100644
--- a/Src/Zle/compresult.c
+++ b/Src/Zle/compresult.c
@@ -627,10 +627,9 @@ do_ambiguous(void)
 	cline_str(ainfo->line, 1, NULL);
 
 	/* Sometimes the different match specs used may result in a cline
-	 * that is shorter than the original string. If that happened, we
-	 * re-insert the old string. Unless there were matches added with
-	 * -U, that is. */
-	if (lastend - wb < we - wb && !hasunmatched) {
+	 * that gives an empty string. If that happened, we re-insert the
+         * old string. Unless there were matches added with -U, that is. */
+	if (!(lastend - wb) && !hasunmatched) {
 	    cs = wb;
 	    foredel(lastend - wb);
 	    inststrlen(old, 0, we - wb);