-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bind: add variable and fix function completion #352
base: main
Are you sure you want to change the base?
Conversation
Add completion to the common invocation forms of: bind 'set variable-name value' and bind '"keyseq":function-name'
multiple separate readline commands can be supplied, putting in the check for `[[ $cword -gt 1 ]]` was a mistake.
for v in "${vals[@]}"; do | ||
[[ $v == "$val"* ]] && COMPREPLY+=("${pre}${val}${v/#$val}") | ||
done | ||
eval "$reset" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking eval "$reset"
might be a better/cleaner construct to use in these cases, rather than doing the $IFS
switcheroo, since eval "$reset"
works the same way regardless of $IFS
value and so doesn't require protection from non-default values. Curious what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistency and eval avoidance are good things to pursue.
_bind_vars() | ||
{ | ||
local pre=$1 var=$2 | ||
local v reset=$(shopt -p nocasematch); shopt -s nocasematch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above wrt shopt and eval
completions/bind
Outdated
local v reset=$(shopt -p nocasematch); shopt -s nocasematch | ||
while IFS=' ' read _ v _; do | ||
[[ $v == "$var"* ]] && COMPREPLY+=("${pre}${var}${v/#$var}") | ||
done < <(bind -v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Replaced with a command substitution approach.
_bind() | ||
{ | ||
local cur prev words cword | ||
_init_completion || return | ||
local cur prev words cword IFS=$'\n' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, this might actually provide for the IFS protection I mentioned above. Right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think IFS
would have to contain a space in order for the expansion of $reset
to be evaluated as separate words
c0e9459
to
09307f8
Compare
This adds completion to the common invocation forms of:
and
A little tricky because the whole argument is likely to be quoted and/or has colons in it.
Supported completions (works w/ or w/o
:
in$COMP_WORDBREAKS
):The variable names and values are completed in a case-insensitive and case-preserving manner.
I added some test but they seem to all be getting skipped, unless I put the
_bind()
function definition first in the file -- not sure what's up with that.