Sun, 15 Dec 2019 18:43:01 +0100
Added tag v1.3.0 for changeset 33c9b0f17cb2
676
fb466ba2edc5
bash completion now handles spaces correctly in both quoted and unquoted strings
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
1 | dav_completion_build_args() { |
fb466ba2edc5
bash completion now handles spaces correctly in both quoted and unquoted strings
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
2 | local word |
fb466ba2edc5
bash completion now handles spaces correctly in both quoted and unquoted strings
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
3 | for i in "${!COMP_WORDS[@]}"; do |
fb466ba2edc5
bash completion now handles spaces correctly in both quoted and unquoted strings
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
4 | word="${COMP_WORDS[$i]}" |
fb466ba2edc5
bash completion now handles spaces correctly in both quoted and unquoted strings
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
5 | if [[ "$word" =~ ^\'|^\" ]]; then |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
676
diff
changeset
|
6 | printf "%s\n" "$word" |
676
fb466ba2edc5
bash completion now handles spaces correctly in both quoted and unquoted strings
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
7 | else |
fb466ba2edc5
bash completion now handles spaces correctly in both quoted and unquoted strings
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
8 | echo "$word" | xargs printf "%s" |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
676
diff
changeset
|
9 | printf "\n" |
676
fb466ba2edc5
bash completion now handles spaces correctly in both quoted and unquoted strings
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
10 | fi |
fb466ba2edc5
bash completion now handles spaces correctly in both quoted and unquoted strings
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
11 | done |
fb466ba2edc5
bash completion now handles spaces correctly in both quoted and unquoted strings
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
12 | } |
fb466ba2edc5
bash completion now handles spaces correctly in both quoted and unquoted strings
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
13 | |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | dav_completion() { |
676
fb466ba2edc5
bash completion now handles spaces correctly in both quoted and unquoted strings
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
15 | local cmd |
434
bc173bae3caa
improves dav-bash-completion.bash
Mike Becker <universe@uap-core.de>
parents:
431
diff
changeset
|
16 | local out |
bc173bae3caa
improves dav-bash-completion.bash
Mike Becker <universe@uap-core.de>
parents:
431
diff
changeset
|
17 | local cmd_res |
bc173bae3caa
improves dav-bash-completion.bash
Mike Becker <universe@uap-core.de>
parents:
431
diff
changeset
|
18 | |
676
fb466ba2edc5
bash completion now handles spaces correctly in both quoted and unquoted strings
Mike Becker <universe@uap-core.de>
parents:
673
diff
changeset
|
19 | cmd="${COMP_WORDS[0]} complete $COMP_CWORD" |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
676
diff
changeset
|
20 | out=$(dav_completion_build_args | $cmd 2> /dev/null) |
435
def0359fb48f
adds some error detection to completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
434
diff
changeset
|
21 | cmd_res=$? |
434
bc173bae3caa
improves dav-bash-completion.bash
Mike Becker <universe@uap-core.de>
parents:
431
diff
changeset
|
22 | |
673
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
457
diff
changeset
|
23 | if [[ $cmd_res -eq 10 ]]; then |
435
def0359fb48f
adds some error detection to completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
434
diff
changeset
|
24 | compopt -o nospace |
684
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
676
diff
changeset
|
25 | fi |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
676
diff
changeset
|
26 | |
a4b4257c1a5f
improve shell completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
676
diff
changeset
|
27 | |
673
8e7e56cfc103
adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents:
457
diff
changeset
|
28 | if [[ $cmd_res -eq 12 ]]; then |
435
def0359fb48f
adds some error detection to completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
434
diff
changeset
|
29 | compopt -o default |
def0359fb48f
adds some error detection to completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
434
diff
changeset
|
30 | COMPREPLY=() |
def0359fb48f
adds some error detection to completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
434
diff
changeset
|
31 | else |
434
bc173bae3caa
improves dav-bash-completion.bash
Mike Becker <universe@uap-core.de>
parents:
431
diff
changeset
|
32 | IFS=$'\n' declare -ga 'COMPREPLY=($out)' |
435
def0359fb48f
adds some error detection to completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
434
diff
changeset
|
33 | fi |
431
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | } |
1e8592657a01
adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | |
435
def0359fb48f
adds some error detection to completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
434
diff
changeset
|
36 | complete -F dav_completion dav |
def0359fb48f
adds some error detection to completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
434
diff
changeset
|
37 |