diff --git a/augeas.spec.in b/augeas.spec.in index 95f1d37ec..8f8c5a941 100644 --- a/augeas.spec.in +++ b/augeas.spec.in @@ -104,6 +104,7 @@ rm -rf $RPM_BUILD_ROOT %doc %{_mandir}/man1/* %{_datadir}/vim/vimfiles/syntax/augeas.vim %{_datadir}/vim/vimfiles/ftdetect/augeas.vim +%{bash_completions_dir}/*-completion.bash %files libs %defattr(-,root,root,-) @@ -126,6 +127,9 @@ rm -rf $RPM_BUILD_ROOT %{_libdir}/libfa.a %changelog +* Sun Nov 20 2022 George Hansper - 1.14.0 +- add bash completions + * Fri Mar 17 2017 David Lutterkort - 1.8.0-1 - add static subpackage diff --git a/configure.ac b/configure.ac index 5116455dc..fb7104dbf 100644 --- a/configure.ac +++ b/configure.ac @@ -140,3 +140,8 @@ AC_OUTPUT(Makefile \ doc/Makefile \ doc/naturaldocs/Makefile \ augeas.pc augeas.spec) + +# Bash completion ... +PKG_CHECK_VAR(bashcompdir, [bash-completion], [completionsdir], , + bashcompdir="${sysconfdir}/bash_completion.d") +AC_SUBST(bashcompdir) diff --git a/src/Makefile.am b/src/Makefile.am index d14314dda..44a06fe85 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -68,3 +68,8 @@ FORCE-datadir.h: Makefile $(top_srcdir)/build/ac-aux/move-if-change datadir.h1 datadir.h datadir.h: FORCE-datadir.h + +#bashcompdir = @bashcompdir@ +bashcompdir = $(datadir)/bash-completion/completions +dist_bashcomp_DATA = augtool-completion.bash augmatch-completion.bash augprint-completion.bash + diff --git a/src/augmatch-completion.bash b/src/augmatch-completion.bash new file mode 100644 index 000000000..140b4cda0 --- /dev/null +++ b/src/augmatch-completion.bash @@ -0,0 +1,33 @@ +# bash completion for augtool -*- shell-script -*- + +_augmatch() +{ + local cur prev words cword + _init_completion || return + + case $prev in + --help | -!(-*)[h]) + return + ;; + --lens | -!(-*)[l]) + local lenses + lenses="$(augtool --noload 'match /augeas/load/*/lens' | sed -e 's/.*@//')" + COMPREPLY=($(compgen -W "${lenses,,}" -- "${cur,,}")) + return + ;; + --root | --include | -!(-*)[rI]) + _filedir -d + return + ;; + esac + + if [[ "$cur" == -* ]]; then + local opts="$(_parse_help "$1")" + COMPREPLY=($(compgen -W '${opts:-$(_parse_help "$1")}' -- "$cur")) + else + _filedir + fi +} && + complete -F _augmatch augmatch + +# ex: filetype=sh diff --git a/src/augprint-completion.bash b/src/augprint-completion.bash new file mode 100644 index 000000000..fbde3920a --- /dev/null +++ b/src/augprint-completion.bash @@ -0,0 +1,33 @@ +# bash completion for augtool -*- shell-script -*- + +_augprint() +{ + local cur prev words cword + _init_completion || return + + case $prev in + --help | --version | -!(-*)[hV]) + return + ;; + --target | -!(-*)[t]) + _filedir + return + ;; + --lens | -!(-*)[l]) + local lenses + lenses="$(augtool --noload 'match /augeas/load/*/lens' | sed -e 's/.*@//')" + COMPREPLY=($(compgen -W "${lenses,,}" -- "${cur,,}")) + return + ;; + esac + + if [[ "$cur" == -* ]]; then + local opts="$(_parse_help "$1")" + COMPREPLY=($(compgen -W '${opts:-$(_parse_help "$1")}' -- "$cur")) + else + _filedir + fi +} && + complete -F _augprint augprint + +# ex: filetype=sh diff --git a/src/augtool-completion.bash b/src/augtool-completion.bash new file mode 100644 index 000000000..1e558bca3 --- /dev/null +++ b/src/augtool-completion.bash @@ -0,0 +1,29 @@ +# bash completion for augtool -*- shell-script -*- + +_augtool() +{ + local cur prev words cword + _init_completion || return + + case $prev in + --help | --version | -!(-*)[hV]) + return + ;; + --load-file | --file | -!(-*)[lf]) + _filedir + return + ;; + --root | --include | -!(-*)[rI]) + _filedir -d + return + ;; + esac + + if [[ "$cur" == -* ]]; then + local opts="$(_parse_help "$1")" + COMPREPLY=($(compgen -W '${opts:-$(_parse_help "$1")}' -- "$cur")) + fi +} && + complete -F _augtool augtool + +# ex: filetype=sh