Des menus dans votre terminal - retour accueil
git clone git://bebou.netlib.re/zenu
Log | Files | Refs |
README.nope (4068B)
1 # A CLI menu engine in ZSH 2 3 Written by Marc Chantreux 4 5 ## How to install 6 7 First, source the ZSH functions written in zenu.zsh in your `.zshrc` file 8 9 echo ". path/to/zenu/zenu.zsh" >> path/to/.zshrc 10 11 Then provide menu files in a `menus` folder found at the root of this git 12 project. Create it if it doesn't exist. Examples given in the `eg` folder can 13 be copied to `menus`. 14 15 Build the script files 16 17 make 18 19 And launch the loop 20 21 zenu.loop in path/to/zenu/menus 22 23 If you used the examples given in `eg` you should see 24 25 mail 26 recent (MRU) 27 jobs 28 notes 29 network 30 31 With some letters highlighted. 32 33 You can make the command `zenu.loop in path/to/zenu/menus` easily accessible 34 in you `.zshrc` file : 35 36 # With a shortcut (ctrl+w) 37 bindkey -s '' 'zenu.loop in path/to/zenu/menus' 38 # With an alias 39 alias z="zenu.loop in path/to/zenu/menus" 40 41 ## Usage 42 43 To enter submenus and/or execute commands, use the highlighted key. By default 44 to go back one menu press enter. 45 46 ### Creating / Customizing menus 47 48 Menus are stored in the `menus` folder. The file named `main` is the default 49 starting menu. A menu is defined as 50 51 1. A list of commands and/or submenus with one given key being its activator 52 53 This part of the main menu given as an example looks like : 54 55 mail 56 recent (MRU) 57 jobs 58 notes 59 network 60 61 by default the character preceding the activator key has to be `ctrl+_` : ``. 62 63 2. An optional "pre" section 64 65 This section is arbitrary zsh code executed before zenu listens for a key 66 press. It can be used to make the following section easier to write or print 67 information below the menu section. By default this section starts after a `## 68 pre` comment in our menu declaration. 69 70 In the `network` menu given as an example in the `eg` folder this section the 71 pre section is as follows : 72 73 ## pre 74 local save=$zenu_store/network_interface 75 local state=$zenu_store/network_state 76 local nif= 77 touch $save 78 read nif < $save 79 echo 80 ip -br a | sed -r " 81 s/ /! / # separator for pick 82 s/^/ / # margin 83 "| tee $state | 84 sed "/${nif:-é}!/s/.*/\x1b[7m&\x1b[m/;s/!/ /" 85 86 Which (at least on my machine) prints basic information about the machines 87 network interfaces. This could also by a simple heredoc to document key 88 shortcuts or what each command does. 89 90 3. A scripting "react" section 91 92 This section is where you declare what each command should do. It starts with a 93 `## react` command and follows the zsh `case` syntax. 94 95 The react section of the main menu in the eg folder : 96 97 ## react 98 ;; (m) zenu+ mail 99 ;; (r) zenu+ mru 100 ;; (w) zenu+ network 101 ;; (n) vim ~p/start +'cd %:h' +'setf roguemode' 102 103 The line should always start with `;;`. The letter between brackets should 104 match with the corresponding activator key in the first section. In the first 105 section the "m" key was identified as activating the `mail` command therefore 106 corresponding reaction should be `;; (m) command`. 107 108 What comes after the activation key is arbitrary zsh code. If a submenu is to be 109 opened the `zenu+` function, written in `zenu.zsh` can be used with the name of 110 the submenu passed as an argument. For it to work the given argument has to exist 111 as a menu file in `menus`. 112 113 The entire main menu file with an added small tutorial would be : 114 115 mail 116 recent (MRU) 117 jobs 118 notes 119 network 120 ## pre 121 <<% cat 122 Welcome to your menu 123 Press the highlighted keys to navigate and enter to go back up one menu 124 % 125 ## react 126 ;; (m) zenu+ mail 127 ;; (r) zenu+ mru 128 ;; (w) zenu+ network 129 ;; (n) vim ~p/start +'cd %:h' +'setf roguemode' 130 131 ### Changing defaults 132 133 #### "Go up a menu" key 134 135 To modify the default "go up a menu" key from enter to something else edit the 136 case around line 26 of `bin/build`. 137 138 For example, to substitute enter for both backspace and `q` 139 140 ... 141 case "\$zenu_key" 142 in (\$'') zenu-- 143 ;; (\$'q') zenu-- 144 ... 145 146 #### Activator key declarator 147 148 To modify which character has to precede the activator key for a command from 149 ctrl+_ to something else 150 151 #### Default starting menu 152 153 To modify the default starting menu from main to another file modify line 36 of 154 zenu.zsh 155 156 zenu_stack=( anotherfile )