From e82f76b87ff9779532908a02315b6425fb8a53f4 Mon Sep 17 00:00:00 2001 From: Einhard Leichtfuß Date: Mon, 24 Dec 2018 21:56:30 +0100 Subject: 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). --- CHANGELOG | 7 ++++ Makefile.in | 33 +++++++++-------- README | 2 ++ TODO | 12 +++---- bash_completion.in | 94 +++++++++++++++++++++++++++++++++++++++++++++++++ config.sh.in | 15 -------- configure | 56 +++++++++++------------------ configure.ac | 55 ++++++++++++----------------- ctct.1.in | 11 +++--- ctct.bash_completion.in | 94 ------------------------------------------------- ctct.in | 11 +++--- ctct_config.5.in | 17 +++++---- ctct_config.in | 14 ++++++++ 13 files changed, 202 insertions(+), 219 deletions(-) create mode 100644 bash_completion.in delete mode 100644 config.sh.in delete mode 100644 ctct.bash_completion.in create mode 100644 ctct_config.in diff --git a/CHANGELOG b/CHANGELOG index 43f9792..1223dfb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -24,6 +24,13 @@ Manual: - Improve and correct ctct(1) and ctct_config(5). +Configuration Files: +-------------------- + +- Renamed to ctct_config. +- Installed global configuration file directly into sysconfdir. + + Compatibility: -------------- - Fixed incompatibility with OpenBSD. diff --git a/Makefile.in b/Makefile.in index 656c116..ed1cdeb 100644 --- a/Makefile.in +++ b/Makefile.in @@ -26,7 +26,9 @@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ SRCS = @PACKAGE_NAME@.c DOCS = COPYING README CHANGELOG -CONFIGS = config.sh + +# If there were more than one, a separate confdir should be created. +CONFIG = ctct_config INSTALL = install INSTALL_PROGRAM = $(INSTALL) -m 755 @@ -39,44 +41,47 @@ exec_prefix = @exec_prefix@ bindir = @bindir@ datarootdir = @datarootdir@ sysconfdir = @sysconfdir@ -confdir = @confdir@ docdir = @docdir@ bash_completion_dir = @bash_completion_dir@ mandir = @mandir@ -man1dir = ${mandir}/man1 +man1dir = $(mandir)/man1 +man5dir = $(mandir)/man5 man1ext = .1 +man5ext = .5 all: $(TARGET) install: installdirs $(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)$(bindir)/ - $(INSTALL_DATA) $(CONFIGS) $(DESTDIR)$(confdir)/ + $(INSTALL_DATA) $(CONFIG) $(DESTDIR)$(sysconfdir)/ $(INSTALL_DATA) $(DOCS) $(DESTDIR)$(docdir)/ - $(INSTALL_DATA) $(TARGET).bash_completion \ + $(INSTALL_DATA) bash_completion \ $(DESTDIR)$(bash_completion_dir)/$(TARGET) $(INSTALL_DATA) $(TARGET)$(man1ext) $(DESTDIR)$(man1dir)/ + $(INSTALL_DATA) $(CONFIG)$(man5ext) $(DESTDIR)$(man5dir)/ installdirs: $(INSTALL_DIR) $(DESTDIR)$(bindir) - $(INSTALL_DIR) $(DESTDIR)$(confdir) + $(INSTALL_DIR) $(DESTDIR)$(sysconfdir) $(INSTALL_DIR) $(DESTDIR)$(docdir) $(INSTALL_DIR) $(DESTDIR)$(bash_completion_dir) $(INSTALL_DIR) $(DESTDIR)$(man1dir) + $(INSTALL_DIR) $(DESTDIR)$(man5dir) uninstall: $(RM) $(DESTDIR)$(bindir)/$(TARGET) - # only remove configuration file if unchanged - for file in $(CONFIGS); do \ - if cmp $$file $(DESTDIR)$(confdir)/$$file; then \ - $(RM) $(DESTDIR)$(confdir)/$$file; \ - fi \ - done - -$(RM) -d $(DESTDIR)$(confdir) - for file in $(DOCS); do \ + # Only remove configuration file if unchanged. + if cmp $(CONFIG) $(DESTDIR)$(sysconfdir)/$(CONFIG); \ + then \ + $(RM) $(DESTDIR)$(sysconfdir)/$(CONFIG); \ + fi + for file in $(DOCS); \ + do \ $(RM) $(DESTDIR)$(docdir)/$$file; \ done -$(RM) -d $(DESTDIR)$(docdir) $(RM) $(DESTDIR)$(bash_completion_dir)/$(TARGET) $(RM) $(DESTDIR)$(man1dir)/$(TARGET)$(man1ext) + $(RM) $(DESTDIR)$(man5dir)/$(CONFIG)$(man5ext) .PHONY: install installdirs uninstall diff --git a/README b/README index dd5bda5..ffb7f38 100644 --- a/README +++ b/README @@ -37,6 +37,8 @@ Dependencies: bash grep coreutils +find +sed Licensing: diff --git a/TODO b/TODO index 0994a89..1c732c5 100644 --- a/TODO +++ b/TODO @@ -5,16 +5,18 @@ TODO file for ctct `- to circumvent the necessity for eval * Honor $VISUAL. * Use git tags for future versions. -* Rename ctct/config.sh to ctct_config. * On `ctct -s ', do not match illegal sequences (e.g. a+b). * On `ctct -l', do only list legal names (e.g. not a+b). +* Use the EXIT_* variables. * [consider] On `ctct -d', check format of string. * [consider] Remove character restriction except '.', '/'. * [consider] Use `grep -F' for --search-by-name. -* Use the EXIT_* variables. +* [consider] Require at least one argument for --search-by-*. [CONFIGURE SCRIPT] * Take care of some_dir=/ (man page). +* Fully expand all variables found outside Makefile.in, like is already done + for sysconfdir_expanded. [FEATURES] * [consider] Allow for directories with special meaning (e.g. pictures/). @@ -29,11 +31,7 @@ TODO file for ctct * [consider] Use another default editor. `- nano, easily understandable. `- ed, the editor. +* Honor XDG user dirs. [MANUAL] * Add an EXAMPLE section to ctct(1). - -[BUGS] -* strange behaviour: - `- `ctct -S $'mobile\nabc' - `- `ctct -S $'mobile\na' 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 . +# + +_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 diff --git a/config.sh.in b/config.sh.in deleted file mode 100644 index d0eb94e..0000000 --- a/config.sh.in +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -# -# configuration file for ctct -# default values are commented out -# - -# user_config_dir="@default_user_config_dir@" -# datadir="@default_datadir@" -# fallback_editor="@default_fallback_editor@" -# default_editor= -# input_program="@default_input_program@" -# output_program="@default_output_program@" -# visual_program="@default_visual_program@" -# confirm_deletion=@default_confirm_deletion@ -# confirm_default_yes=@default_confirm_default_yes@ diff --git a/configure b/configure index 2e278a5..b3b2ca9 100755 --- a/configure +++ b/configure @@ -591,12 +591,10 @@ default_confirm_deletion default_visual_program default_output_program default_input_program -default_user_config_dir default_fallback_editor default_datadir -default_confdir +sysconfdir_expanded bash_completion_dir -confdir target_alias host_alias build_alias @@ -642,11 +640,9 @@ enable_option_checking ac_precious_vars='build_alias host_alias target_alias -confdir bash_completion_dir default_datadir default_fallback_editor -default_user_config_dir default_input_program default_output_program default_visual_program @@ -1258,15 +1254,12 @@ if test -n "$ac_init_help"; then cat <<\_ACEOF Some influential environment variables: - confdir 'system wide configuration directory' bash_completion_dir 'directory to store bash-completion script in' default_datadir 'directory to store contact data in' default_fallback_editor 'editor to use if EDITOR is unset' - default_user_config_dir - 'user configuration directory' default_input_program 'the program that newly created or edited contact files get passed to on stdin' @@ -1711,46 +1704,41 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu -ac_config_files="$ac_config_files Makefile ctct.1 ctct_config.5 ctct.bash_completion config.sh" +ac_config_files="$ac_config_files Makefile ctct.1 ctct_config.5 bash_completion ctct_config" ac_config_files="$ac_config_files ctct" -# Do not use $(.) notation here, confdir shall allow for shell substitution. - -test -z "$confdir" && confdir='${sysconfdir}/${TARGET}' - test -z "$bash_completion_dir" \ && bash_completion_dir='${datarootdir}/bash-completion/completions' -# Used in manpage. Needs to be fully expanded. +# Used in manpage and the ctct script. Needs to be fully expanded. # Use a function to allow for local variables. fun() { - if test -z "$default_confdir" - then + local prefix="$prefix" + local TARGET="$PACKAGE_NAME" + local next - # If $prefix is unset by the user, set it to autoconf's default value: - test "$prefix" = NONE && local prefix=/usr/local + # If $prefix is unset by the user, set it to autoconf's default value: + test "$prefix" = NONE && prefix=/usr/local - # Prevent //. - test "$prefix" = / && local prefix='' + # Prevent //. + test "$prefix" = / && prefix='' - local TARGET="$PACKAGE_NAME" - default_confdir="$confdir" + sysconfdir_expanded="$sysconfdir" - # Resolve $confdir recursively (notably including $prefix): - while - eval "default_confdir_expand=\"$default_confdir\"" - test "$default_confdir" != "$default_confdir_expand" - do - default_confdir="$default_confdir_expand" - done - fi + # Expand $sysconfdir recursively (notably including $prefix): + while + eval "next=\"$sysconfdir_expanded\"" + test "$next" != "$sysconfdir_expanded" + do + sysconfdir_expanded="$next" + done }; fun @@ -1761,10 +1749,6 @@ test -z "$default_datadir" && default_datadir='$HOME/.ctct' test -z "$default_fallback_editor" && default_fallback_editor=vi -test -z "$default_user_config_dir" \ - && default_user_config_dir='$HOME/.config/'"$PACKAGE_NAME" - - test -z "$default_input_program" \ && default_input_program='cat' @@ -2493,8 +2477,8 @@ do "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; "ctct.1") CONFIG_FILES="$CONFIG_FILES ctct.1" ;; "ctct_config.5") CONFIG_FILES="$CONFIG_FILES ctct_config.5" ;; - "ctct.bash_completion") CONFIG_FILES="$CONFIG_FILES ctct.bash_completion" ;; - "config.sh") CONFIG_FILES="$CONFIG_FILES config.sh" ;; + "bash_completion") CONFIG_FILES="$CONFIG_FILES bash_completion" ;; + "ctct_config") CONFIG_FILES="$CONFIG_FILES ctct_config" ;; "ctct") CONFIG_FILES="$CONFIG_FILES ctct" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; diff --git a/configure.ac b/configure.ac index 8ffce4e..70cf150 100644 --- a/configure.ac +++ b/configure.ac @@ -23,47 +23,42 @@ AC_CONFIG_FILES( [Makefile] [ctct.1] [ctct_config.5] - [ctct.bash_completion] - [config.sh] + [bash_completion] + [ctct_config] ) AC_CONFIG_FILES([ctct], [chmod +x ctct]) -# Do not use $(.) notation here, confdir shall allow for shell substitution. -AC_ARG_VAR([confdir], ['system wide configuration directory']) -test -z "$confdir" && confdir='${sysconfdir}/${TARGET}' - AC_ARG_VAR([bash_completion_dir], ['directory to store bash-completion script in']) test -z "$bash_completion_dir" \ && bash_completion_dir='${datarootdir}/bash-completion/completions' -# Used in manpage. Needs to be fully expanded. -AC_SUBST([default_confdir]) +# Used in manpage and the ctct script. Needs to be fully expanded. +AC_SUBST([sysconfdir_expanded]) # Use a function to allow for local variables. fun() { - if test -z "$default_confdir" - then - - # If $prefix is unset by the user, set it to autoconf's default value: - test "$prefix" = NONE && local prefix=/usr/local - - # Prevent //. - test "$prefix" = / && local prefix='' - - local TARGET="$PACKAGE_NAME" - default_confdir="$confdir" - - # Resolve $confdir recursively (notably including $prefix): - while - eval "default_confdir_expand=\"$default_confdir\"" - test "$default_confdir" != "$default_confdir_expand" - do - default_confdir="$default_confdir_expand" - done - fi + local prefix="$prefix" + local TARGET="$PACKAGE_NAME" + local next + + # If $prefix is unset by the user, set it to autoconf's default value: + test "$prefix" = NONE && prefix=/usr/local + + # Prevent //. + test "$prefix" = / && prefix='' + + sysconfdir_expanded="$sysconfdir" + + # Expand $sysconfdir recursively (notably including $prefix): + while + eval "next=\"$sysconfdir_expanded\"" + test "$next" != "$sysconfdir_expanded" + do + sysconfdir_expanded="$next" + done }; fun @@ -73,10 +68,6 @@ test -z "$default_datadir" && default_datadir='$HOME/.ctct' AC_ARG_VAR([default_fallback_editor], ['editor to use if EDITOR is unset']) test -z "$default_fallback_editor" && default_fallback_editor=vi -AC_ARG_VAR([default_user_config_dir], ['user configuration directory']) -test -z "$default_user_config_dir" \ - && default_user_config_dir='$HOME/.config/'"$PACKAGE_NAME" - AC_ARG_VAR([default_input_program], ['the program that newly created or edited contact files get passed to on stdin']) test -z "$default_input_program" \ diff --git a/ctct.1.in b/ctct.1.in index d621778..5a9ba61 100644 --- a/ctct.1.in +++ b/ctct.1.in @@ -51,8 +51,7 @@ ctct \- a simple console contact manager .SH DESCRIPTION .P .B ctct -manages a set of simple contact entries, identified by -.IR name \. +manages a set of simple contact entries, identified by name\. If called with no special arguments, the contact entry identified by .I name @@ -126,13 +125,13 @@ See also .BR grep (1)\. .\" .TP -.B \-l, \-\-list\-all +.BR \-l ", " \-\-list\-all List all contacts alphabetically by name\. If a contact entry is composed of two dot separated parts, these parts' order is the one chosen at creation respectively renaming\. .\" .TP -.BI "\-e, \-\-edit " name +.BR \-e ", " \-\-edit " \fIname\fP" Edit and, if non-existent, create the entry identified by .IR name \. For the format of @@ -144,7 +143,7 @@ the actual name inside the contact entry, on whose format there are precisely no restrictions\. .\" .TP -.BI "\-d, \-\-delete " name \.\.\. +.BR \-d ", " \-\-delete " \fIname\fP \.\.\." Delete all specified contact entries\. .\" .TP @@ -159,7 +158,7 @@ to Show brief version and licensing information\. .\" .TP -.B \-h, \-\-help +.BR \-h ", " \-\-help Show a simple help text basically depicting the above options\. .\" .\" diff --git a/ctct.bash_completion.in b/ctct.bash_completion.in deleted file mode 100644 index 54aa137..0000000 --- a/ctct.bash_completion.in +++ /dev/null @@ -1,94 +0,0 @@ -#!/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 . -# - -_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 diff --git a/ctct.in b/ctct.in index ef7b588..a705e59 100644 --- a/ctct.in +++ b/ctct.in @@ -19,8 +19,7 @@ # ## DEFAULT SETTINGS: -system_config_dir="@default_confdir@" -user_config_dir="@default_user_config_dir@" +sysconfdir="@sysconfdir_expanded@" datadir="@default_datadir@" fallback_editor="@default_fallback_editor@" default_editor= # none - use $EDITOR @@ -31,10 +30,10 @@ confirm_deletion=@default_confirm_deletion@ confirm_default_yes=@default_confirm_default_yes@ ## 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" +test -f "$sysconfdir/ctct_config" \ + && source "$sysconfdir/ctct_config" +test -f "$user_config_file" \ + && source "$user_config_file" ## CONSTANTS: exec_name="${0##*/}" diff --git a/ctct_config.5.in b/ctct_config.5.in index a1f6184..4dcf063 100644 --- a/ctct_config.5.in +++ b/ctct_config.5.in @@ -27,7 +27,7 @@ ctct_config \- configuration of ctct The main configuration file for .BR ctct (1) is -.IR @default_confdir@/config\.sh \. +.IR @sysconfdir_expanded@/ctct_config \. The file is a .BR bash (1) script which is simply sourced by @@ -35,20 +35,19 @@ script which is simply sourced by It must not exit\. Any configuration is done by setting shell variables\. Configuration may be overriden in per-user configuration scripts, see -.BR user_config_dir \. +.BR user_config_file \. .P The following variables are recognized: .\" .TP -.B user_config_dir -The directory where the per user configuration file -.I config\.sh -is searched for\. +.B user_config_file +The per user configuration file. If set, this variable must contain the prefix .I $HOME or alternatively any other variable resolving to a directory below the respective home directory\. -.RI "The default value is " @default_user_config_dir@ \. +The default value is +.IR $HOME/.config/ctct_config" \. .\" .TP .B datadir @@ -176,11 +175,11 @@ file are stored by default\. .\" .SH FILES .TP -.I @default_confdir@/config\.sh +.I @sysconfdir_expanded@/ctct_config System wide configuration file\. .\" .TP -.I @default_user_config_dir@/config\.sh +.I $HOME/.config/config\.sh Default location of the user configuration file\. .\" .TP diff --git a/ctct_config.in b/ctct_config.in new file mode 100644 index 0000000..0231725 --- /dev/null +++ b/ctct_config.in @@ -0,0 +1,14 @@ +#!/bin/bash +# +# configuration file for ctct +# default values are commented out +# + +# datadir="@default_datadir@" +# fallback_editor="@default_fallback_editor@" +# default_editor= +# input_program="@default_input_program@" +# output_program="@default_output_program@" +# visual_program="@default_visual_program@" +# confirm_deletion=@default_confirm_deletion@ +# confirm_default_yes=@default_confirm_default_yes@ -- cgit v1.2.3