#!/usr/bin/env bash # # bash completion script for ctct # # Copyright 2015 - 2018 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 . # _ctct() { ## DEFAULT SETTINGS: local sysconfdir="@sysconfdir_expanded@" local user_config_file="@default_user_config_file@" local datadir="@default_datadir@" local temp ## USER SETTINGS: test -f "$sysconfdir/ctct_config" \ && source "$sysconfdir/ctct_config" test -f "$user_config_file" \ && source "$user_config_file" local cur action opts typeset -i i COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" test $COMP_CWORD -gt 1 && action="${COMP_WORDS[1]}" if [ $COMP_CWORD -eq 1 ] && [[ "$cur" =~ ^- ]] then COMPREPLY=( $(compgen -W \ "-h -l -s -S -e -d \ --help --list-all --search-by-name --search-by-data --edit --delete \ --rename --version" \ -- "${cur}") ) elif [ $COMP_CWORD -eq 1 ] \ || ( [ $COMP_CWORD -eq 2 ] && \ ( [ "$action" = "-e" ] \ || ( [[ "--edit" =~ ^"$action" ]] && [ ${#action} -ge 3 ] ) \ || ( [[ "--rename" =~ ^"$action" ]] && [ ${#action} -ge 3 ] ))) \ || [ "$action" = "-d" ] \ || ( [[ "--delete" =~ ^"$action" ]] && [ ${#action} -ge 3 ] ) then i=0 shopt -s nullglob for file in "$HOME/.ctct"/"$cur"* do COMPREPLY[i++]="${file##*/}" done if [[ "$cur" =~ \. ]] then cur=( ${cur/\./ } ) for file in "$HOME/.ctct"/"${cur[1]}"*."${cur[0]}" do file="${file##*/}" COMPREPLY[i++]="${cur[0]}.${file%.*}" done else for file in "$HOME/.ctct"/*."$cur"* do file="${file##*/}" file=( ${file/\./ } ) COMPREPLY[i++]="${file[1]}.${file[0]}" done fi shopt -u nullglob fi return 0 } complete -F _ctct ctct # vi: ts=2 sw=2