Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tsoc
hg-misc-tools
Commits
c0285d0b
Commit
c0285d0b
authored
Mar 26, 2026
by
one
Browse files
[shell] Update hy-smi bash-completion
parent
f93c64de
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
23 deletions
+45
-23
shell/bash-completion/hy-smi
shell/bash-completion/hy-smi
+45
-23
No files found.
shell/bash-completion/hy-smi
View file @
c0285d0b
...
...
@@ -4,32 +4,30 @@ _hy_smi_completion() {
local
cur prev subcmds
COMPREPLY
=()
cur
=
"
${
COMP_WORDS
[COMP_CWORD]
}
"
prev
=
"
${
COMP_WORDS
[COMP_CWORD-1]
}
"
[[
$COMP_CWORD
-gt
0
]]
&&
prev
=
"
${
COMP_WORDS
[COMP_CWORD-1]
}
"
||
prev
=
""
# Subcommands
# Subcommands
(distinct from --mig/--multi-instance-gpu set option)
subcmds
=
"virtual mig"
# If cache variable _HY_SMI_OPTS is empty, parse options from help output.
# Lazily parse options from help output on first invocation.
# To force a refresh after upgrading hy-smi, run: unset _HY_SMI_OPTS
if
[[
-z
"
$_HY_SMI_OPTS
"
]]
;
then
# Extract only valid short/long options (e.g. -h, --help),
# avoiding punctuation-contaminated tokens like -h' or --foo.
export
_HY_SMI_OPTS
=
$(
hy-smi
-h
2>/dev/null |
awk
'{
for(i=1;i<=NF;i++) {
token=$i
while (match(token, /--[A-Za-z0-9][A-Za-z0-9-]*|-[A-Za-z0-9]/)) {
print substr(token, RSTART, RLENGTH)
token=substr(token, RSTART + RLENGTH)
}
}
}'
|
sort
-u
)
# Match both GNU-style long options (--foo-bar) and
# tool-specific single-dash multi-char options (-idmon, -sdmon, etc.)
_HY_SMI_OPTS
=
$(
hy-smi
-h
2>/dev/null
\
|
grep
-oP
'(?<!\w)(--[A-Za-z][A-Za-z0-9-]*|-[A-Za-z][A-Za-z0-9]*)'
\
|
sort
-u
)
fi
# Provide
intelligent suggestions for specific parameters (prev)
# Provide
completions for options that take specific values
case
"
${
prev
}
"
in
# File arguments
--load
|
--save
|
--filename
|
-fdmon
)
COMPREPLY
=(
$(
compgen
-f
--
"
${
cur
}
"
)
)
return
0
;;
# Enumerated string values
--loglevel
)
COMPREPLY
=(
$(
compgen
-W
"debug info warning error critical"
--
"
${
cur
}
"
)
)
return
0
...
...
@@ -42,6 +40,17 @@ _hy_smi_completion() {
COMPREPLY
=(
$(
compgen
-W
"on off stable"
--
"
${
cur
}
"
)
)
return
0
;;
-tdmon
)
COMPREPLY
=(
$(
compgen
-W
"text csv"
--
"
${
cur
}
"
)
)
return
0
;;
-sdmon
)
# Flags can be combined (e.g. cfpu), offer individual letters
COMPREPLY
=(
$(
compgen
-W
"c f p u"
--
"
${
cur
}
"
)
)
return
0
;;
# Binary 0/1 toggles
--direction
)
COMPREPLY
=(
$(
compgen
-W
"0 1"
--
"
${
cur
}
"
)
)
return
0
...
...
@@ -50,19 +59,32 @@ _hy_smi_completion() {
COMPREPLY
=(
$(
compgen
-W
"0 1"
--
"
${
cur
}
"
)
)
return
0
;;
# Multi-value enumerations
--setboost
)
COMPREPLY
=(
$(
compgen
-W
"0-AI(default), 1-HPC(default), 2-AI(typical), 3-HPC(typical)"
--
"
${
cur
}
"
)
)
# Valid levels per help output: 0-AI(default), 2-AI(typical), 3-HPC(typical)
# NOTE: 1 does NOT exist
COMPREPLY
=(
$(
compgen
-W
"0 2 3"
--
"
${
cur
}
"
)
)
return
0
;;
--setextendbw
)
# 0: off, 1: 1GB, 2: 2GB, 3: 4GB
COMPREPLY
=(
$(
compgen
-W
"0 1 2 3"
--
"
${
cur
}
"
)
)
return
0
;;
--channel
)
# 0-31 or all
COMPREPLY
=(
$(
compgen
-W
"
$(
seq
0 31
)
all"
--
"
${
cur
}
"
)
)
return
0
;;
--link
)
# 0-6 or all
COMPREPLY
=(
$(
compgen
-W
"0 1 2 3 4 5 6 all"
--
"
${
cur
}
"
)
)
return
0
;;
esac
if
[[
${
cur
}
==
-
*
]]
;
then
# Only complete the dynamically extracted flags
COMPREPLY
=(
$(
compgen
-W
"
${
_HY_SMI_OPTS
}
"
--
"
${
cur
}
"
)
)
return
0
fi
# Default complete all flags and subcommands
# Complete flags and subcommands
COMPREPLY
=(
$(
compgen
-W
"
${
_HY_SMI_OPTS
}
${
subcmds
}
"
--
"
${
cur
}
"
)
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment