#!/bin/bash # # bash completion script for ctct # # Copyright 2015 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=@plain_datadir@ system_config_dir=@plain_confdir@ user_config_dir=@plain_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 prev opts COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" if [ $COMP_CWORD -eq 1 ] && [[ "$cur" =~ ^- ]] then opts="-h -l -s -S -e \ --help --list-all --search-by-name --search-by-data --edit" elif [ $COMP_CWORD -eq 1 ] || [ "$prev" = "-s" ] || [ "$prev" = "-e" ] 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