scripts/dav-bash-completion.bash

Sat, 23 Nov 2019 11:46:45 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 23 Nov 2019 11:46:45 +0100
changeset 683
53bcb5e47220
parent 676
fb466ba2edc5
child 684
a4b4257c1a5f
permissions
-rw-r--r--

fix -c option for dav rm command

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
fb466ba2edc5 bash completion now handles spaces correctly in both quoted and unquoted strings
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
6 printf "%s\0" "$word"
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"
fb466ba2edc5 bash completion now handles spaces correctly in both quoted and unquoted strings
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
9 printf "\0"
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"
fb466ba2edc5 bash completion now handles spaces correctly in both quoted and unquoted strings
Mike Becker <universe@uap-core.de>
parents: 673
diff changeset
20 out=$(dav_completion_build_args | xargs -0 $cmd)
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
def0359fb48f adds some error detection to completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 434
diff changeset
25 fi
673
8e7e56cfc103 adds support for quotes in dav bash completion
Mike Becker <universe@uap-core.de>
parents: 457
diff changeset
26 if [[ $cmd_res -eq 12 ]]; then
435
def0359fb48f adds some error detection to completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 434
diff changeset
27 compopt -o default
def0359fb48f adds some error detection to completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 434
diff changeset
28 COMPREPLY=()
def0359fb48f adds some error detection to completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 434
diff changeset
29 else
434
bc173bae3caa improves dav-bash-completion.bash
Mike Becker <universe@uap-core.de>
parents: 431
diff changeset
30 IFS=$'\n' declare -ga 'COMPREPLY=($out)'
435
def0359fb48f adds some error detection to completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 434
diff changeset
31 fi
431
1e8592657a01 adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 }
1e8592657a01 adds semi-functional bash completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
435
def0359fb48f adds some error detection to completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 434
diff changeset
34 complete -F dav_completion dav
def0359fb48f adds some error detection to completion
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 434
diff changeset
35

mercurial