syntax: highlight commands following sudo-style wrappers#695
Conversation
Apply command-type coloring (built-in / function / file / error) to the
command word that follows wrapper commands such as sudo, doas, command,
nohup, env, and xargs. Previously only the first word of the line was
classified, so typos like "sudo nonexistant" showed nonexistant in the
default argument color rather than as an error.
The set of wrappers is configurable via "bleopt command_wrappers".
Wrapper-specific options that take an argument (e.g. "sudo -u USER",
"env -u VAR") are skipped over so the next command word is recognized
correctly, and nested wrappers ("sudo env CMD") are walked through to
the innermost command.
Signed-off-by: ChrisJr404 <chris@hacknow.com>
|
Thanks for the contribution. I haven't yet finalized the chroma interface, but basically, I would like to make # bashrc
function ble/cmdinfo/cmd:sudo/chroma { ble/progcolor/command-wrapper.chroma "$@"; }
function ble/cmdinfo/cmd:doas/chroma { ble/progcolor/command-wrapper.chroma "$@"; }
...instead of indirectly specifying that through However, I haven't yet concluded the entire interface. Actually, the original idea is to put the chroma settings in |
|
I need time to think about the design. |
|
Makes sense — the direct No rush from my side. I'll rework against whatever interface you settle on. If a draft of the contrib/chroma split would help inform the design, I can put one up; otherwise I'll wait for your decision on the shape. |
Took a stab at #692 — wasn't sure of the cleanest place to hook this in, so happy to move it if there's a better spot.
The idea is to register
ble/cmdinfo/cmd:NAME/chromafor a configurable list of wrapper commands (sudo,doas,command,nohup,env,xargs). The chroma walks past wrapper-specific options (handling things likesudo -u root,env VAR=val,--) and then applies the same command-type coloring used for the head of the line to the inner command word. Nested wrappers (sudo env CMD) are followed to the innermost command.The list is exposed as
bleopt command_wrappers. Setting it to an empty string disables the behavior; users can add or remove names withbleopt command_wrappers+=name/-=name. User-defined chromas for the same names are preserved across changes to the option.I went with hardcoded option specs per wrapper rather than tying into the existing
cmdspecmachinery to keep the patch self-contained. A smallcasecovers the flag-with-arg patterns each wrapper actually uses; happy to refactor ontocmdspec/optsif that's preferable.Manually verified against bash-5.3 with
out/ble.sh:sudo nonexistent_xyz→ second word colored as errorsudo ls,nohup ls,command ls,env FOO=1 ls→ second/third word picks upcommand_file/command_builtin/ etc.sudo cd,sudo _user_function→ builtin and function are highlighted correctlysudo -u root ls→-u rootskipped,lshighlightedsudo env nonexistent_xyz→ nested wrapper followed, innermost word colored as errorbleopt command_wrappers=→ behavior disabled, no chromas registeredbash out/ble.sh --testpasses with no new failures.Closes #692