Des menus dans votre terminal - retour accueil
git clone git://bebou.netlib.re/zenu
Log | Files | Refs | README |
commit 713d5af704d0abd3492b631b2941cc0614ee42ab parent ccd07276ff78124e403d764b2f24d591c42d5d05 Auterice: Arthur Pons <arthur.pons@unistra.fr> Date: Tue, 28 May 2024 15:11:50 +0200 readme de Marc = didi, Et aussi lister les dépendances Diffstat:
A | README | | | 158 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
D | README.nope | | | 156 | ------------------------------------------------------------------------------- |
D | readme.fr | | | 6 | ------ |
3 files changed, 158 insertions(+), 162 deletions(-)
diff --git a/README b/README @@ -0,0 +1,158 @@ +# A CLI menu engine in ZSH + +Written by Marc Chantreux + +## How to install + +Zenu requires at least zsh and GNU sed to work. + +First, source the ZSH functions written in zenu.zsh in your `.zshrc` file + + echo ". path/to/zenu/zenu.zsh" >> path/to/.zshrc + +Then provide menu files in a `menus` folder found at the root of this git +project. Create it if it doesn't exist. Examples given in the `eg` folder can +be copied to `menus`. + +Build the script files + + make + +And launch the loop + + zenu.loop in path/to/zenu/menus + +If you used the examples given in `eg` you should see + + mail + recent (MRU) + jobs + notes + network + +With some letters highlighted. + +You can make the command `zenu.loop in path/to/zenu/menus` easily accessible +in you `.zshrc` file : + + # With a shortcut (ctrl+w) + bindkey -s '' 'zenu.loop in path/to/zenu/menus' + # With an alias + alias z="zenu.loop in path/to/zenu/menus" + +## Usage + +To enter submenus and/or execute commands, use the highlighted key. By default +to go back one menu press enter. + +### Creating / Customizing menus + +Menus are stored in the `menus` folder. The file named `main` is the default +starting menu. A menu is defined as + + 1. A list of commands and/or submenus with one given key being its activator + +This part of the main menu given as an example looks like : + + mail + recent (MRU) + jobs + notes + network + +by default the character preceding the activator key has to be `ctrl+_` : ``. + + 2. An optional "pre" section + +This section is arbitrary zsh code executed before zenu listens for a key +press. It can be used to make the following section easier to write or print +information below the menu section. By default this section starts after a `## +pre` comment in our menu declaration. + +In the `network` menu given as an example in the `eg` folder this section the +pre section is as follows : + + ## pre + local save=$zenu_store/network_interface + local state=$zenu_store/network_state + local nif= + touch $save + read nif < $save + echo + ip -br a | sed -r " + s/ /! / # separator for pick + s/^/ / # margin + "| tee $state | + sed "/${nif:-é}!/s/.*/\x1b[7m&\x1b[m/;s/!/ /" + +Which (at least on my machine) prints basic information about the machines +network interfaces. This could also by a simple heredoc to document key +shortcuts or what each command does. + + 3. A scripting "react" section + +This section is where you declare what each command should do. It starts with a +`## react` command and follows the zsh `case` syntax. + +The react section of the main menu in the eg folder : + + ## react + ;; (m) zenu+ mail + ;; (r) zenu+ mru + ;; (w) zenu+ network + ;; (n) vim ~p/start +'cd %:h' +'setf roguemode' + +The line should always start with `;;`. The letter between brackets should +match with the corresponding activator key in the first section. In the first +section the "m" key was identified as activating the `mail` command therefore +corresponding reaction should be `;; (m) command`. + +What comes after the activation key is arbitrary zsh code. If a submenu is to be +opened the `zenu+` function, written in `zenu.zsh` can be used with the name of +the submenu passed as an argument. For it to work the given argument has to exist +as a menu file in `menus`. + +The entire main menu file with an added small tutorial would be : + + mail + recent (MRU) + jobs + notes + network + ## pre + <<% cat + Welcome to your menu + Press the highlighted keys to navigate and enter to go back up one menu + % + ## react + ;; (m) zenu+ mail + ;; (r) zenu+ mru + ;; (w) zenu+ network + ;; (n) vim ~p/start +'cd %:h' +'setf roguemode' + +### Changing defaults + +#### "Go up a menu" key + +To modify the default "go up a menu" key from enter to something else edit the +case around line 26 of `bin/build`. + +For example, to substitute enter for both backspace and `q` + + ... + case "\$zenu_key" + in (\$'') zenu-- + ;; (\$'q') zenu-- + ... + +#### Activator key declarator + +To modify which character has to precede the activator key for a command from +ctrl+_ to something else + +#### Default starting menu + +To modify the default starting menu from main to another file modify line 36 of +zenu.zsh + + zenu_stack=( anotherfile ) diff --git a/README.nope b/README.nope @@ -1,156 +0,0 @@ -# A CLI menu engine in ZSH - -Written by Marc Chantreux - -## How to install - -First, source the ZSH functions written in zenu.zsh in your `.zshrc` file - - echo ". path/to/zenu/zenu.zsh" >> path/to/.zshrc - -Then provide menu files in a `menus` folder found at the root of this git -project. Create it if it doesn't exist. Examples given in the `eg` folder can -be copied to `menus`. - -Build the script files - - make - -And launch the loop - - zenu.loop in path/to/zenu/menus - -If you used the examples given in `eg` you should see - - mail - recent (MRU) - jobs - notes - network - -With some letters highlighted. - -You can make the command `zenu.loop in path/to/zenu/menus` easily accessible -in you `.zshrc` file : - - # With a shortcut (ctrl+w) - bindkey -s '' 'zenu.loop in path/to/zenu/menus' - # With an alias - alias z="zenu.loop in path/to/zenu/menus" - -## Usage - -To enter submenus and/or execute commands, use the highlighted key. By default -to go back one menu press enter. - -### Creating / Customizing menus - -Menus are stored in the `menus` folder. The file named `main` is the default -starting menu. A menu is defined as - - 1. A list of commands and/or submenus with one given key being its activator - -This part of the main menu given as an example looks like : - - mail - recent (MRU) - jobs - notes - network - -by default the character preceding the activator key has to be `ctrl+_` : ``. - - 2. An optional "pre" section - -This section is arbitrary zsh code executed before zenu listens for a key -press. It can be used to make the following section easier to write or print -information below the menu section. By default this section starts after a `## -pre` comment in our menu declaration. - -In the `network` menu given as an example in the `eg` folder this section the -pre section is as follows : - - ## pre - local save=$zenu_store/network_interface - local state=$zenu_store/network_state - local nif= - touch $save - read nif < $save - echo - ip -br a | sed -r " - s/ /! / # separator for pick - s/^/ / # margin - "| tee $state | - sed "/${nif:-é}!/s/.*/\x1b[7m&\x1b[m/;s/!/ /" - -Which (at least on my machine) prints basic information about the machines -network interfaces. This could also by a simple heredoc to document key -shortcuts or what each command does. - - 3. A scripting "react" section - -This section is where you declare what each command should do. It starts with a -`## react` command and follows the zsh `case` syntax. - -The react section of the main menu in the eg folder : - - ## react - ;; (m) zenu+ mail - ;; (r) zenu+ mru - ;; (w) zenu+ network - ;; (n) vim ~p/start +'cd %:h' +'setf roguemode' - -The line should always start with `;;`. The letter between brackets should -match with the corresponding activator key in the first section. In the first -section the "m" key was identified as activating the `mail` command therefore -corresponding reaction should be `;; (m) command`. - -What comes after the activation key is arbitrary zsh code. If a submenu is to be -opened the `zenu+` function, written in `zenu.zsh` can be used with the name of -the submenu passed as an argument. For it to work the given argument has to exist -as a menu file in `menus`. - -The entire main menu file with an added small tutorial would be : - - mail - recent (MRU) - jobs - notes - network - ## pre - <<% cat - Welcome to your menu - Press the highlighted keys to navigate and enter to go back up one menu - % - ## react - ;; (m) zenu+ mail - ;; (r) zenu+ mru - ;; (w) zenu+ network - ;; (n) vim ~p/start +'cd %:h' +'setf roguemode' - -### Changing defaults - -#### "Go up a menu" key - -To modify the default "go up a menu" key from enter to something else edit the -case around line 26 of `bin/build`. - -For example, to substitute enter for both backspace and `q` - - ... - case "\$zenu_key" - in (\$'') zenu-- - ;; (\$'q') zenu-- - ... - -#### Activator key declarator - -To modify which character has to precede the activator key for a command from -ctrl+_ to something else - -#### Default starting menu - -To modify the default starting menu from main to another file modify line 36 of -zenu.zsh - - zenu_stack=( anotherfile ) diff --git a/readme.fr b/readme.fr @@ -1,6 +0,0 @@ -# TODO - -* zenu.up is a bad name: better named cursor-up ? -* repartir de README.nope pour écrire une doc -* écrire un eg/ utilisable ? ou écrire un tuto ? -