aboutsummaryrefslogtreecommitdiffstats
path: root/bash-completion.sh
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2015-03-21 17:13:32 +0100
committerGuilhem Moulin <guilhem@fripost.org>2015-03-23 12:54:09 +0100
commit80438cd2af17083d85bb12da6756961abfedecbb (patch)
treefa7f801395d3e38ceebc28cca7c14b97bbbfcbcc /bash-completion.sh
parentce23c7053355aa3bdae387959eeeb2a67ced2ad3 (diff)
Move the CLI part to a dedicated dir, with a separate Makefile.
Diffstat (limited to 'bash-completion.sh')
-rw-r--r--bash-completion.sh86
1 files changed, 0 insertions, 86 deletions
diff --git a/bash-completion.sh b/bash-completion.sh
deleted file mode 100644
index 81bee51..0000000
--- a/bash-completion.sh
+++ /dev/null
@@ -1,86 +0,0 @@
-# Bash completion support for icevault(1)
-# Copyright © 2015 Guilhem Moulin <guilhem@fripost.org>
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or (at
-# your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-_icevault() {
- local cur prev words cword
- _init_completion -n := || return
-
- COMPREPLY=()
- declare -a files
- local opts="--debug -h --help -p --show-passwords -s --socket= --version"
- local args="fill insert dump clip edit ls"
-
- local OPTIND IFS
- # find out if our $cur is an optional argument or a command
- for (( OPTIND = 1; OPTIND < cword; OPTIND++ )); do
- case "${words[OPTIND]}" in
- -s) (( OPTIND++ ));;
- --) break;;
- -*) ;;
- *) break;;
- esac
- done
-
- local p
- # list sockets (and dirs) only
- if [[ $OPTIND -eq $(( $cword + 1)) && "$prev" = -s ]] || [[ $OPTIND -eq $cword && "$cur" =~ ^--socket= ]]; then
- [[ $OPTIND -eq $cword && "$cur" =~ ^--socket= ]] && cur="${cur#--socket=}"
- _filedir
- files=( "${COMPREPLY[@]}" )
- COMPREPLY=()
- for p in "${files[@]}"; do
- [ -d "$p" -o -S "$p" ] && COMPREPLY+=( "$p" )
- done
- return
- fi
-
- # complete options and commands
- if [ $OPTIND -eq $cword -a "$cur" ]; then
- COMPREPLY+=( $(compgen -W "$opts $args" -- "$cur") )
- [ "${#COMPREPLY[@]}" -eq 1 -a "${COMPREPLY[0]}" = --socket= ] && compopt -o nospace
- fi
- [ $(($OPTIND + 1)) -lt $cword ] && return
-
- local trim=
- if [ -z "$cur" -a $(($OPTIND + 1)) -eq $cword -a "${words[OPTIND]}" = insert ]; then
- return
- elif [ -z "$cur" -a $OPTIND -eq $cword ] || [ -z "$cur" -a $(($OPTIND + 1)) -eq $cword -a "${words[OPTIND]}" = fill ]; then
- cur="$(./icevault _geturi)"/ # get URI from webpage
- else
- cur=$(dequote "$cur")
- # trim words with : or = in $COMP_WORDBREAKS; see __ltrim_colon_completions
- if [[ "$cur" == *[:=]* && "$COMP_WORDBREAKS" == *:* && "$COMP_WORDBREAKS" == *=* ]]; then
- trim=${cur%"${cur##*[:=]}"}
- elif [[ "$cur" == *:* && "$COMP_WORDBREAKS" == *:* ]]; then
- trim=${cur%"${cur##*:}"}
- elif [[ "$cur" == *=* && "$COMP_WORDBREAKS" == *=* ]]; then
- trim=${cur%"${cur##*=}"}
- fi
- fi
-
- local uri
- if [[ $OPTIND -eq $cword || ! "${words[OPTIND]}" =~ :// ]]; then
- compopt -o filenames -o noquote
- while read -r -d $'\0' uri; do
- # quote manually (so we don't quote the : and =)
- uri=$( echo "${uri#$trim}" | sed "s/[][\\{}*?~<>;'\"|&()\!$\` \t]/\\\\&/g" )
- COMPREPLY+=( "$uri" )
- done < <(./icevault -0 _complete "$cur")
- [ "${#COMPREPLY[@]}" -eq 1 -a "${COMPREPLY[0]: -1:1}" = / ] && compopt -o nospace
- return 0
- fi
-}
-complete -F _icevault icevault