about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-11-19 10:19:07 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-11-19 10:19:07 +0000
commitb47a5f4f2b9a5f99d9bf95fc5e701ef6464f2c4d (patch)
treebf1207155681c4d9ff1867976992b35e48558818
parent76a31dd1b62a0330a22940f391933de2fa7ab07d (diff)
downloadzsh-b47a5f4f2b9a5f99d9bf95fc5e701ef6464f2c4d.tar.gz
zsh-b47a5f4f2b9a5f99d9bf95fc5e701ef6464f2c4d.tar.xz
zsh-b47a5f4f2b9a5f99d9bf95fc5e701ef6464f2c4d.zip
zsh-workers/8679
-rw-r--r--Completion/Base/_jobs48
-rw-r--r--Doc/Zsh/compsys.yo5
2 files changed, 46 insertions, 7 deletions
diff --git a/Completion/Base/_jobs b/Completion/Base/_jobs
index 40d6efc34..d9297086b 100644
--- a/Completion/Base/_jobs
+++ b/Completion/Base/_jobs
@@ -22,13 +22,47 @@ else
   _description expl job
 fi
 
-disp=()
-jobs=()
-for job in "$jids[@]"; do
-  [[ -n "$desc" ]] &&
-      disp=( "$disp[@]" "${pfx}${(r:2:: :)job} -- ${(r:COLUMNS-8:: :)jobtexts[$job]}" )
-  jobs=( "$jobs[@]" "$job" )
-done
+if [[ -n "$desc" ]]; then
+  disp=()
+  for job in "$jids[@]"; do
+    [[ -n "$desc" ]] &&
+        disp=( "$disp[@]" "${pfx}${(r:2:: :)job} -- ${(r:COLUMNS-8:: :)jobtexts[$job]}" )
+  done
+fi
+
+if _style jobs strings; then
+  local texts i text str tmp
+
+  # Find shortest unambiguous strings.
+
+  texts=( "$jobtexts[@]" )
+  jobs=()
+  for i in "$jids[@]"; do
+    text="$jobtexts[$i]"
+    str="${text%% *}"
+    if [[ "$text" = *\ * ]]; then
+      text="${text#* }"
+    else
+      text=""
+    fi
+    tmp=( "${(@M)texts:#${str}*}" )
+    while [[ -n "$text" && $#tmp -ge 2 ]]; do
+      str="${str} ${text%% *}"
+      if [[ "$text" = *\ * ]]; then
+        text="${text#* }"
+      else
+        text=""
+      fi
+      tmp=( "${(@M)texts:#${str}*}" )
+    done
+
+    jobs=( "$jobs[@]" "$str" )
+  done
+
+  [[ -n "$pfx" && -n "$desc" ]] && disp=( "${(@)disp#%}" )
+else
+  jobs=( "$jids[@]" )
+fi
 
 if [[ -n "$desc" ]]; then
   compadd "$@" "$expl[@]" -ld disp - "%$^jobs[@]"
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index d5393e9a1..1f1dac658 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -1065,6 +1065,11 @@ command will always insert matches as if menu-completion were started
 and it will stop when the last match is inserted. If this style is set
 to tt(verbose) a message will be displayed when the last match is reached.
 )
+item(tt(strings))(
+This is used with the tt(jobs) tag. If it is `true', the completions
+will use the shortest unambiguous strings of the jobs' command lines
+instead of the job numbers.
+)
 item(tt(substitute))(
 If this is unset or set to the empty string, the tt(_expand) completer
 will first try to expand all substitutions in the string (such as