feat: fzf inline editing completion#1191
Conversation
Signed-off-by: ArkhamKnight25 <[email protected]>
66f0238 to
d2c7ebb
Compare
fujitatomoya
left a comment
There was a problem hiding this comment.
@ArkhamKnight25 thanks for creating PR.
IMO, i am not inclined to take this approach, there could be many downsides with this PR because those shell scripts are not small shim... originally those shim scripts are meant to register ros2cli python application with our shell’s completion framework. (https://kislyuk.github.io/argcomplete/)
i believe the fundamental issue is that the scripts shadow the entire ros2 command with a shell function....
| fi | ||
|
|
||
| history -s -- "$full_cmd" | ||
| eval -- "$full_cmd" |
There was a problem hiding this comment.
is this a security concern? the user is presented with a pre-filled prompt they can edit freely, and the result is passed to eval?
There was a problem hiding this comment.
you are right, using eval will introduce a security risk, allowing execution of additional commands, will not use it.
|
|
||
| if ! command -v fzf &> /dev/null; then | ||
| echo "fzf is not installed. Install with: sudo apt install fzf" >&2 | ||
| command ros2 "$@" |
There was a problem hiding this comment.
it replaces the ros2 binary with a shell function for the entire session. that said, this will intercept all ros2 calls, including from other scripts. it changes behavior for every user who sources this file, not just in interactive completion contexts.
There was a problem hiding this comment.
yes shadowing ros2() will indeed start intercepting everything
| case "$*" in | ||
| "topic echo" | "topic info" | "topic hz" | \ | ||
| "topic bw" | "topic pub" | "topic type" | \ | ||
| "topic delay") |
There was a problem hiding this comment.
this matches "$*" (all args joined by space) against exact strings. i think there are some problems here,
ros2 topic echo(double space) does not.ros2 --log-level debug topic echodoes not match.- any future subcommands (e.g., ros2 topic inspect) won't be caught without updating these scripts.
There was a problem hiding this comment.
yes, it is fragile, will remove the pattern matching.
|
@fujitatomoya Thank you for reviewing it. So the flow would look something like this: And once the user selects it, it would look like this: Or can make it look better with just User can type the additional arguments after Then I’d update the five topic verbs (echo, info, hz, bw, type). Each verb would store a reference to its parser in And
I did think of this approach earlier, but it won't store it in the history, so dropped the idea. happy to adjust based on feedback. |
@fujitatomoya san, Please review the changes. Thank you.
Description
Added shell scripts (Bash + Zsh) that lets us pick topics, services and nodes with fzf, then drop us back on the command line so we can add flags before running. If you cancel fzf, it falls back to ros2cli's default picker. Should I keep this fallback or remove it?
Fixes #1184
Is this user-facing behavior change?
Yes, now we can easily hit up and down arrow keys to get the executed commands from the terminal.
Please let me know of any changes that are needed. It was interesting to learn about cli workflows. Thanks.