Skip to content

Commit

Permalink
add bash completion for jsequence.
Browse files Browse the repository at this point in the history
  • Loading branch information
thehunmonkgroup committed Jan 20, 2016
1 parent 73e1bdf commit 3055163
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
10 changes: 7 additions & 3 deletions doc/04-Scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>keys</code>, it will output the template for the rather complex <code>keys</code> 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:

* <code>keys</code>: outputs the template for the rather complex <code>keys</code> parameter.
* <code>actions</code>: outputs a list of all known actions.

#### Installation

Expand All @@ -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 <code>scripts/jsequence.bash\_completion</code> in your bash completion directory to enable completion for the command.
9 changes: 6 additions & 3 deletions scripts/jsequence
Original file line number Diff line number Diff line change
Expand Up @@ -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

--[[
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions scripts/jsequence.bash_completion
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3055163

Please sign in to comment.