zenu

Des menus dans votre terminal - retour accueil

Anonyme, en lecture seule : git clone git://bebou.netlib.re/zenu
Authentifié·e, en écriture : git clone ssh://git@bebou.netlib.re:1459/srv/git/zenu

Log | Files | Refs | README | zip | tar.gz |

ModeNameSize
-rw-r--r--.gitignore2L
-rw-r--r--README259L
-rwxr-xr-xbin/build42L
-rw-r--r--eg/main22L
-rw-r--r--eg/network17L
-rw-r--r--eg/screens117L
-rw-r--r--makefile16L
-rw-r--r--zenu.zsh103L

README (7666B)


      1 # A CLI menu engine in ZSH
      2 
      3 Written by Marc Chantreux
      4 
      5 ## How to install
      6 
      7 Zenu requires at least zsh and GNU sed to work. On debian machines they can be
      8 installed with :
      9 
     10 	apt install zsh coreutils
     11 
     12 Provide menu files in a `menus` folder found at the root of this git
     13 project. Create it if it doesn't exist :
     14 
     15 	mkdir -p path/to/zenu/menus
     16 
     17 Examples given in the `eg` folder can be copied to `menus` :
     18 
     19 	cp path/to/zenu/eg/* menus
     20 
     21 Build the script files
     22 
     23 	make
     24 
     25 ### Launch if you use zsh as your login shell
     26 
     27 Source the ZSH functions written in zenu.zsh in your `.zshrc` file. If it
     28 doesn't exist you may create it, preferably in your home. In a typical install
     29 this would be done with (replace `path/to/zenu/` with the folder in which you
     30 found this README file`) :
     31 
     32 	echo ". path/to/zenu/zenu.zsh" >> $HOME/.zshrc
     33 
     34 And launch the loop
     35 
     36 	zenu.loop in path/to/zenu/menus
     37 
     38 You can make the command `zenu.loop in path/to/zenu/menus` easily accessible
     39 in you `.zshrc` file :
     40 
     41 	# With an alias
     42 	alias z="zenu.loop in path/to/zenu/menus"
     43 	# And a shortcut (ctrl+w)
     44 	bindkey -s '' 'z'
     45 
     46 ### Launch if you use another login shell
     47 
     48 You may still use zenu if you use another login shell. Launch zsh with a
     49 command that sources `zenu.zsh` and calls the `zenu.loop` command :
     50 
     51 	zsh -c '. ~/git/zenu/zenu.zsh; zenu.loop in ~/git/zenu/menus'
     52 
     53 Make sure you create a function or an alias in your shell's `rc` file for
     54 easier use :)
     55 
     56 ## Usage
     57 
     58 To enter submenus and/or execute commands, use the highlighted key. By default
     59 to go back one menu press enter.
     60 
     61 ### Creating / Customizing menus
     62 
     63 Menus are stored in the `menus` folder. The file named `main` is the default
     64 starting menu. A menu is defined as
     65 
     66 #### A list of commands and/or submenus with one given key being its activator
     67 
     68 This part of the main menu given as an example looks like :
     69 
     70 	_screens
     71 	_network
     72 	_update
     73 
     74 by default the character preceding the activator key has to be `_`.
     75 
     76   2. An optional "pre" section
     77 
     78 This section is arbitrary zsh code executed before zenu listens for a key
     79 press. It can be used to make the following section easier to write or print
     80 information below the menu section. By default this section starts after a `##
     81 pre` comment in our menu declaration.
     82 
     83 In the main menu pre section is as follows :
     84 
     85 	## pre
     86 	cat <<%
     87 	Highlighted key to open menu
     88 	q to go back
     89 	= to edit menu
     90 	%
     91 
     92 	zenu_battery=$( upower -i /org/freedesktop/UPower/devices/DisplayDevice | grep -E 'percentage|time')
     93 	current_time=$(date +"%Hh%M.")
     94 	zenu_ssid="ssid:$( nmcli | grep "connected to " | sed 's/.*\( .*$\)/\1/' )"
     95 	echo "${ssid:-not connected}\n$current_time\n$battery"
     96 	ip -4 -br  addr | tail -n1 | tr -s ' ' | cut -f3 -d" "
     97 
     98 
     99 Which (at least on our debian machines) prints basic information about the machine network interfaces, battery state & time. 
    100 
    101   3. A scripting "react" section
    102 
    103 This section is where you declare what each command should do. It starts with a
    104 `## react` command and follows the zsh `case` syntax.
    105 
    106 The react section of the main menu in the eg folder :
    107 
    108 	## react
    109 	;; (s) zenu+ screens
    110 	;; (n) zenu+ network
    111 	;; (u)
    112 		sudo apt update && sudo apt upgrade
    113 		read -k1
    114 
    115 The line should always start with `;;`. The letter between brackets should
    116 match with the corresponding activator key in the first section. In the first
    117 section the "m" key was identified as activating the `mail` command therefore
    118 corresponding reaction should be `;; (m) command`.
    119 
    120 What comes after the activation key is arbitrary zsh code. If a submenu is to be
    121 opened the `zenu+` function, written in `zenu.zsh` can be used with the name of
    122 the submenu passed as an argument. For it to work the given argument has to exist
    123 as a menu file in `menus`.
    124 
    125 The entire main menu file with an added small tutorial would be :
    126 
    127 	_screens
    128 	_network
    129 	_update
    130 	## pre
    131 	cat <<%
    132 	Highlighted key to open menu
    133 	q to go back
    134 	= to edit menu
    135 	%
    136 
    137 	battery=$( upower -i /org/freedesktop/UPower/devices/DisplayDevice | grep -E 'percentage|time')
    138 	current_time=$(date +"%Hh%M.")
    139 	ssid="ssid:$( nmcli | grep "connected to " | sed 's/.*\( .*$\)/\1/' )"
    140 	echo "${ssid:-not connected}\n$current_time\n$battery"
    141 	ip -4 -br  addr | tail -n1 | tr -s ' ' | cut -f3 -d" "
    142 
    143 	## react
    144 	;; (s) zenu+ screens
    145 	;; (n) zenu+ network
    146 	;; (u)
    147 		sudo apt update && sudo apt upgrade
    148 		read -k1
    149 
    150 ### Launching a specific submenu
    151 
    152 You might want to directly get access to a specific submenu without having to
    153 navigate through the tree, effectively overriding the default start menu
    154 `main`. To achieve this use the `from` option :
    155 
    156 	zenu.loop in path/to/zenu/menus from network
    157 
    158 `zenu` will be launched as if the `network` was the `main` menu.
    159 
    160 ### Editing an existing menu while inside zenu
    161 
    162 At any moment you can press the default key `=` and edit the current menu.
    163 Menus will be recompiled automatically. The `EDITOR` environnment variable will
    164 be read to know which text editor to use. If you wish to set it write
    165 
    166 	EDITOR=your-favorite-editor
    167 
    168 In the `rc` file of your shell (`.bashrc`, `.zshrc` etc). Alternatively you can
    169 specify the variable only for zenu when executing the command :
    170 
    171 	EDITOR=your-favorite-editor zenu.loop in path/to/menus
    172 
    173 If EDITOR is not set `vim` is used as the default editor.
    174 
    175 ### Creating a new menu inside zenu
    176 
    177 If you try to open a non existing menu with a `zenu+` command you will be asked
    178 wether you want to create said menu or not. If you do a dummy file will be
    179 created with the corresponding file name and opened in a text editor. Therefore
    180 if you want to create a new menu inside zenu you can edit the current menu with
    181 `=`, add a `zenu+ menu-to-create` command, exit the editor and execute said
    182 command.
    183 
    184 The `EDITOR` environnment variable will be read to know which text editor to
    185 use. If you wish to set it write
    186 
    187 	EDITOR=your-favorite-editor
    188 
    189 In the `rc` file of your shell (`.bashrc`, `.zshrc` etc). Alternatively you can
    190 specify the variable only for zenu when executing the command :
    191 
    192 	EDITOR=your-favorite-editor zenu.loop in path/to/menus
    193 
    194 If EDITOR is not set `vim` is used as the default editor.
    195 
    196 ### Changing defaults
    197 
    198 #### "Go up a menu" key and "edit menu" key
    199 
    200 To modify the default "go up a menu" key from enter to something else edit the
    201 case around line 26 of `bin/build`.
    202 
    203 For example, to substitute enter for both backspace and `q`
    204 
    205 	...
    206 	case "\$zenu_key"
    207 	in (\$'') zenu--
    208 	;; (\$'q') zenu--
    209 	...
    210 
    211 The editing key `=` can be changed in a similar way.
    212 
    213 #### Activator key declarator
    214 
    215 To modify which character has to precede the activator key for a command from `_`
    216 to say `~` swap the `_` characters in these two lines in `bin/build` :
    217 
    218 	;; (face   | -f) sed -En '/^##/q;s/_(.)/\1/g;s/^/ /p' "$@"
    219 	[...]
    220 	sed -En '/^##/q;s/(.*)_((.).*)/\3 \1\2 /;p' "$@" | awk '
    221 
    222 to
    223 
    224 	;; (face   | -f) sed -En '/^##/q;s/~(.)/\1/g;s/^/ /p' "$@"
    225 	[...]
    226 	sed -En '/^##/q;s/(.*)~((.).*)/\3 \1\2 /;p' "$@" | awk '
    227 
    228 You'll have to modify your menus accordingly. You can achieve this with this
    229 command (if you have a `sed` with the `-i` option) :
    230 
    231 	sed -iE '1,/## +pre/ s/_/~/' path/to/menus/*
    232 
    233 #### Default starting menu
    234 
    235 To modify the default starting menu from main to another file modify line 36 of
    236 zenu.zsh
    237 
    238 	zenu_stack=( anotherfile )
    239 
    240 #### Shortcut to the root
    241 
    242 It is possible to take a shortcut back to the root with the command :
    243 
    244 	zenu_stack=( main )
    245 
    246 This command could be added to all menus by adding a line to `bin/build` :
    247 
    248 	...
    249 	case "\$zenu_key"
    250 	in (\$'q') zenu--
    251 	in ('~')   zenu_stack=( main )
    252 	...
    253 
    254 Or to every menu with a sed script :
    255 
    256 	sed -Ei '$ a;; ("~") zenu_stack=( main )' path/to/menus/*
    257 
    258 Take note that if you use another root menu than `main` you'll have to adapt
    259 the above.
README.nope - zenu - Des menus dans votre terminal

zenu

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 )