Skip to content

Commit 6b98c25

Browse files
feat: runagent shell auto-completion
Press TAB to complete -m/--module-id option with agent IDs.
1 parent b3eb802 commit 6b98c25

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

core/imageroot/etc/profile.d/runagent.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,35 @@ if [ -n "${AGENT_STATE_DIR}" ] && [ -f "${AGENT_STATE_DIR}/agent.env" ]; then
1010
. ${AGENT_STATE_DIR}/agent.env
1111
export PATH
1212
fi
13+
14+
if [ -z "$BASH" ]; then
15+
return
16+
fi
17+
18+
_runagent_wastyped()
19+
{
20+
local xword checkword="$1"
21+
for xword in "${COMP_WORDS[@]}"; do
22+
if [[ "${xword}" == "${checkword}" ]]; then
23+
return 0
24+
fi
25+
done
26+
return 1
27+
}
28+
29+
_runagent_completions()
30+
{
31+
local cword="$2"
32+
local agents=()
33+
34+
if _runagent_wastyped "-l" || _runagent_wastyped "--list-modules"; then
35+
:
36+
elif _runagent_wastyped "-m" || _runagent_wastyped "--module-id" ; then
37+
agents+=($(runagent --list-modules | sort | grep ^"${cword}"))
38+
COMPREPLY+=($(compgen -W "${agents[*]}" -- "${cword}"))
39+
else
40+
COMPREPLY+=($(compgen -W "--list-modules --module-id --current-dir --help" -- "${cword}"))
41+
fi
42+
}
43+
44+
complete -F _runagent_completions runagent

0 commit comments

Comments
 (0)