#!/bin/bash # # bash completion script for ctct # # Copyright 2015,2016 Einhard Leichtfuß # # This file is part of ctct. # # ctct is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published # by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # ctct 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 Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with ctct. If not, see . # ## DEFAULT SETTINGS: datadir="@default_datadir@" system_config_dir="@default_confdir@" user_config_dir="@default_user_config_dir@" ## USER SETTINGS: test -f "$system_config_dir/config.sh" \ && source "$system_config_dir/config.sh" test -f "$user_config_dir/config.sh" \ && source "$user_config_dir/config.sh" _ctct() { local cur action opts COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" test $COMP_CWORD -gt 1 && action="${COMP_WORDS[1]}" if [ $COMP_CWORD -eq 1 ] && [[ "$cur" =~ ^- ]] then opts="-h -l -s -S -e -d \ --help --list-all --search-by-name --search-by-data --edit --delete" elif [ $COMP_CWORD -eq 1 ] \ || ( [ $COMP_CWORD -eq 2 ] && \ ( [ "$action" = "-e" ] \ || ( [[ "--edit" =~ ^"$action" ]] && [ ${#action} -ge 3 ] ))) \ || [ "$action" = "-d" ] \ || ( [[ "--delete" =~ ^"$action" ]] && [ ${#action} -ge 3 ] ) then opts= for file in "$HOME/.ctct"/*.* do name="${file##*/}" test -f "$file" && \ opts+="$name $(sed 's/^\(.*\)\.\(.*\)/\2.\1/' <<< "$name") " done fi COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 } complete -F _ctct ctct