summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2026-09-26 21:16:04 +0200
committerGitHub <noreply@github.com>2026-09-26 21:16:04 +0200
commit13612846c457ce8ae490a4033aff0cf3fe6f2dcb (patch)
treeeea198e62426d853f3d39ac4cbf05b3f2e76c827 /src
parent3979c9322b380a1a46f1fa4d08f1c980d883175b (diff)
parent412dfb9e933b9811b0731a60e4412af313d190ad (diff)
downloadvyos-1x-13612846c457ce8ae490a4033aff0cf3fe6f2dcb.tar.gz
vyos-1x-13612846c457ce8ae490a4033aff0cf3fe6f2dcb.zip
Merge pull request #5328 from BradKollmyer/T9077-literal-question-mark
cli: T9077: insert literal '?' inside quoted values instead of triggering help
Diffstat (limited to 'src')
-rw-r--r--src/etc/bash_completion.d/vyatta-op37
-rwxr-xr-xsrc/op_mode/toggle_help_binding.sh3
2 files changed, 38 insertions, 2 deletions
diff --git a/src/etc/bash_completion.d/vyatta-op b/src/etc/bash_completion.d/vyatta-op
index cedbcfbc1..444ca385d 100644
--- a/src/etc/bash_completion.d/vyatta-op
+++ b/src/etc/bash_completion.d/vyatta-op
@@ -35,6 +35,40 @@ test -z "$_vyatta_default_pager" && \
test -z "$VYATTA_PAGER" && \
declare -x VYATTA_PAGER=$_vyatta_default_pager
+# Handler for the '?' key. Outside of a quoted string, '?' shows the
+# completion help as before. Inside a quoted string (or after a
+# backslash), it self-inserts, so values like URLs with query strings
+# can be typed without Ctrl-V:
+# set firewall group remote-group X url 'https://example.com/list?key=abc'
+_vyatta_question_mark ()
+{
+ local head="${READLINE_LINE:0:READLINE_POINT}"
+ local i c in_sq='' in_dq='' esc=''
+ for (( i=0; i<${#head}; i++ )); do
+ c="${head:i:1}"
+ if [[ -n $esc ]]; then
+ esc=''
+ continue
+ fi
+ case $c in
+ \\) [[ -z $in_sq ]] && esc=1 ;;
+ \') [[ -z $in_dq ]] && { [[ -n $in_sq ]] && in_sq='' || in_sq=1; } ;;
+ \") [[ -z $in_sq ]] && { [[ -n $in_dq ]] && in_dq='' || in_dq=1; } ;;
+ esac
+ done
+ if [[ -n $in_sq || -n $in_dq || -n $esc ]]; then
+ READLINE_LINE="${READLINE_LINE:0:READLINE_POINT}?${READLINE_LINE:READLINE_POINT}"
+ (( READLINE_POINT++ ))
+ else
+ # 'bind -x' handlers cannot invoke readline functions directly, so
+ # ask the terminal for a Device Status Report (DSR); the terminal's
+ # reply (ESC [ 0 n) is bound to possible-completions below, which
+ # re-enters the standard help path with the line unchanged.
+ # Write to /dev/tty so help still works if stdout is redirected.
+ printf '\e[5n' > /dev/tty
+ fi
+}
+
_vyatta_op_do_key_bindings ()
{
if [[ "$SHELL" != "/bin/vbash" && "$SHELL" != "/sbin/radius_shell" ]]; then
@@ -45,7 +79,8 @@ _vyatta_op_do_key_bindings ()
shopt -u nullglob
case "$-" in
*i*)
- bind '"?": possible-completions'
+ bind -x '"?": _vyatta_question_mark'
+ bind '"\e[0n": possible-completions'
bind 'set show-all-if-ambiguous on'
bind_cmds=$(grep '^bind .* # vyatta key binding$' $HOME/.bashrc)
eval $bind_cmds
diff --git a/src/op_mode/toggle_help_binding.sh b/src/op_mode/toggle_help_binding.sh
index 7c8bc05ce..23550bff6 100755
--- a/src/op_mode/toggle_help_binding.sh
+++ b/src/op_mode/toggle_help_binding.sh
@@ -21,5 +21,6 @@ if [ "$1" == 'disable' ]; then
bind '"?": self-insert'
else
sed -i "/^bind '\"?\": .* # vyatta key binding$/d" $HOME/.bashrc
- bind '"?": possible-completions'
+ # default binding: quote-aware help handler from bash_completion.d/vyatta-op
+ bind -x '"?": _vyatta_question_mark'
fi