From 30551635647535272f66b8a76b25163f150ca824 Mon Sep 17 00:00:00 2001 From: Chad Phillips Date: Wed, 20 Jan 2016 16:26:58 -0700 Subject: [PATCH] add bash completion for jsequence. --- doc/04-Scripts.md | 10 +++++++--- scripts/jsequence | 9 ++++++--- scripts/jsequence.bash_completion | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 scripts/jsequence.bash_completion diff --git a/doc/04-Scripts.md b/doc/04-Scripts.md index 3b8d8fd..d296968 100644 --- a/doc/04-Scripts.md +++ b/doc/04-Scripts.md @@ -10,7 +10,12 @@ Easily generate properly formatted sequence templates or action fragments with o jsequence removes the headache of getting initial sequence templates laid out. Probably the most frustrating part of building sequences is dealing with syntax errors due to improper formatting, and this script eliminates many of those issues. -When called with no arguments, it brings up a dialog asking a few simple questions which it uses to generate the template. Alternatively, it can be called with a variable number of arguments, each the name of an action, and it will output just the structure for the passed actions, which can then be copied or piped into an existing sequence. Or, when called with just the argument keys, it will output the template for the rather complex keys parameter. +When called with no arguments, it brings up a dialog asking a few simple questions which it uses to generate the template. Alternatively, it can be called with a variable number of arguments, each the name of an action, and it will output just the structure for the passed actions, which can then be copied or piped into an existing sequence. + +You can also call it with the following special arguments: + + * keys: outputs the template for the rather complex keys parameter. + * actions: outputs a list of all known actions. #### Installation @@ -23,6 +28,5 @@ The script is installed into your path if the [Luarocks](https://luarocks.org) p ###### Manually 1. Follow the instructions in the [main Jester installation instructions](https://github.com/thehunmonkgroup/jester/blob/master/INSTALL.md) for properly setting your LUA_PATH environment variable. - 2. Move (or better yet, symlink) this script somewhere into your $PATH (~/bin, /usr/local/bin, etc.) - + 3. If you use bash completion, you can place scripts/jsequence.bash\_completion in your bash completion directory to enable completion for the command. diff --git a/scripts/jsequence b/scripts/jsequence index 285f0c0..ea01380 100755 --- a/scripts/jsequence +++ b/scripts/jsequence @@ -15,9 +15,10 @@ require "jester.support.table" --[[ Grab a comma separated list of all available actions. ]] -function actions_list() +function actions_list(sep) + sep = sep or ", " local ordered_actions = table.orderkeys(action_map) - return table.concat(ordered_actions, ", ") + return table.concat(ordered_actions, sep) end --[[ @@ -162,7 +163,9 @@ local skipped_actions = {} -- Arguments were passed, use them to build actions instead of full output. if #arguments > 0 then - if arguments[1] == "keys" then + if arguments[1] == "actions" then + preview = actions_list(" ") + elseif arguments[1] == "keys" then preview = " keys = " .. keys_table() .. ",\n" else output, skipped_actions = build_actions_output(arguments) diff --git a/scripts/jsequence.bash_completion b/scripts/jsequence.bash_completion new file mode 100644 index 0000000..83c90b9 --- /dev/null +++ b/scripts/jsequence.bash_completion @@ -0,0 +1,14 @@ +#!/bin/bash + +_jsequence() +{ + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + if [ $COMP_CWORD > 0 ]; then + local actions=$(jsequence actions) + COMPREPLY=($(compgen -W "${actions}" -- ${cur})) + fi + return 0 +} +complete -F _jsequence jsequence +