From 970811a1c58d22fad37d8cbe2233b8344f358e78 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Wed, 4 Apr 2018 00:07:45 -0700 Subject: Conditionally install bash completion Signed-off-by: Alexey Neyman diff --git a/Makefile.am b/Makefile.am index a331832..768a3c5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,8 +6,13 @@ include verbatim-data.mk SUBDIRS = kconfig bin_SCRIPTS = ct-ng -CLEANFILES = $(bin_SCRIPTS) -EXTRA_DIST = ct-ng.in bootstrap docs/ct-ng.1.in +CLEANFILES = ct-ng ct-ng.comp docs/ct-ng.1 +EXTRA_DIST = bootstrap ct-ng.in ct-ng.comp.in docs/ct-ng.1.in maintainer + +if INSTALL_BASH_COMPLETION +compdir = $(sysconfdir)/@BASH_COMPLETION_DIR@ +comp_SCRIPTS = ct-ng.comp +endif man1_MANS = docs/ct-ng.1 @@ -45,8 +50,11 @@ do_subst = ( @SED@ \ ct-ng: ct-ng.in Makefile $(AM_V_GEN)$(do_subst) < $< >$@-t && chmod a-w,a+x $@-t && mv -f $@-t $@ -docs/ct-ng.1: docs/ct-ng.1.in +docs/ct-ng.1: docs/ct-ng.1.in Makefile $(AM_V_GEN)$(MKDIR_P) docs && $(do_subst) < $< >$@-t && mv -f $@-t $@ +ct-ng.comp: ct-ng.comp.in Makefile + $(AM_V_GEN)$(do_subst) < $< >$@-t && mv -f $@-t $@ + dist-hook: maintainer/download-docs.sh $< $(top_distdir) $(USER_MANUAL_FILES) diff --git a/configure.ac b/configure.ac index c7b6f5a..920e42d 100644 --- a/configure.ac +++ b/configure.ac @@ -33,6 +33,16 @@ AC_ARG_ENABLE( [run ct-ng from the current directory; 'make install' unsupported])]) AC_SUBST([enable_local], [${enable_local:-no}]) +AC_ARG_WITH([bash-completion-dir], + [AS_HELP_STRING( + [--with-bash-completion], + [install bash(1) command completion for ct-ng into specified directory, + relative to sysconfdir])], + [], + [with_bash_completion_dir=bash_completion.d]) +AM_CONDITIONAL([INSTALL_BASH_COMPLETION], [test "${with_bash_completion_dir}" != "no" ]) +AC_SUBST([BASH_COMPLETION_DIR], [${with_bash_completion_dir}]) + # FIXME: I don't know why we have this. Will remove after the 1.24 release. AC_ARG_ENABLE( [shared], diff --git a/ct-ng.comp b/ct-ng.comp deleted file mode 100644 index e89e686..0000000 --- a/ct-ng.comp +++ /dev/null @@ -1,36 +0,0 @@ -# To be sourced - -_ct_ng () { - local cur prev samples show_samples actions steps start_steps stop_steps ct_ng_opts vars - COMPREPLY=() - cur=$(_get_cword) - prev=${COMP_WORDS[COMP_CWORD-1]} - - samples=$( "${COMP_WORDS[0]}" list-samples-short 2>/dev/null ) - show_samples=$(echo "${samples}" |sed -r -e 's/(^| )/\1show-/g;') - build_samples=$(echo "${samples}" |sed -r -e 's/(^| )/\1build-/g;') - check_samples=$(echo "${samples}" |sed -r -e 's/(^| )/\1check-/g;') - - steps=$(${COMP_WORDS[0]} list-steps 2>/dev/null |awk '$1 == "-" { print $2; }') - start_steps=$(echo "${steps}" |sed -r -e 's/($| )/\1+/;') - stop_steps=$(echo "${steps}" |sed -r -e 's/(^| )/+\1/;') - - actions='help menuconfig nconfig oldconfig saveconfig extractconfig - defconfig savedefconfig - build build. build-all build-all. - wiki-samples list-samples list-samples-short check-samples - list-steps - show-tuple show-all show-config - clean distclean updatetools - version' - - vars="RESTART= STOP= PREFIX= V= DEFCONFIG=" - - ct_ng_opts="${samples} ${show_samples} ${build_samples} ${check_samples} - ${steps} ${start_steps} ${stop_steps} - ${actions} ${vars}" - - COMPREPLY=($(compgen -W "${ct_ng_opts}" -- "${cur}")) - return 0 -} -complete -F _ct_ng ct-ng diff --git a/ct-ng.comp.in b/ct-ng.comp.in new file mode 100644 index 0000000..f38c881 --- /dev/null +++ b/ct-ng.comp.in @@ -0,0 +1,36 @@ +# To be sourced + +_ct_ng () { + local cur prev samples show_samples actions steps start_steps stop_steps ct_ng_opts vars + COMPREPLY=() + cur=$(_get_cword) + prev=${COMP_WORDS[COMP_CWORD-1]} + + samples=$( "${COMP_WORDS[0]}" list-samples-short 2>/dev/null ) + show_samples=$(echo "${samples}" |sed -r -e 's/(^| )/\1show-/g;') + build_samples=$(echo "${samples}" |sed -r -e 's/(^| )/\1build-/g;') + check_samples=$(echo "${samples}" |sed -r -e 's/(^| )/\1check-/g;') + + steps=$(${COMP_WORDS[0]} list-steps 2>/dev/null |awk '$1 == "-" { print $2; }') + start_steps=$(echo "${steps}" |sed -r -e 's/($| )/\1+/;') + stop_steps=$(echo "${steps}" |sed -r -e 's/(^| )/+\1/;') + + actions='help menuconfig nconfig oldconfig saveconfig extractconfig + defconfig savedefconfig + build build-all + wiki-samples list-samples list-samples-short check-samples + list-steps + show-tuple show-all show-config + clean distclean updatetools + version' + + vars="RESTART= STOP= PREFIX= V= DEFCONFIG=" + + ct_ng_opts="${samples} ${show_samples} ${build_samples} ${check_samples} + ${steps} ${start_steps} ${stop_steps} + ${actions} ${vars}" + + COMPREPLY=($(compgen -W "${ct_ng_opts}" -- "${cur}")) + return 0 +} +complete -F _ct_ng @progname@ -- cgit v0.10.2-6-g49f6