Skip to content

Commit b53b45c

Browse files
committed
completions: support completion of jobids with ascii f
Problem: The bash completions suggest jobids in f58 encoding, but users may want to complete jobs using a plain f since it is easier to type. For commands that can complete with jobids, if the current string starts with an ascii f, then force the suggested jobid list to be in f58plain encoding.
1 parent ba586ea commit b53b45c

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

etc/completions/flux.pre

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,17 @@ __get_flux_subcommands() {
129129
echo "$subcommands"
130130
}
131131

132+
# Helper to emit id.f58plain when match begins with `f`
133+
_flux_id_fmt()
134+
{
135+
local cur=$1
136+
local fmt="{id}"
137+
if [[ $cur == f* ]]; then
138+
fmt="{id.f58plain}"
139+
fi
140+
echo "${fmt}"
141+
}
142+
132143
# flux-cancel(1) completions
133144
_flux_cancel()
134145
{
@@ -143,7 +154,7 @@ _flux_cancel()
143154
"
144155
if [[ $cur != -* ]]; then
145156
# Attempt to substitute an active jobid
146-
active_jobs=$(flux jobs -no {id})
157+
active_jobs=$(flux jobs -no $(_flux_id_fmt $cur))
147158
COMPREPLY=( $(compgen -W "${active_jobs}" -- "$cur") )
148159
return 0
149160
fi
@@ -165,7 +176,7 @@ _flux_update()
165176
"
166177
if [[ $cur != -* ]]; then
167178
# Attempt to substitute an active jobid
168-
active_jobs="$(flux jobs -no {id})"
179+
active_jobs="$(flux jobs -no $(_flux_id_fmt $cur))"
169180
COMPREPLY=( $(compgen -W "${active_jobs}" -- "$cur") )
170181
return 0
171182
fi
@@ -516,7 +527,7 @@ _flux_job()
516527
if [[ $cur != -* ]]; then
517528
if _flux_contains_word ${cmd} ${subcmds}; then
518529
# These commands take active jobids by default:
519-
active_jobs=$(flux jobs -no {id})
530+
active_jobs=$(flux jobs -no $(_flux_id_fmt $cur))
520531
COMPREPLY=( $(compgen -W "${active_jobs}" -- "$cur") )
521532
return 0
522533
fi
@@ -1080,7 +1091,7 @@ _flux_watch()
10801091
"
10811092
if [[ $cur != -* ]]; then
10821093
# Attempt to substitute an active jobid
1083-
active_jobs=$(flux jobs -no {id})
1094+
active_jobs=$(flux jobs -no $(_flux_id_fmt $cur))
10841095
COMPREPLY=( $(compgen -W "${active_jobs}" -- "$cur") )
10851096
return 0
10861097
fi
@@ -1141,7 +1152,7 @@ _flux_top()
11411152
return 0
11421153
fi
11431154
# flux-top(1) can target jobids that are also instances
1144-
local jobs=$(flux jobs -no {uri}:{id} | grep -v ^None: \
1155+
local jobs=$(flux jobs -no {uri}:$(_flux_id_fmt $cur) | grep -v ^None: \
11451156
| sed -n 's/.*://p')
11461157
COMPREPLY=( $(compgen -W "${OPTS} $jobs" -- "$cur") )
11471158
if [[ "${COMPREPLY[@]}" == *= ]]; then

0 commit comments

Comments
 (0)