Skip to content

Commit

Permalink
Add bash-completion for augtool, augmatch, augprint (#783)
Browse files Browse the repository at this point in the history
Co-authored-by: George Hansper <[email protected]>
  • Loading branch information
georgehansper and George Hansper authored Dec 3, 2022
1 parent 187de8b commit 564c5bf
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 0 deletions.
4 changes: 4 additions & 0 deletions augeas.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -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,-)
Expand All @@ -126,6 +127,9 @@ rm -rf $RPM_BUILD_ROOT
%{_libdir}/libfa.a

%changelog
* Sun Nov 20 2022 George Hansper <[email protected]> - 1.14.0
- add bash completions

* Fri Mar 17 2017 David Lutterkort <[email protected]> - 1.8.0-1
- add static subpackage

Expand Down
5 changes: 5 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 5 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,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

33 changes: 33 additions & 0 deletions src/augmatch-completion.bash
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions src/augprint-completion.bash
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions src/augtool-completion.bash
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 564c5bf

Please sign in to comment.