Skip to content

Commit

Permalink
complete_run: Be more careful about calling self
Browse files Browse the repository at this point in the history
COMP_WORDS/words gets filled with exact contents of the command line,
this includes application name. Usually application is invoked via $PATH
so this works fine, but it is also possible to specify a path containing
~ or env variables. This is usually expanded by shell.
this expansion is not performed by <( xxx ) so we are doing it by hand
instead

Fixes #315
  • Loading branch information
pacak committed Jan 19, 2024
1 parent a86daec commit 9011d8b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/complete_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ fn dump_bash_completer(name: &str) {
println!(
r#"_bpaf_dynamic_completion()
{{
source <( "$1" --bpaf-complete-rev=8 "${{COMP_WORDS[@]:1}}" )
line="$1 --bpaf-complete-rev=8 ${{COMP_WORDS[@]:1}}"
if [[ ${{COMP_WORDS[-1]}} == "" ]]; then
line="${{line}} \"\""
fi
source <( eval ${{line}})
}}
complete -o nosort -F _bpaf_dynamic_completion {name}"#,
name = name,
Expand All @@ -15,7 +19,12 @@ complete -o nosort -F _bpaf_dynamic_completion {name}"#,
fn dump_zsh_completer(name: &str) {
println!(
r#"#compdef {name}
source <( "${{words[1]}}" --bpaf-complete-rev=7 "${{words[@]:1}}" )
local line
line="${{words[1]}} --bpaf-complete-rev=7 ${{words[@]:1}}"
if [[ ${{words[-1]}} == "" ]]; then
line="${{line}} \"\""
fi
source <(eval ${{line}})
"#,
name = name
);
Expand Down

0 comments on commit 9011d8b

Please sign in to comment.