aboutsummaryrefslogtreecommitdiff
path: root/bash_completion.in
diff options
context:
space:
mode:
authorEinhard Leichtfuß <alguien@respiranto.de>2018-12-24 21:56:30 +0100
committerEinhard Leichtfuß <alguien@respiranto.de>2018-12-24 22:08:46 +0100
commite82f76b87ff9779532908a02315b6425fb8a53f4 (patch)
tree265ddbeb6281b29fdb4b34f90334359aa0f10245 /bash_completion.in
parent263743c43945d4ee8d0fcd88636db3ddd4981eaa (diff)
Rename conf file and bash completion script
Also, - Add the new manpage to the Makefile. - Add additional dependencies in README. - Fix some small formatting mistakes in ctct(1).
Diffstat (limited to 'bash_completion.in')
-rw-r--r--bash_completion.in94
1 files changed, 94 insertions, 0 deletions
diff --git a/bash_completion.in b/bash_completion.in
new file mode 100644
index 0000000..54aa137
--- /dev/null
+++ b/bash_completion.in
@@ -0,0 +1,94 @@
+#!/usr/bin/env bash
+#
+# bash completion script for ctct
+#
+# Copyright 2015 - 2017 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 <https://www.gnu.org/licenses/>.
+#
+
+_ctct()
+{
+ ## DEFAULT SETTINGS:
+ local datadir="@default_datadir@"
+ local system_config_dir="@default_confdir@"
+ local user_config_dir="@default_user_config_dir@"
+
+ local temp
+
+ ## USER SETTINGS:
+ temp=$(
+ 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"
+ echo "$datadir"
+ )
+ test -n "$temp" && datadir="$temp"
+
+ 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