From b47a5f4f2b9a5f99d9bf95fc5e701ef6464f2c4d Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Fri, 19 Nov 1999 10:19:07 +0000 Subject: zsh-workers/8679 --- Completion/Base/_jobs | 48 +++++++++++++++++++++++++++++++++++++++++------- Doc/Zsh/compsys.yo | 5 +++++ 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 -- cgit 1.4.1