summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-10-13 15:55:52 +0000
committerDavid Robillard <d@drobilla.net>2009-10-13 15:55:52 +0000
commit1d558c962f2ee969c981b50866f0ef9220f25515 (patch)
tree2ce440487c0edacdf8b35df7da77ef2a5e3635c1
parentff698ce3bbf8dee1c7a45669d7ddc72dee4b55f6 (diff)
downloadlilv-1d558c962f2ee969c981b50866f0ef9220f25515.tar.gz
lilv-1d558c962f2ee969c981b50866f0ef9220f25515.tar.bz2
lilv-1d558c962f2ee969c981b50866f0ef9220f25515.zip
Bash completion support for SLV2 utilities from Lars Luthman.
git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2191 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--utils/slv2.bash_completion59
-rw-r--r--wscript8
2 files changed, 67 insertions, 0 deletions
diff --git a/utils/slv2.bash_completion b/utils/slv2.bash_completion
new file mode 100644
index 0000000..921087a
--- /dev/null
+++ b/utils/slv2.bash_completion
@@ -0,0 +1,59 @@
+# Bash auto-completion script written for lv2_inspect, lv2_jack_host
+# and lv2_simple_jack_host. Could be adapted to any other program
+# that takes an LV2 plugin URI as parameter.
+
+# Written by Lars Luthman <lars.luthman@gmail.com> on 2009-10-12.
+# No copyright claimed for this script. Do what you want with it.
+
+# For some reason Bash splits the command line not only at whitespace
+# but also at ':' signs before putting the parts into COMP_WORDS.
+# Since ':' is used in all URIs, which are what we want to complete,
+# we have to put the URI back together before we can complete it
+# and then cut off the parts we prepended from the completions.
+# It probably breaks in some special cases but for most common uses
+# it should work fine.
+
+function _lv2_inspect() {
+ local uri cur opts w wn raw_reply len type
+ opts=`lv2_list | xargs -n1 echo -n " "`
+
+ # This is the last "word", as split by Bash.
+ cur="${COMP_WORDS[COMP_CWORD]}"
+ w="$cur"
+
+ # Add the previous word while it or this one is a word break character
+ for i in `seq $(( $COMP_CWORD - 1 )) -1 1`; do
+ wn="${COMP_WORDS[i]}"
+ if expr "$COMP_WORDBREAKS" : ".*$wn" > /dev/null; then
+ if expr "$COMP_WORDBREAKS" : ".*$w" > /dev/null; then
+ break
+ fi
+ fi
+ w="$wn"
+ uri="$w$uri"
+ done
+
+ # Check the length of the words we prepend
+ len=${#uri}
+ uri="$uri$cur"
+ raw_reply="$(compgen -W "${opts}" -- ${uri})"
+
+ # If we are listing alternatives, just print the full URIs.
+ type=`echo $COMP_TYPE | awk '{ printf "%c", $1 }'`
+ if expr "?!@%" : ".*$type" > /dev/null; then
+ COMPREPLY=( $raw_reply )
+ return 0
+ fi
+
+ # Otherwise, strip the prepended words from all completion suggestions.
+ COMPREPLY=()
+ for i in $raw_reply; do
+ COMPREPLY=( ${COMPREPLY[@]} ${i:len} )
+ done
+}
+
+complete -F _lv2_inspect lv2_inspect
+
+# And the same for lv2_jack_host and lv2_simple_jack_host.
+complete -F _lv2_inspect lv2_jack_host
+complete -F _lv2_inspect lv2_simple_jack_host
diff --git a/wscript b/wscript
index 4e45735..1c9eb71 100644
--- a/wscript
+++ b/wscript
@@ -46,6 +46,8 @@ def set_options(opt):
help="Build support for dynamic manifest extension [false]")
opt.add_option('--test', action='store_true', default=False, dest='build_tests',
help="Build unit tests")
+ opt.add_option('--bash-completion', action='store_true', default=False, dest='bash_completion',
+ help="Install bash completion script in /etc/bash_completion.d")
def configure(conf):
autowaf.configure(conf)
@@ -61,6 +63,7 @@ def configure(conf):
conf.env['USE_JACK'] = conf.env['HAVE_JACK'] and not Options.options.no_jack
conf.env['BUILD_TESTS'] = Options.options.build_tests
+ conf.env['BASH_COMPLETION'] = Options.options.bash_completion
autowaf.print_summary(conf)
autowaf.display_header('SLV2 Configuration')
@@ -149,6 +152,11 @@ def build(bld):
bld.install_files('${MANDIR}/man3', blddir + '/default/doc/man/man3/*')
bld.install_files('${MANDIR}/man1', 'doc/*.1')
+ # Bash completion
+ if bld.env['BASH_COMPLETION']:
+ bld.install_as(
+ '/etc/bash_completion.d/slv2', 'utils/slv2.bash_completion')
+
def shutdown():
autowaf.shutdown()