├── LICENSE
├── README.md
├── fixture
└── package.json
├── functions
├── __touchrunner.fish
├── __touchrunner_keydown.fish
├── __touchrunner_list_tasks.fish
└── __touchrunner_osc_command.fish
├── init.fish
├── key_bindings.fish
└── touchrunner.gif
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2017 Derek W. Stavis
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | #### touchrunner
4 | > Run tasks from the touchbar
5 |
6 | [](/LICENSE)
7 | [](https://fishshell.com)
8 | [](https://www.github.com/oh-my-fish/oh-my-fish)
9 |
10 |
11 |
12 |
13 | ## Installing
14 |
15 | ```fish
16 | $ omf install touchrunner
17 | ```
18 |
19 | ## What will you get
20 |
21 | 
22 |
23 | ## Requirements
24 |
25 | 1. Have **Oh My Fish** installed. For more information, check [here](https://github.com/oh-my-fish/oh-my-fish#installation).
26 | 1. Be using **iTerm2**, for Touch Bar support.
27 |
28 | ## Usage
29 |
30 | 1. Edit the Touch Bar (View -> Customize Touch Bar) to have only "Function keys" block.
31 | 1. Enter a directory with a `package.json` and the tasks will appear at the touch bar.
32 | 1. Exitting the directory makes the Touch Bar be restored to function keys.
33 |
34 | ## Configuration
35 |
36 | By default touchrunner will use `npm run`. If you want to switch the task
37 | runner, you can override via `touchrunner_command` global variable, eg.:
38 |
39 | ```fish
40 | set -g touchrunner_command yarn
41 | ```
42 |
43 | # License
44 |
45 | [MIT][mit] © [Derek Stavis][author]
46 |
47 |
48 | [mit]: https://opensource.org/licenses/MIT
49 | [author]: https://github.com/derekstavis
50 | [omf-link]: https://www.github.com/oh-my-fish/oh-my-fish
51 |
52 | [license-badge]: https://img.shields.io/badge/license-MIT-007EC7.svg?style=flat-square
53 |
--------------------------------------------------------------------------------
/fixture/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "fixture",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "foobar": "echo foobar",
8 | "quxcux": "echo quxcux"
9 | },
10 | "keywords": [],
11 | "author": "",
12 | "license": "ISC"
13 | }
14 |
--------------------------------------------------------------------------------
/functions/__touchrunner.fish:
--------------------------------------------------------------------------------
1 | function __touchrunner
2 | test -f "package.json"
3 | or return
4 |
5 | set -l tasks (__touchrunner_list_tasks)
6 | set key 1
7 |
8 | if test (count $tasks) = 0
9 | if test "$__touchrunner_wd_has_tasks" = 1
10 | __touchrunner_osc_command 'PopKeyLabels=npm-scripts'
11 | end
12 |
13 | set __touchrunner_wd_has_tasks 0
14 | end
15 |
16 | if test "$__touchrunner_wd_has_tasks" = 0
17 | __touchrunner_osc_command 'PopKeyLabels=npm-scripts'
18 | __touchrunner_osc_command 'PushKeyLabels=npm-scripts'
19 | end
20 |
21 | set __touchrunner_wd_has_tasks 1
22 |
23 | for task in $tasks
24 | __touchrunner_osc_command (printf 'SetKeyLabel=%s=%s' F$key $task)
25 |
26 | set key (math $key + 1)
27 |
28 | if test $key -gt 20
29 | break
30 | end
31 | end
32 | end
33 |
--------------------------------------------------------------------------------
/functions/__touchrunner_keydown.fish:
--------------------------------------------------------------------------------
1 | function __touchrunner_keydown -a index
2 | set -l tasks (__touchrunner_list_tasks)
3 | set -l cmd "npm run"
4 |
5 | if test -n "$touchrunner_command"
6 | set cmd "$touchrunner_command"
7 | end
8 |
9 | commandline -r "$cmd $tasks[$index]"
10 | commandline -f execute
11 | end
12 |
--------------------------------------------------------------------------------
/functions/__touchrunner_list_tasks.fish:
--------------------------------------------------------------------------------
1 | set -g __touchrunner_script 'Object.keys(require("./package.json").scripts).forEach(n => console.log(n))'
2 |
3 | function __touchrunner_list_tasks
4 | set -l stat (stat -f "%m" "package.json")
5 |
6 | if test "$stat" != "$__touchrunner_mtime"
7 | set -g __touchrunner_mtime $stat
8 | set -g __touchrunner_packages (node -e "$__touchrunner_script" 2>/dev/null)
9 | end
10 |
11 | printf "%s\n" $__touchrunner_packages
12 | end
13 |
--------------------------------------------------------------------------------
/functions/__touchrunner_osc_command.fish:
--------------------------------------------------------------------------------
1 | function __touchrunner_osc_command -a cmd
2 | switch "$TERM"
3 | case 'screen*'
4 | printf '\033Ptmux;\033\033]'
5 | case '*'
6 | printf '\033]'
7 | end
8 |
9 | printf '1337;%s' "$cmd"
10 |
11 | switch "$TERM"
12 | case 'screen*'
13 | printf '\a\033\\"'
14 | case '*'
15 | printf '\a'
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/init.fish:
--------------------------------------------------------------------------------
1 | set -gx __touchrunner_wd_has_tasks 0
2 |
3 | function __touchrunner_pwd -v PWD
4 | __touchrunner
5 | end
6 |
7 | __touchrunner
8 |
--------------------------------------------------------------------------------
/key_bindings.fish:
--------------------------------------------------------------------------------
1 | for n in (seq 20)
2 | if test "$__fish_active_key_bindings" = fish_vi_key_bindings
3 | bind -M insert -k f$n "__touchrunner_keydown $n"
4 | else
5 | bind -k f$n "__touchrunner_keydown $n"
6 | end
7 | end
8 |
--------------------------------------------------------------------------------
/touchrunner.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/derekstavis/touchrunner/f4bad3755ac6115486d314bba9a1f9efb1c9935e/touchrunner.gif
--------------------------------------------------------------------------------