julienmoumne / hotshell Goto Github PK
View Code? Open in Web Editor NEWInteractive single keystroke menus for the shell
Home Page: http://julienmoumne.github.io/hotshell
License: MIT License
Interactive single keystroke menus for the shell
Home Page: http://julienmoumne.github.io/hotshell
License: MIT License
What I would like is to underline the letter choose as key.
Because the user knows the world and letter used for the key shortcut, he will remember it easily.
Two ideas:
The following variables and methods are globally available when defining menus :
These references should be imported using regular "require" statements as in :
var item = require('hotshell').item
var exec = require('hotshell').exec
var _ = require('underscore')
item({desc: 'topten'}, function () {
var topTen =
'echo "history" | bash -i 2>/dev/null | sed "s/^ *[0-9]* *//" | ' +
'sort | uniq -c | sort -nr | head | sed "s/^ *[0-9]* *//"'
_(exec(topTen).split('\n')).each(function (el, ix) {
item({key: ix, cmd: el})
})
})
In the current implementation, with the following directory structure :
./subproject/docker-compose.yml
./subproject/script.sh
./hs.js
issuing a docker-compose command requires either :
-f
option as in docker-compose -f subproject/docker-compose.yml
cd subproject; docker-compose
if script.sh
uses relative paths, it needs to be called with the working directory set to ./subproject
. The command definition must then be cd subproject; ./script.sh
This adds boilerplate code and makes menus less readable.
Proposition : add a wd
(working directory) property to item definitions as in
item({desc: 'top-menu'}, function() {
item({key: 's', desc: 'subproject', wd: './subproject'}, function() {
// 'cd ./subproject' will be called for every command contained in this menu
item({key: 'r', desc: 'docker-compose run', cmd: 'docker-compose run'})
item({key: 'e', desc: 'execute script', cmd: './script.sh'})
})
})
This ticket fixes two issues as documented in blog post Building Trees using a JavaScript DSL section Hacking a way through the forest.
hs --generate-md > COMMANDS.md
See examples > "generated markdowns"
when no hs.js
file is present in the current working directory, hotshell will no longer load the menu defined in ~/.hs/hs.js
if present
recommended workaround is to use hs -f ~/.hs/hs.js
or create an alias :
# user hotshell
alias hs-home="hs -f ~/.hs/hs.js"
Taking the network example as a case study.
item({desc: 'network'}, function () {
item({key: 'e', desc: 'eth0'}, interface('eth0'))
item({key: 'w', desc: 'wlan0'}, function () {
interface('wlan0')()
// specific commands can be added when needed
item({key: 'l', desc: 'list access points', cmd: 'iwlist scan'})
})
function interface(id) {
var ifconfig = 'ifconfig ' + id
var sudo = 'sudo ' + ifconfig
return function() {
item({key: 'i', desc: 'info', cmd: ifconfig})
item({key: 'u', desc: 'up', cmd: sudo + ' up'})
item({key: 'd', desc: 'down', cmd: sudo + ' down'})
}
}
})
Could become
menu('network')
.menu('eth0').key('e')
.interfaceManager('eth0')
.menu('wlan0').key('w')
.interfaceManager('wlan0')
.cmd('iwlist scan').key('l').desc('list access points')
registry.interfaceManager = function(id) {
var ifconfig = 'ifconfig ' + id
var sudo = 'sudo ' + ifconfig
return function(menu) {
menu.cmd(ifconfig).key('i').desc('info')
menu.cmd(sudo + ' up').key('u').desc('up')
menu.cmd(sudo + ' down').key('d').desc('down')
}
}
Attributes that can be arbitrary long such as "cmd" should probably appear at the end. Better yet, attributes could be defined in whatever order.
This new DSL could incubate within a NPM module such as hotshell-docker :
var fluentDsl = require('./lib/fluent-dsl.hs.js')
var menu = fluentDsl.menu
var registry = fluentDsl.registry
menu('network')
.menu('eth0').key('e')
[...]
hs -f http://somesite/hs.js
will no longer work
recommended workaround (taken from askubuntu.com):
H='somesite/hs.js'; T=`mktemp`; wget $H -qO $T && hs -f $T; rm $T
--chdir
changes the current working directory to the directory of the loaded definition file
This option :
cd
as in (cd PATH_TO_MENU; hs)
npm modules offer a convenient way to factor and distribute Hotshell patterns, see hotshell-util as an example.
Downloading npm modules is straightforward using a Node environment.
However, Hotshell does not require Node and should remain, at runtime, dependency free.
This ticket is about finding a way to make Hotshell interpret a package.json
file and download the required dependencies.
Lets make them configurable per user by having a JavaScript configuration file in ~\.hsrc.js
.
hs -f ~/projects/web
will no longer work
hs -f ~/projects/web/hs.js
should be used instead
Following your recommandations after my pull request, I wanted to open a debate about display options.
It'd be nice to have a way to configure the display (per project like in my PR, or per user, or something else).
Maybe that a user configuration would be better, but what if a project owner wants to add some specific features to its hotshell menu ?
What do you think about it ?
Use motto to provide a nodejs like module environment so menu definitions can be decomposed into multiple modules/files.
Sometimes I'd like to edit a command in my menu before running it.
Some cases where it could happen.
ssh user@hostname watch -n5 nvidia-smi
-> ssh user@hostname watch -n1 nvidia-smi
Proposal
Add a combination key (Alt+) to show command in rather that running it.
Hotshell currently reads only one byte from the user input.
This limits the ability to specify unicode
item({key: 'Ô'})
This idea is directly taken from Python.
A definition file written as shown bellow will be both usable as a library and as a standalone menu :
// ./menu1.hs.js
var item = require('hotshell').item
module.exports = function () {
item({key: 'r', desc: 'restart apache', cmd: 'sudo service apache2 restart'})
item({key: 's', desc: 'synchronize time', cmd: 'sudo /usr/sbin/ntpdate pool.ntp.org'})
}
// https://nodejs.org/api/modules.html#modules_accessing_the_main_module
if (require.main === module)
item({desc: 'menu 1'}, module.exports)
hs -f ./menu1.hs.js
// ./menu2.hs.js
var item = require('hotshell').item
var menu1 = require('./menu1.hs.js')
item({desc: 'menu 2'}, menu1)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.