Skip to content

Commit

Permalink
improve bash-completion
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
  • Loading branch information
ignatenkobrain committed Jun 13, 2014
1 parent f32a4e4 commit f7236af
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
22 changes: 22 additions & 0 deletions configure.ac
Expand Up @@ -95,6 +95,18 @@ AX_CHECK_COMPILE_FLAG([-fPIE],
AC_SUBST(PIE_CFLAGS)
AC_SUBST(PIE_LDFLAGS)

# bash-completion
AC_ARG_WITH([bashcompletiondir],
AS_HELP_STRING([--with-bashcompletiondir=DIR], [Bash completions directory]),
[],
[AS_IF([$($PKG_CONFIG --exists bash-completion)], [
with_bashcompletiondir=$($PKG_CONFIG --variable=completionsdir bash-completion)
] , [
with_bashcompletiondir=${datadir}/bash-completion/completions
])])
AC_SUBST([bashcompletiondir], [$with_bashcompletiondir])


# use gperf for faster string -> enum matching
AC_PATH_PROG(GPERF, [gperf], [no])
if test x$GPERF != xno ; then
Expand All @@ -120,3 +132,13 @@ docs/api/Makefile
docs/api/version.xml
])
AC_OUTPUT
AC_MSG_RESULT([
$PACKAGE_NAME $VERSION
prefix: ${prefix}
sysconf dir: ${sysconfdir}
datarootdir: ${datarootdir}
includedir: ${includedir}
lib dir: ${libdir}
Bash completion dir: ${with_bashcompletiondir}
])
3 changes: 3 additions & 0 deletions data/Makefile.am
@@ -1,4 +1,7 @@
SUBDIRS = \
tests

bashcompletiondir=@bashcompletiondir@
dist_bashcompletion_DATA = appstream-util

-include $(top_srcdir)/git.mk
72 changes: 72 additions & 0 deletions data/appstream-util
@@ -0,0 +1,72 @@
# appstream-util completion -*- shell-script -*-
#
# This file is part of libappstream-glib.
#
# Copyright 2014 Igor Gnatenko
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License,
# or (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

_appstream-util()
{
local cur prev words cword
_init_completion -s || return

local commandix command
for (( commandix=1; commandix < cword; commandix++ )); do
if [[ ${words[commandix]} != -* ]]; then
command=${words[commandix]}
break
fi
done

case $prev in
-h|--help|--version)
return
;;
*)
;;
esac

$split && return

if [[ $command ]]; then

case $command in
validate|validate-relax|validate-strict)
ext='@(appdata|metainfo).xml?(.in)'
;;
install|uninstall)
ext='@(appdata|metainfo).xml'
;;
dump)
ext='@(desktop|@(appdata|metainfo).xml)'
;;
*)
;;
esac
[[ -n $ext ]] && _filedir $ext
return
fi

if [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
elif [[ ! $command ]]; then
COMPREPLY=( $( compgen -W '$( "$1" list-commands 2>/dev/null )' -- "$cur" ) )
fi
} &&
complete -F _appstream-util appstream-util

# ex: ts=4 sw=4 et filetype=sh

0 comments on commit f7236af

Please sign in to comment.