Git Product home page Git Product logo

hotshell's People

Contributors

julienmoumne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

hotshell's Issues

Add possibility to format item description

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:

  • accept unicode in text
  • provide helpers that will convert text depending on OS

[breaking change] remove global variables and functions (item(), exec(), _, items, current)

The following variables and methods are globally available when defining menus :

  • item()
  • exec()
  • _
  • items
  • current

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})
    })
})

Ability to specify the current working directory per item

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 :

  • using the -f option as in docker-compose -f subproject/docker-compose.yml
  • changing directory as in 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'}) 
  })
})

[breaking change] do not autoload ~/.hs/hs.js

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"

Study the possibility to provide a more concise DSL

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')

[...]

[breaking change] delete '--chdir' option

--chdir changes the current working directory to the directory of the loaded definition file

This option :

  • introduces complexity in the code,
  • will be mostly superseded in #15
  • can be replaced by doing a cd as in (cd PATH_TO_MENU; hs)

As a user I would like to import npm modules

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.

One idea would be to integrate the npm lib using Otto.

Horizontal menu breadcrumb

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 ?

Modular menu definitions

Use motto to provide a nodejs like module environment so menu definitions can be decomposed into multiple modules/files.

Temporary edit a command

Sometimes I'd like to edit a command in my menu before running it.

Some cases where it could happen.

  • Replace a hostname by an IP address (because hostname cannot be resolved)
  • Edit a parameter in the predefined command (ssh user@hostname watch -n5 nvidia-smi -> ssh user@hostname watch -n1 nvidia-smi
  • etc.

Proposal
Add a combination key (Alt+) to show command in rather that running it.

Support UTF-8 key codes

Hotshell currently reads only one byte from the user input.

This limits the ability to specify unicode

  • keybindings such as Escape, Delete, ..
  • item keys, as in item({key: 'Ô'})

Allow a definition file to be used both as a library and as a standalone menu

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)
  • as a standalone menu
hs -f ./menu1.hs.js
  • as a reusable menu
// ./menu2.hs.js
var item = require('hotshell').item
var menu1 = require('./menu1.hs.js')

item({desc: 'menu 2'}, menu1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.