From f1e6902155f4aaef00c78072d3a0f8f186819965 Mon Sep 17 00:00:00 2001 From: Emanuele Petriglia Date: Sun, 24 Nov 2019 15:15:19 +0100 Subject: [PATCH] Add Bash completion for xfconf-query Signed-off-by: Emanuele Petriglia --- Makefile.am | 4 +++ completions/Makefile.am | 4 +++ completions/xfconf-query | 58 ++++++++++++++++++++++++++++++++++++++++ configure.ac.in | 19 +++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 completions/Makefile.am create mode 100644 completions/xfconf-query diff --git a/Makefile.am b/Makefile.am index f0e0405..4d63085 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,6 +10,10 @@ SUBDIRS = \ docs \ tests +if ENABLE_BASH_COMPLETION +SUBDIRS += completions +endif + if XFCONF_ENABLE_GSETTINGS_BACKEND SUBDIRS += gsettings-backend endif diff --git a/completions/Makefile.am b/completions/Makefile.am new file mode 100644 index 0000000..e2014ba --- /dev/null +++ b/completions/Makefile.am @@ -0,0 +1,4 @@ +if ENABLE_BASH_COMPLETION +bashcompletiondir = $(BASH_COMPLETION_DIR) +dist_bashcompletion_DATA = xfconf-query +endif diff --git a/completions/xfconf-query b/completions/xfconf-query new file mode 100644 index 0000000..781a889 --- /dev/null +++ b/completions/xfconf-query @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +# +# Bash completion for xfconf-query. +# +# Copyright (C) 2019 Emanuele Petriglia +# +# +# 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 + +_xfconf-query() { + local current options words long_options + COMPREPLY=() + current="${COMP_WORDS[$COMP_CWORD]}" + previous="${COMP_WORDS[$COMP_CWORD - 1]}" + short_options="-h -V -c -p -s -l -v -n -t -r -R -a -T -m" + + long_options="--help --version --channel --property --set --list --verbose" + long_options+=" --create --type --reset --recursive --force-array --toggle" + long_options+=" --monitor" + + options="$short_options $long_options" + + if [[ "$current" == --* ]]; then + words="$long_options" + elif [[ "$current" == -* ]]; then + words="$options" + else + case "$previous" in + # Delete first line and the initial two spaces (see 'xfconf-query -l'). + -c|--channel) words="$(xfconf-query -l | sed -e '1d' -e 's/^ //')" ;; + -p|--property) + # Get given channel, if exists. + channel="$(echo "$COMP_LINE" | grep -oPe '(-c|--channel) \K([a-z]+)')" + + if [[ "$channel" ]]; then + words="$(xfconf-query -c "$channel" -l)" + fi + ;; + esac + fi + + mapfile -t COMPREPLY < <(compgen -W "$words" -- "$current") + return 0 +} + +complete -F _xfconf-query xfconf-query diff --git a/configure.ac.in b/configure.ac.in index ef00e16..080e523 100644 --- a/configure.ac.in +++ b/configure.ac.in @@ -97,6 +97,24 @@ XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.10.0]) dnl check for perl bindings for --disable-perl-bindings and make-exo-alias.pl AC_PATH_PROGS([PERL], [perl5.8 perl5.6 perl5 perl]) +dnl Bash completion for xfconf-query. +AC_ARG_WITH([bash-completion-dir], + AS_HELP_STRING([--with-bash-completion-dir[=PATH]], + [Install the bash auto-completion script in this directory. @<:@default=yes@:>@]), + [], + [with_bash_completion_dir=yes]) + +if test "x$with_bash_completion_dir" = "xyes"; then + PKG_CHECK_MODULES([BASH_COMPLETION], [bash-completion >= 2.0], + [BASH_COMPLETION_DIR="`pkg-config --variable=completionsdir bash-completion`"], + [BASH_COMPLETION_DIR="$datadir/bash-completion/completions"]) +else + BASH_COMPLETION_DIR="$with_bash_completion_dir" +fi + +AC_SUBST([BASH_COMPLETION_DIR]) +AM_CONDITIONAL([ENABLE_BASH_COMPLETION],[test "x$with_bash_completion_dir" != "xno"]) + dnl see if we can build the perl bindings AC_ARG_ENABLE([perl-bindings], [AC_HELP_STRING([--disable-perl-bindings], @@ -266,6 +284,7 @@ xfconf-perl/xs/Makefile xfconf-query/Makefile xfconfd/Makefile gsettings-backend/Makefile +completions/Makefile ]) dnl *************************** -- 2.21.0