4 |
5 | Introduction
6 | Getting the source
7 | Optional installation locations
8 | Help in bash-menu
9 | Using bash-menu
10 | Sub-commands
11 | Editing
12 | Using the _title_ command
13 | Examples
14 |
15 | ## Introduction
16 | **dynamide** [bash-menu](http://dynamide.org/bash-menu) is a menu system for bash which keeps lists of
17 | - directories you wish to navigate to
18 | - command lines you wish to execute
19 | - spaces, which group directories and commands by project
20 |
21 | You use the menu to select from these lists. Selecting a directory from a menu changes to that directory. Selecting a command from a command menu executes that command. You can use the menu or the command line to add to, remove from, and edit these lists.
22 |
23 | A fancy bash-prompt is also provided, which give you options to display on one line the title, user, host, pwd, and git-status. See [Using the *title* command](#using-the-title-command).
24 |
25 | After you install bash-menu and log in, you'll have a custom prompt, and some new commands:
26 | - **d** directory changer
27 | - **da** add a directory to the list
28 | - **m** menu of executable command-lines
29 | - **ma** add a command to the list
30 | - **catall** cat all text files in current directory with a colored line between each.
31 | - **title** set the title, user, or hostname in a multi-line, colored PS1 bash prompt.
32 |
33 | ## Getting the source
34 |
35 | On [GitHub](https://github.com/dynamide/bash-menu), mash on the "Download ZIP" button, and extract to `~/.bash-menu`, or use wget or curl:
36 |
37 | cd ~
38 | curl -o master.zip https://codeload.github.com/dynamide/bash-menu/zip/master
39 | unzip master.zip
40 | mv bash-menu-master/ ~/.bash-menu/
41 |
42 | Or, checkout bash-menu from GitHub:
43 |
44 | cd ~
45 | git clone https://github.com/dynamide/bash-menu.git .bash-menu
46 |
47 | or
48 |
49 | cd ~
50 | git clone git@github.com:dynamide/bash-menu.git .bash-menu
51 |
52 | Then pull in the bash-menu from your bash profile, by sourcing in the bash menu, e.g.
53 |
54 | | _~/.bash_profile_ |
55 | | :------------- |
56 | | source ~/.bash-menu/.bash_profile |
57 |
58 | You can source with `.` or `source`.
59 |
60 | All of the shell aliases created by bash-menu are defined in `~/.bash-menu/aliases` (or `$DYNAMIDE_MENU/aliases`). Please review these aliases before launching.
61 |
62 | The next time you log in, you'll have a custom prompt, and some new commands. Try the main command `d` for example.
63 |
64 | Here is a sample bash prompt on two lines with current working directory, and git status:
65 |
66 |
67 |
68 | ## Optional Installation Locations
69 |
70 | By default, the above check-out will leave you with a new, hidden directory in your home directory, that is, `~/.bash-menu`, or something like `/home/laramie/.bash-menu/`. **bash-menu** knows about this because it sets DYNAMIDE_MENU in `~/.bash-menu/.bash_profile`.
71 |
72 | If you checked out to some directory other than `~/.bash-menu`, for example `~/.my-menu/` then you need to do two things to connect **bash-menu** to your shell.
73 |
74 | 1) Edit this file, on the line where it sets DYNAMIDE_MENU (by default it is `DYNAMIDE_MENU=~/.bash-menu`), so that **bash-menu** will know where its home directory is.
75 |
76 | | _~/.my-menu/.bash_profile_ |
77 | | :------------- |
78 | | DYNAMIDE_MENU=~/.my-menu |
79 | | ... |
80 |
81 |
82 | 2) Then, in your ~/.bash_profile source in the **bash-menu** control file we just edited:
83 |
84 | | _~/.bash_profile_ |
85 | | :------------- |
86 | | source ~/.my-menu/.bash_profile |
87 |
88 |
89 | ## Help in bash-menu
90 | To see help, run with `-h` or `h` which will dump out usage.
91 |
92 | `d -h`
93 |
94 | To see help on options:
95 |
96 | `d h options`
97 |
98 | To see all the options and their alternate spellings, see:
99 |
100 | `d h aliases`
101 |
102 | To see the current configuration, see:
103 |
104 | `d h info`
105 |
106 | ## Using bash-menu
107 |
108 | To get started, just type `d` at your new prompt. From there you can choose a listed item by typing it's number.
109 |
110 | Here is the dynamide bash-menu being used to change to directory 6 on the menu:
111 |
112 |
113 |
114 | Note that it shows you the directory you chose, "/Users/vcrocla/src/dynamide/build/resource_root", and then a quick "ls" of that directory, then it changes to that directory. You can tell because the fancy bash prompt has changed and now shows the current working directory as /Users/vcrocla/src/dynamide/build/resource_root, and the git status in that directory is (master) which means we are on git branch "master" with no pending pulls or pushes.
115 |
116 | From a menus such as the directory menu, you can type another menu option. You can type `?` to see the mini-help of sub-commands at this menu.
117 |
118 |
119 |
120 | ## Sub-commands
121 |
122 | You can choose options on the command line, and skip the menus. You can also choose some options after you have launched bash-menu and are sitting in a menu, where you are prompted for a choice. If you type a number from the list of choices, you will get that choice. But there are also sub-commands at these menus. These mirror options available on the command line. So you could, for example, launch right into your command menu like this:
123 |
124 | `d -m`
125 |
126 | Or, you could launch the directory menu, then change to the command menu with this sequence:
127 | ```
128 | d
129 | m
130 | ```
131 |
132 | This represents typing `d` at your bash prompt, then typing `m` at the **choose dir>** prompt.
133 |
134 | The `edit` sub-command is context-sensitive, and will launch your EDITOR or VISUAL editor to let you edit the correct menu.
135 |
136 | Here is an actual example:
137 |
138 |
139 |
140 | The sub-commands take an option form: `-h`, a single-letter form: `h`, and a word form: `help`.
141 |
142 | Here are all the sub-command options and their equivalents (-c and -s are completely equivalent):
143 |
144 |
145 | | option | cmd | cmd | context |
146 | | ------------- | ------------- | ------------- | ------------- |
147 | | -a | a | add |directory, command|
148 | | -c | c | connect |directory, command|
149 | | -d | d | list |command, space|
150 | | -e | e | edit |*|
151 | | -h | h | help |*|
152 | | -i | i | info |*|
153 | | -l | l | list |command, space |
154 | | -m | m | menu |directory, space|
155 | | -s | s | space |directory, command|
156 | | -x | x | delete |directory, command|
157 | | -o | o | options |help|
158 | | -a | a | aliases |help|
159 | | -i | i | info |help|
160 |
161 |
162 | Options or _cmd_ may be used on the command line.
163 |
164 | Options or _cmd_ may be used as sub-commands.
165 |
166 | Help takes subcommands `options`, `aliases`, and `info`, or their alternate names listed above. For example:
167 |
168 | ```
169 | d h info
170 | ```
171 |
172 | On the command line, these options could look like these examples:
173 | ```
174 | d a # Add to your directory list
175 |
176 | d e # Edit your directory list
177 |
178 | d m # Show your command menu
179 | d -m
180 |
181 | d m e # Edit your command menu
182 | d m -e
183 | d m edit
184 |
185 | d s e # Edit your spaces menu
186 | d s -e
187 | d -s edit
188 | d -s -e
189 | d s edit
190 | ```
191 | And so on.
192 |
193 | ## Using the *title* command
194 |
195 | bash-menu comes with a custom PS1 bash prompt. This prompt can show you:
196 | - title
197 | - user
198 | - host
199 | - pwd
200 | - git-status
201 |
202 | To see all the options, type
203 |
204 | `title -h`
205 |
206 | Here is a sample of what setting various options does to your prompt:
207 |
208 |
209 |
210 | In these examples, my user name is "vcrocla", my host is "SFCAML-G2XFD56", which I override with the fake hostname "myhost".
211 |
212 | The title (appears at left of the first line) is any placeholder that reminds you of what this shell was for. If you use -w, or -window, the title is also sent to the shell window's title bar.
213 |
214 | My directory "~/src/tagonomy" is a git repository, and its git status in that directory is (master) which means we are on git branch "master" with no pending pulls or pushes. My directory "~/src/dynamide" is also a git repository, and also is on branch "master".
215 |
216 | You'll also see the numbers of commits ahead/behind if you are not up-to-date. (Thanks to the authors who wrote `git-branch-status`, listed in our NOTICE file.)
217 |
218 | Here is what it looks like when you are ahead:
219 |
220 |
221 |
222 | If you type `git status` you'll see why:
223 |
224 |
225 |
226 | Here is what it looks like when you are ahead and behind:
227 |
228 |
229 |
230 | If you type `git status` (I have it aliased to `st`) you'll see why:
231 |
232 |
233 |
234 | To customize your prompt, call `title` in your ~/.bash_profile *after* you source in ~/.bash-menu/.bash_profile:
235 |
236 | | _~/.bash_profile_ |
237 | | :------------- |
238 | | source ~/.bash-menu/.bash_profile |
239 | | source ~/.laramie/.bash_profile |
240 |
241 | | _~/.laramie/.bash_profile_ |
242 | | :------------- |
243 | | DYNAMIDE_SPACES_LIST=~/.laramie/spaces.laramie.list |
244 | | title -user -nohost -title Lappy -window |
245 |
246 | ## Editing
247 |
248 | You can edit your menus in two ways:
249 | - 1. using the command-line args or sub-commands in menus, and
250 | - 2. using your console editor such as `vi` or `emacs`.
251 |
252 | For case (2), bash-menu will launch your EDITOR or VISUAL editor on the appropriate file. Just edit, then save normally. Files contain non-blank lines or separators. Separators are three hyphens alone on one line, like this:
253 | ```
254 | /some/directory/on/dirlist
255 | ---
256 | /other/dirs
257 | /other/dirs/bin
258 | ```
259 |
260 | | _Sub-commands:_ ||
261 | | :------------- | :------------- |
262 | |d x | launches the delete menu for directory lists|
263 | |d x 3 | deletes directory list item 3|
264 | |d mx | launches the delete menu for commands|
265 | |d mx 3 | deletes command menu item 3|
266 | |d m x | launches the delete menu for commands, using submenu|
267 | |d ma | add to the command menu, using command-line|
268 | |d m a | add to the command menu, using submenu|
269 | |d e | launch EDITOR for directory lists|
270 | |d m e | launch EDITOR for the command menu|
271 | |d s | launch the space chooser|
272 |
273 |
274 | ##Examples
275 |
276 | **Show your directory menu**
277 |
278 | d
279 |
280 | **Show your command menu**
281 |
282 | m
283 |
284 | **put shell history item 467 (expanded) into your menu**
285 |
286 | d -ma !467
287 |
288 | **put a command into your menu using the alias `ma` (installed in ~/.bash-menu/aliases)**
289 |
290 | ma find . -iname '*my-file.*'
291 |
292 | **chose menu item 2 and execute it**
293 |
294 | d -m 2
295 |
296 | **chose menu item 2 and execute it**
297 |
298 | m 2
299 |
300 | **put a separator into your menu using the special string ---**
301 |
302 | ma ---
303 |
304 | **Add ~/zanzibar (expanded) to your directory list**
305 |
306 | d -a ~/zanzibar
307 |
308 | **Add ~/zanzibar (NOT expanded) to your directory list**
309 |
310 | d -a '~/zanzibar'
311 |
312 | **Add $JAVA_HOME (NOT expanded) to your directory list**
313 |
314 | d -a '$JAVA_HOME'
315 |
316 | **Add $JAVA_HOME (expanded) to your directory list**
317 |
318 | d -a $JAVA_HOME
319 |
320 | **Choose directory 2 from your directory list**
321 |
322 | d 2
323 |
324 | **Add . (expanded using \`pwd\`) to your directory list**
325 |
326 | d -a .
327 |
328 | **Add `foo` in current directory (expanded using `pwd`/foo) to your directory list**
329 |
330 | d -a foo
331 |
332 | **Add /var/log (full path, unexpanded) to your directory list**
333 |
334 | d -a /var/log
335 |
336 | **Add a frequently used Maven (mvn) command to the menu and use the menu to run it. The command is
337 | `mvn -DskipTests -o install` and we are adding the whole thing using the ma command.**
338 |
339 |
340 |
341 | `mvn` is a popular build tool. You can see where it begins to run with the line "[INFO] Scanning for projects...
342 |
343 | **Re-run that command without looking at the menu, now that you know the number**
344 |
345 |
346 |
347 | *You could also run the command in your shell, then use the `ma` command to capture the command to your command list in your current space. The ma command will take a command-line as its arguments. With no arguments, the ma command grabs the last item on your history. Note that you need to read the output of the ma command to see the index of the new command, in this case, the number `4`.*
348 |
349 | ```
350 | mvn -DskipTests -o install
351 | ma
352 | m 4
353 | ```
354 |
355 |
356 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # bash-menu
2 |
3 |
4 |
5 | Introduction
6 | Philosophy / Workflow
7 | Getting the source
8 | Optional installation locations
9 | Help in bash-menu
10 | Using bash-menu
11 | Sub-commands
12 | Editing
13 | Using the _title_ command
14 | Scripting
15 | Examples
16 |
17 | ## Introduction
18 | **dynamide** [bash-menu](http://dynamide.org/bash-menu) is a menu system for bash which keeps lists of
19 | - directories you wish to navigate to
20 | - command lines you wish to execute
21 | - spaces, which group directories and commands by project
22 |
23 | Here's a screenshot showing launching the directory menu, then switching to the command menu:
24 |
25 |
26 |
27 | You use the menu to select from these lists. Selecting a directory from a menu changes to that directory. Selecting a command from a command menu executes that command. You can use the menu or the command line to add to, remove from, and edit these lists.
28 |
29 | A fancy bash-prompt is also provided, which gives you options to display on one line the title, user, host, pwd, and git-status. See [Using the *title* command](#using-the-title-command).
30 |
31 | After you install **bash-menu** and log in, you'll have a custom prompt, and some new commands:
32 | - **d** directory changer
33 | - **da** add a directory to the list
34 | - **m** menu of executable command-lines
35 | - **ma** add a command to the list
36 | - **catall** cat all text files in current directory with a colored line between each.
37 | - **title** set the title, user, or hostname in a multi-line, colored PS1 bash prompt.
38 |
39 | ## Philosophy / Workflow
40 |
41 | #### Why do you want a bash menu?
42 | - You are a whiz at `history`, tab-completion, expansion, reverse-search... but you still have to ask: what am I doing here, how did I get here, and what do I do next?
43 | - you work on several projects, and having them all together in one history list doesn't help
44 | - you work in multiple terminals simultaneously, and synchronizing the histories doesn't help
45 | - you prefer command-line tools for their configurable options, but so many options to remember!
46 | - you hate typing long paths or aliasing everything
47 | - you run multiple, complicated command lines repeatedly, but they aren't quite ready for putting into scripts yet.
48 |
49 | #### Prototyping Workflow
50 |
51 | **Scenario 1**
52 | Execute command-by-command at the command-line, until you get one that does just what you want it to do.
53 | Add that last command by executing `ma` which grabs the last item from your history and adds it to the command menu.
54 |
55 | **Scenario 2**
56 | You have completed a prototyping session locally, and would like to write a script to capture all the steps you did.
57 | List your history, then cherry-pick the commands you want using `ma
153 |
154 | ## Optional Installation Locations
155 |
156 | By default, the above check-out will leave you with a new, hidden directory in your home directory, that is,
157 | ```
158 | ~/.bash-menu
159 | ```
160 |
161 | or something like `/home/laramie/.bash-menu/`. **bash-menu** knows about this because it sets DYNAMIDE_MENU in `~/.bash-menu/.bash_profile`.
162 |
163 | | _~/.bash-menu/.bash_profile_ |
164 | | :------------- |
165 | | DYNAMIDE_MENU=~/.bash-menu |
166 | | ... |
167 |
168 | If you checked out to some directory other than `~/.bash-menu`, for example `~/.my-menu/` then you need to do two things to connect **bash-menu** to your shell.
169 |
170 | 1) Edit this file, on the line where it sets DYNAMIDE_MENU (by default it is `DYNAMIDE_MENU=~/.bash-menu`), so that **bash-menu** will know where its home directory is.
171 |
172 | | _~/.my-menu/.bash_profile_ |
173 | | :------------- |
174 | | DYNAMIDE_MENU=~/.my-menu |
175 | | ... |
176 |
177 |
178 | 2) Then, in your ~/.bash_profile source in the **bash-menu** control file we just edited:
179 |
180 | | _~/.bash_profile_ |
181 | | :------------- |
182 | | source ~/.my-menu/.bash_profile |
183 |
184 |
185 | ## Help in bash-menu
186 | To see help, run with `-h` or `h` which will dump out usage.
187 |
188 | `d -h`
189 |
190 | To see help on options:
191 |
192 | `d h options`
193 |
194 | To see all the options and their alternate spellings, see:
195 |
196 | `d h aliases`
197 |
198 | To see the current configuration, see:
199 |
200 | `d h info`
201 |
202 | ## Using bash-menu
203 |
204 | To get started, just type `d` at your new prompt. From there you can choose a listed item by typing it's number.
205 |
206 | Here is the dynamide **bash-menu** being used to change to directory 6 on the menu:
207 |
208 |
209 |
210 | Note that it shows you the directory you chose, "/Users/vcrocla/src/dynamide/build/resource_root", and then a quick "ls" of that directory, then it changes to that directory. You can tell because the fancy bash prompt has changed and now shows the current working directory as /Users/vcrocla/src/dynamide/build/resource_root, and the git status in that directory is (master) which means we are on git branch "master" with no pending pulls or pushes.
211 |
212 | ## Sub-commands
213 |
214 | From menus such as the directory menu, you can type another menu option. You can type `?` to see the mini-help of sub-commands at this menu.
215 |
216 |
217 |
218 | You can choose options on the command line, and skip the menus. You can also choose some options after you have launched **bash-menu** and are sitting in a menu, where you are prompted for a choice. If you type a number from the list of choices, you will get that choice. But there are also sub-commands at these menus. These mirror options available on the command line. So you could, for example, launch right into your command menu like this:
219 |
220 | `d -m`
221 |
222 | Or, you could launch the directory menu, then change to the command menu with this sequence:
223 |
224 | `d` `Enter` `m` `Enter`
225 |
226 | that is, typing `d` at your bash prompt, then the `Enter` key (or `Return` key) then typing `m` at the **choose dir>** prompt, then `Enter` again.
227 |
228 | Here is an actual example:
229 |
230 |
231 |
232 | The sub-commands take an option form: `-h`, a single-letter form: `h`, and a word form: `help`.
233 |
234 | Here are all the sub-command options and their equivalents (-c and -s are completely equivalent):
235 |
236 |
237 | | option | cmd | cmd | context |
238 | | ------------- | ------------- | ------------- | ------------- |
239 | | -a | a | add |directory, command|
240 | | -c | c | connect |directory, command|
241 | | -d | d | list |command, space|
242 | | -e | e | edit |*|
243 | | -h | h | help |*|
244 | | -i | i | info |*|
245 | | -l | l | list |command, space |
246 | | -m | m | menu |directory, space|
247 | | -s | s | space |directory, command|
248 | | -x | x | delete |directory, command|
249 | | -o | o | options |help|
250 | | -a | a | aliases |help|
251 | | -i | i | info |help|
252 |
253 |
254 | The _option_ form or the _cmd_ form may be used on the command line, or as sub-commands.
255 |
256 | Help takes subcommands `options`, `aliases`, and `info`, or their alternate names listed above. For example:
257 |
258 | ```
259 | d h info
260 | ```
261 |
262 | The `edit` sub-command is context-sensitive, and will launch your EDITOR or VISUAL editor to let you edit the correct menu.
263 |
264 | On the command line, using these options could look like these examples below. Eeach group of commands is equivalent, so `d m` is the same as `d -m`:
265 | ```
266 | d a # Add to your directory list
267 |
268 | d e # Edit your directory list
269 |
270 | d m # Show your command menu
271 | d -m
272 |
273 | d m e # Edit your command menu
274 | d m -e
275 | d m edit
276 |
277 | d s e # Edit your spaces menu
278 | d s -e
279 | d -s edit
280 | d -s -e
281 | d s edit
282 | ```
283 | And so on.
284 |
285 | `d -ma` takes a special option flag, `-cd` that adds a `cd` to the current directory before the command you are adding.
286 |
287 | d -ma -cd #adds the last shell command to your command menu with a cd `pwd` before it.
288 | d -ma -cd !! #adds the last shell command to your command menu with a cd `pwd` before it.
289 | d -ma -cd !480 #adds shell history command number 480 to your command menu with a cd `pwd` before it.
290 | d -ma -cd bin/make #adds 'bin/make' to your command menu with a cd `pwd` before it.
291 |
292 | This works with the alias `ma` like so:
293 |
294 | ma -cd
295 | ma -cd bin/make
296 |
297 | NOTE: *There is no alias for -cd, so you can* **NOT** *do this without the hyphen on -cd:* ~~d -ma cd /bin/mycommand~~.
298 | In other words:
299 |
300 | LEGAL----> `d -ma -cd /bin/mycommand`
301 |
302 | ILLEGAL--> `d -ma cd /bin/mycommand`
303 |
304 | ## Using the *title* command
305 |
306 | **bash-menu** comes with a custom PS1 bash prompt. This prompt can show you:
307 | - title
308 | - user
309 | - host
310 | - pwd
311 | - git-status
312 |
313 | To see all the options, type
314 |
315 | `title -h`
316 |
317 | Here is a sample of what setting various options does to your prompt:
318 |
319 |
320 |
321 | In these examples, my user name is "vcrocla", my host is "SFCAML-G2XFD56", which I override with the fake hostname "myhost".
322 |
323 | The title (appears at left of the first line) is any placeholder that reminds you of what this shell was for. If you use -w, or -window, the title is also sent to the shell window's title bar.
324 |
325 | My directory "~/src/tagonomy" is a git repository, and its git status in that directory is (master) which means we are on git branch "master" with no pending pulls or pushes. My directory "~/src/dynamide" is also a git repository, and also is on branch "master".
326 |
327 | You'll also see the numbers of commits ahead/behind if you are not up-to-date. (Thanks to the authors who wrote `git-branch-status`, listed in our NOTICE file.)
328 |
329 | Here is what it looks like when you are ahead:
330 |
331 |
332 |
333 | If you type `git status` you'll see why:
334 |
335 |
336 |
337 | Here is what it looks like when you are ahead and behind:
338 |
339 |
340 |
341 | If you type `git status` (I have it aliased to `st`) you'll see why:
342 |
343 |
344 |
345 | To customize your prompt, call `title` in your ~/.bash_profile *after* you source in ~/.bash-menu/.bash_profile:
346 |
347 | | _~/.bash_profile_ |
348 | | :------------- |
349 | | source ~/.bash-menu/.bash_profile |
350 | | source ~/.laramie/.bash_profile |
351 |
352 | | _~/.laramie/.bash_profile_ |
353 | | :------------- |
354 | | DYNAMIDE_SPACES_LIST=~/.laramie/spaces.laramie.list |
355 | | title -user -nohost -title Lappy -window |
356 |
357 | ## Editing
358 |
359 | You can edit your menus in two ways:
360 | - 1. using the command-line args or sub-commands in menus, and
361 | - 2. using your console editor such as `vi` or `emacs`.
362 |
363 | For case (2), **bash-menu** will launch your EDITOR or VISUAL editor on the appropriate file. Just edit, then save normally. Files contain non-blank lines or separators.
364 |
365 |
366 | | _Sub-commands:_ |Editing Action|
367 | | :------------- | :------------- |
368 | |d x | launches the delete menu for directory lists|
369 | |d x 3 | deletes directory list item 3|
370 | |d mx | launches the delete menu for commands|
371 | |d mx 3 | deletes command menu item 3|
372 | |d m x | launches the delete menu for commands, using submenu|
373 | |d ma | add to the command menu, using command-line|
374 | |d m a | add to the command menu, using submenu|
375 | |d e | launch EDITOR for directory lists|
376 | |d m e | launch EDITOR for the command menu|
377 | |d s | launch the space chooser|
378 | |d s e | launch the space editor|
379 |
380 | ### Separators
381 |
382 | Separators are three hyphens alone on one line, like this:
383 | ```
384 | /some/directory/on/dirlist
385 | ---
386 | /bin/probe
387 | ---
388 | /other/dirs
389 | /other/dirs/bin
390 | ```
391 | Separators display in your menus as blank lines. So the above menu renders as:
392 |
393 |
394 |
395 | You can also put line-separating labels in, which will be displayed in your menu in highlight color, minus the leading `---`. You can use more `-` characters on that line, or any other printable character. Here I'm using `=` characters to help visually break up the menu.
396 | ```
397 | /some/directory/on/dirlist
398 | ---=== Area 51 ===
399 | /bin/probe
400 | ---=== Area 52 ===
401 | /other/dirs
402 | /other/dirs/bin
403 | ```
404 |
405 |
406 |
407 | ##Scripting
408 |
409 | In case you want to use **bash-menu** in a script itself, you'll want to use the quiet option: `-q` which suppresses all but the most essential output. The opposite is `-v` which gives debugging info.
410 |
411 | To keep things simple, you may wish to avoid aliases in your scripts and use the full names of things, e.g. instead of calling `d`, call `bash-menu-d` which is the name of the main bash function that `d` is aliased to.
412 |
413 | Remember that all `d` and `m` commands are relative to the current *space*, so you should change to your space first, or set it using DYNAMIDE_SPACES_LIST. You can programmatically set your space, e.g. by calling `d s 0` to select space `0` or `d s 1` to select space `1`. (NOTE: $DYNAMIDE_MENU/space.index is written out for you. However, you can overwrite it with the zero-based index of the space you want to use in DYNAMIDE_SPACES_LIST. Usually, `d s 0` is the preferred way.)
414 |
415 | After you call to set the space, e.g. `d s 0`, the following values are exported to your shell:
416 | ```
417 | DYNAMIDE_DIRLIST_LIST
418 | DYNAMIDE_MENU_LIST
419 | DYNAMIDE_MENU_SPACE_INDEX
420 | ```
421 |
422 | Here is how to set the env var to point to a specific space list, e.g.
423 | `DYNAMIDE_SPACES_LIST=~/.laramie/spaces.laramie.list`
424 |
425 | Here is how to programmatically get the menu line for an item in a file:
426 |
427 | ```
428 | line=`bash-menu-getFromList $DYNAMIDE_SPACES_LIST $DYNAMIDE_MENU_SPACE_INDEX`
429 | ```
430 |
431 | will output:
432 | ```
433 | [1]: /Users/vcrocla/.laramie/spaces/pearson
434 | ```
435 |
436 | Here is how to programmatically get the bare menu line for an item in a file without the index being displayed:
437 |
438 | ```
439 | line=`bash-menu-getFromList $DYNAMIDE_SPACES_LIST $DYNAMIDE_MENU_SPACE_INDEX bare`
440 | ```
441 |
442 | This technique can be used to read a line from any of the files: directories.list, menu.list, spaces.list, by passing the list name, and the zero-based index of non-separator lines. (Blank lines are not allowed in the list files.) For example, get the 3rd item (index 2) from your directory list:
443 |
444 | ```
445 | line=`bash-menu-getFromList $DYNAMIDE_DIRLIST_LIST 2 bare`
446 | ```
447 |
448 | For example, get the 4th item (index 3) from your menu list:
449 |
450 | ```
451 | line=`bash-menu-getFromList $DYNAMIDE_MENU_LIST 3 bare`
452 | ```
453 |
454 |
455 | ##Examples
456 |
457 |
458 | ###Show your directory menu
459 |
460 | d
461 |
462 | ###Show your command menu
463 |
464 | m
465 |
466 | ###put shell history item 467 (expanded) into your menu
467 |
468 | d -ma !467
469 |
470 | ###put a command into your menu using the alias `ma` (installed in ~/.bash-menu/aliases)
471 |
472 | ma find . -iname '*my-file.*'
473 |
474 | ###chose menu item 2 and execute it
475 |
476 | d -m 2
477 |
478 | ###chose menu item 2 and execute it
479 |
480 | m 2
481 | ###put a separator into your menu using the special string ---
482 |
483 | ma ---
484 |
485 | ###put a separating label into your menu using the special string ---
486 |
487 | ma ---Build RestReplay
488 |
489 | Everything after the `---` is treated as the label. Note that you don't need quotes around "Build RestReplay" because the ma command just grabs everything: `---Build RestReplay` is put into your menu on a line by itself.
490 |
491 | *Use separating labels help to organize and document groups in one list. Consider using the space feature, with the `d s` command, for working on other servers, or organizing by projects.*
492 |
493 | ###Add ~/zanzibar (expanded) to your directory list
494 |
495 | d -a ~/zanzibar
496 |
497 | ###Add ~/zanzibar (NOT expanded) to your directory list
498 |
499 | d -a '~/zanzibar'
500 |
501 | ###Add $JAVA_HOME (NOT expanded) to your directory list
502 |
503 | d -a '$JAVA_HOME'
504 |
505 | ###Add $JAVA_HOME (expanded) to your directory list
506 |
507 | d -a $JAVA_HOME
508 |
509 | ###Choose directory 2 from your directory list
510 |
511 | d 2
512 |
513 | ###Add . (expanded using \`pwd\`) to your directory list
514 |
515 | d -a .
516 |
517 | ###Add `foo` in current directory (expanded using `pwd`/foo) to your directory list
518 |
519 | d -a foo
520 |
521 | ###Add /var/log (full path, unexpanded) to your directory list
522 |
523 | d -a /var/log
524 |
525 | ###Add a frequently used Maven (mvn) command to the menu and use the menu to run it.
526 |
527 | The command is `mvn -DskipTests -o install` and we are adding the whole thing using the `ma` command.
528 |
529 |
530 |
531 | `mvn` is a popular build tool. You can see where it begins to run with the line "[INFO] Scanning for projects...
532 |
533 | ###Re-run that command without looking at the menu, now that you know the number
534 |
535 |
536 |
537 | *You could also run the command in your shell, then use the `ma` command to capture the command to your command list in your current space. The ma command will take a command-line as its arguments. With no arguments, the ma command grabs the last item on your history. Note that you need to read the output of the ma command to see the index of the new command, in this case, the number `4`.*
538 |
539 | ```
540 | mvn -DskipTests -o install
541 | ma
542 | m 4
543 | ```
544 |
545 |
546 |
547 |
--------------------------------------------------------------------------------
/tests/restreplay/markdown-output.html:
--------------------------------------------------------------------------------
1 | Introduction 7 | Getting the source 8 | Optional installation locations 9 | Help in bash-menu 10 | Using bash-menu 11 | Sub-commands 12 | Editing 13 | Using the title command 14 | Examples
15 | 16 |dynamide bash-menu is a menu system for bash which keeps lists of
20 | 21 |You use the menu to select from these lists. Selecting a directory from a menu changes to that directory. Selecting a command from a command menu executes that command. You can use the menu or the command line to add to, remove from, and edit these lists.
28 | 29 |A fancy bash-prompt is also provided, which give you options to display on one line the title, user, host, pwd, and git-status. See Using the title command.
30 | 31 |After you install bash-menu and log in, you'll have a custom prompt, and some new commands:
32 | 33 |On GitHub, mash on the "Download ZIP" button, and extract to ~/.bash-menu, or use wget or curl:
cd ~
48 | curl -o master.zip https://codeload.github.com/dynamide/bash-menu/zip/master
49 | unzip master.zip
50 | mv bash-menu-master/ ~/.bash-menu/
51 |
52 |
53 | Or, checkout bash-menu from GitHub:
54 | 55 | cd ~
56 | git clone https://github.com/dynamide/bash-menu.git .bash-menu
57 |
58 |
59 | or
60 | 61 | cd ~
62 | git clone git@github.com:dynamide/bash-menu.git .bash-menu
63 |
64 |
65 | Then pull in the bash-menu from your bash profile, by sourcing in the bash menu, e.g.
66 | 67 || ~/.bash_profile | 71 |
|---|
| source ~/.bash-menu/.bash_profile | 76 |
You can source with . or source.
All of the shell aliases created by bash-menu are defined in ~/.bash-menu/aliases (or $DYNAMIDE_MENU/aliases). Please review these aliases before launching.
The next time you log in, you'll have a custom prompt, and some new commands. Try the main command d for example.
Here is a sample bash prompt on two lines with current working directory, and git status:
87 | 88 | 89 | 90 |By default, the above check-out will leave you with a new, hidden directory in your home directory, that is, ~/.bash-menu, or something like /home/laramie/.bash-menu/. bash-menu knows about this because it sets DYNAMIDE_MENU in ~/.bash-menu/.bash_profile.
If you checked out to some directory other than ~/.bash-menu, for example ~/.my-menu/ then you need to do two things to connect bash-menu to your shell.
1) Edit this file, on the line where it sets DYNAMIDE_MENU (by default it is DYNAMIDE_MENU=~/.bash-menu), so that bash-menu will know where its home directory is.
| ~/.my-menu/.bash_profile | 103 |
|---|
| DYNAMIDE_MENU=~/.my-menu | 108 |
| ... | 111 |
2) Then, in your ~/.bash_profile source in the bash-menu control file we just edited:
116 | 117 || ~/.bash_profile | 121 |
|---|
| source ~/.my-menu/.bash_profile | 126 |
To see help, run with -h or h which will dump out usage.
d -h
To see help on options:
138 | 139 |d h options
To see all the options and their alternate spellings, see:
142 | 143 |d h aliases
To see the current configuration, see:
146 | 147 |d h info
To get started, just type d at your new prompt. From there you can choose a listed item by typing it's number.
Here is the dynamide bash-menu being used to change to directory 6 on the menu:
155 | 156 | 157 | 158 |Note that it shows you the directory you chose, "/Users/vcrocla/src/dynamide/build/resource_root", and then a quick "ls" of that directory, then it changes to that directory. You can tell because the fancy bash prompt has changed and now shows the current working directory as /Users/vcrocla/src/dynamide/build/resource_root, and the git status in that directory is (master) which means we are on git branch "master" with no pending pulls or pushes.
159 | 160 |From a menus such as the directory menu, you can type another menu option. You can type ? to see the mini-help of sub-commands at this menu.
You can choose options on the command line, and skip the menus. You can also choose some options after you have launched bash-menu and are sitting in a menu, where you are prompted for a choice. If you type a number from the list of choices, you will get that choice. But there are also sub-commands at these menus. These mirror options available on the command line. So you could, for example, launch right into your command menu like this:
168 | 169 |d -m
Or, you could launch the directory menu, then change to the command menu with this sequence:
172 | 173 |d
174 | m
175 |
176 |
177 | This represents typing d at your bash prompt, then typing m at the choose dir> prompt.
The edit sub-command is context-sensitive, and will launch your EDITOR or VISUAL editor to let you edit the correct menu.
Here is an actual example:
182 | 183 | 184 | 185 |The sub-commands take an option form: -h, a single-letter form: h, and a word form: help.
Here are all the sub-command options and their equivalents (-c and -s are completely equivalent):
188 | 189 || option | 193 |cmd | 194 |cmd | 195 |context | 196 |
|---|---|---|---|
| -a | 201 |a | 202 |add | 203 |directory, command | 204 |
| -c | 207 |c | 208 |connect | 209 |directory, command | 210 |
| -d | 213 |d | 214 |list | 215 |command, space | 216 |
| -e | 219 |e | 220 |edit | 221 |* | 222 |
| -h | 225 |h | 226 |help | 227 |* | 228 |
| -i | 231 |i | 232 |info | 233 |* | 234 |
| -l | 237 |l | 238 |list | 239 |command, space | 240 |
| -m | 243 |m | 244 |menu | 245 |directory, space | 246 |
| -s | 249 |s | 250 |space | 251 |directory, command | 252 |
| -x | 255 |x | 256 |delete | 257 |directory, command | 258 |
| -o | 261 |o | 262 |options | 263 |help | 264 |
| -a | 267 |a | 268 |aliases | 269 |help | 270 |
| -i | 273 |i | 274 |info | 275 |help | 276 |
Options or cmd may be used on the command line.
281 | 282 |Options or cmd may be used as sub-commands.
283 | 284 |Help takes subcommands options, aliases, and info, or their alternate names listed above. For example:
d h info
287 |
288 |
289 | On the command line, these options could look like these examples:
290 | 291 |d a # Add to your directory list
292 |
293 | d e # Edit your directory list
294 |
295 | d m # Show your command menu
296 | d -m
297 |
298 | d m e # Edit your command menu
299 | d m -e
300 | d m edit
301 |
302 | d s e # Edit your spaces menu
303 | d s -e
304 | d -s edit
305 | d -s -e
306 | d s edit
307 |
308 |
309 | And so on.
310 | 311 |bash-menu comes with a custom PS1 bash prompt. This prompt can show you:
315 | 316 |To see all the options, type
325 | 326 |title -h
Here is a sample of what setting various options does to your prompt:
329 | 330 | 331 | 332 |In these examples, my user name is "vcrocla", my host is "SFCAML-G2XFD56", which I override with the fake hostname "myhost".
333 | 334 |The title (appears at left of the first line) is any placeholder that reminds you of what this shell was for. If you use -w, or -window, the title is also sent to the shell window's title bar.
335 | 336 |My directory "~/src/tagonomy" is a git repository, and its git status in that directory is (master) which means we are on git branch "master" with no pending pulls or pushes. My directory "~/src/dynamide" is also a git repository, and also is on branch "master".
337 | 338 |You'll also see the numbers of commits ahead/behind if you are not up-to-date. (Thanks to the authors who wrote git-branch-status, listed in our NOTICE file.)
Here is what it looks like when you are ahead:
341 | 342 | 343 | 344 |If you type git status you'll see why:
Here is what it looks like when you are ahead and behind:
349 | 350 | 351 | 352 |If you type git status (I have it aliased to st) you'll see why:
To customize your prompt, call title in your ~/.bash_profile after you source in ~/.bash-menu/.bash_profile:
| ~/.bash_profile | 362 |
|---|
| source ~/.bash-menu/.bash_profile | 367 |
| source ~/.laramie/.bash_profile | 370 |
| ~/.laramie/.bash_profile | 378 |
|---|
| DYNAMIDE_SPACES_LIST=~/.laramie/spaces.laramie.list | 383 |
| title -user -nohost -title Lappy -window | 386 |
You can edit your menus in two ways:
394 | 395 |vi or emacs.For case (2), bash-menu will launch your EDITOR or VISUAL editor on the appropriate file. Just edit, then save normally. Files contain non-blank lines or separators. Separators are three hyphens alone on one line, like this:
401 | 402 |/some/directory/on/dirlist
403 | ---
404 | /other/dirs
405 | /other/dirs/bin
406 |
407 |
408 | | Sub-commands: | 412 |413 | |
|---|---|
| d x | 418 |launches the delete menu for directory lists | 419 |
| d x 3 | 422 |deletes directory list item 3 | 423 |
| d mx | 426 |launches the delete menu for commands | 427 |
| d mx 3 | 430 |deletes command menu item 3 | 431 |
| d m x | 434 |launches the delete menu for commands, using submenu | 435 |
| d ma | 438 |add to the command menu, using command-line | 439 |
| d m a | 442 |add to the command menu, using submenu | 443 |
| d e | 446 |launch EDITOR for directory lists | 447 |
| d m e | 450 |launch EDITOR for the command menu | 451 |
| d s | 454 |launch the space chooser | 455 |
Show your directory menu
463 | 464 |d
465 |
466 |
467 | Show your command menu
468 | 469 |m
470 |
471 |
472 | put shell history item 467 (expanded) into your menu
473 | 474 |d -ma !467
475 |
476 |
477 | put a command into your menu using the alias ma (installed in ~/.bash-menu/aliases)
ma find . -iname '*my-file.*'
480 |
481 |
482 | chose menu item 2 and execute it
483 | 484 |d -m 2
485 |
486 |
487 | chose menu item 2 and execute it
488 | 489 |m 2
490 |
491 |
492 | put a separator into your menu using the special string ---
493 | 494 |ma ---
495 |
496 |
497 | Add ~/zanzibar (expanded) to your directory list
498 | 499 |d -a ~/zanzibar
500 |
501 |
502 | Add ~/zanzibar (NOT expanded) to your directory list
503 | 504 |d -a '~/zanzibar'
505 |
506 |
507 | Add $JAVA_HOME (NOT expanded) to your directory list
508 | 509 |d -a '$JAVA_HOME'
510 |
511 |
512 | Add $JAVA_HOME (expanded) to your directory list
513 | 514 |d -a $JAVA_HOME
515 |
516 |
517 | Choose directory 2 from your directory list
518 | 519 |d 2
520 |
521 |
522 | Add . (expanded using `pwd`) to your directory list
523 | 524 |d -a .
525 |
526 |
527 | Add foo in current directory (expanded using pwd/foo) to your directory list
d -a foo
530 |
531 |
532 | Add /var/log (full path, unexpanded) to your directory list
533 | 534 |d -a /var/log
535 |
536 |
537 | Add a frequently used Maven (mvn) command to the menu and use the menu to run it. The command is
538 | mvn -DskipTests -o install and we are adding the whole thing using the ma command.
mvn is a popular build tool. You can see where it begins to run with the line "[INFO] Scanning for projects...
Re-run that command without looking at the menu, now that you know the number
545 | 546 | 547 | 548 |You could also run the command in your shell, then use the ma command to capture the command to your command list in your current space. The ma command will take a command-line as its arguments. With no arguments, the ma command grabs the last item on your history. Note that you need to read the output of the ma command to see the index of the new command, in this case, the number 4.
mvn -DskipTests -o install
551 | ma
552 | m 4
553 |
554 |
555 |
556 |
--------------------------------------------------------------------------------
/d.bash:
--------------------------------------------------------------------------------
1 | ### Installation:
2 | ### From .bash_profile, do this, which will in turn pull in this file and dependencies:
3 | ### source .bash-menu/.bash_profile #this sets DYNAMIDE_MENU
4 |
5 | #============ Overridable Options ==============================================
6 | DYNAMIDE_SPACES_LIST="$DYNAMIDE_MENU/spaces.list" ## This gets overridden by sourcing, e.g. ~/.laramie/.bash_profile
7 |
8 | DYNAMIDE_DIRLIST_DEFAULT="$DYNAMIDE_MENU/spaces/default/directories.list"
9 |
10 | DYNAMIDE_MENU_LIST="$DYNAMIDE_MENU/spaces/default/menu.list"
11 |
12 | DYNAMIDE_DEBUG_DIRLIST=f ## bash-menu-log() control: f for normal, q for quiet, v for debugging.
13 |
14 | DM_MENUOPTS_SHOWSPACE=t ## always show space as menu item "s"
15 |
16 | DM_MENU_BEFORE=
17 | DM_MENU_AFTER=
18 | #============ Calculated Options ==============================================
19 | DM_MENU_SPACE_NAME= ## Don't set this--it is calculated and available for you.
20 | ## You could, for example put it in your menu like so:
21 | ## DM_MENU_BEFORE=---------------$DM_MENU_SPACE_NAME---------------
22 | #===============================================================================
23 |
24 | if [ -f "$DYNAMIDE_MENU/space.index" ]; then
25 | read DYNAMIDE_MENU_SPACE_INDEX < "$DYNAMIDE_MENU/space.index"
26 | fi
27 |
28 |
29 | function bash-menu-d(){
30 | if [ "$DYNAMIDE_MENU_SPACE_INDEX" != "" ]; then
31 | space -q "$DYNAMIDE_MENU_SPACE_INDEX"
32 | else
33 | echo "Using default space 0"
34 | space -q 0
35 | fi
36 | FILES_LIST=$DYNAMIDE_DIRLIST_LIST
37 | DYNAMIDE_DEBUG_DIRLIST=f
38 | local CHOICE=""
39 | while test $# -gt 0; do
40 | #options: Command-Line
41 | case "$1" in
42 | -h|h|help|--help)
43 | shift
44 | bash-menu-doHelp $*
45 | return
46 | ;;
47 | -v|v)
48 | shift
49 | export DYNAMIDE_DEBUG_DIRLIST=v
50 | ;;
51 | -q|q)
52 | shift
53 | export DYNAMIDE_DEBUG_DIRLIST=q
54 | ;;
55 | -a|a|add)
56 | shift
57 | bash-menu-addToDirlist "$1" "$FILES_LIST"
58 | shift
59 | shift
60 | return
61 | ;;
62 | -c|c|connect|-s|s|space)
63 | shift
64 | space $*
65 | return
66 | ;;
67 | -e|e|-edit)
68 | shift
69 | echo " Edit list: $FILES_LIST"
70 | $EDITOR $FILES_LIST
71 | return
72 | ;;
73 | -em|em)
74 | shift
75 | echo " Edit menu: $DYNAMIDE_MENU_LIST"
76 | $EDITOR $DYNAMIDE_MENU_LIST
77 | return
78 | ;;
79 | -es|es)
80 | shift
81 | echo " Edit spaces: $DYNAMIDE_SPACES_LIST"
82 | $EDITOR $DYNAMIDE_SPACES_LIST
83 | return
84 | ;;
85 | -i|i|info)
86 | shift
87 | bash-menu-showInfo
88 | return
89 | ;;
90 | -l|l|list)
91 | shift
92 | bash-menu-log " Using list: $FILES_LIST"
93 | bash-menu-showList $FILES_LIST
94 | return
95 | ;;
96 | -lm|lm)
97 | shift
98 | bash-menu-showList $DYNAMIDE_MENU_LIST
99 | return
100 | ;;
101 | -ls|ls)
102 | shift
103 | bash-menu-showList $DYNAMIDE_SPACES_LIST
104 | return
105 | ;;
106 | -m|m|menu)
107 | shift
108 | bash-menu-log "Using menu: $DYNAMIDE_MENU_LIST"
109 | bash-menu-menu $*
110 | return
111 | ;;
112 | -ma|ma)
113 | shift
114 | bash-menu-ma $*
115 | return
116 | ;;
117 | -mx|mx)
118 | shift
119 | if [ "$1" != "" ]; then
120 | bash-menu-deleteFromList $DYNAMIDE_MENU_LIST $1
121 | bash-menu-showList "$DYNAMIDE_MENU_LIST"
122 | else
123 | bash-menu-showList "$DYNAMIDE_MENU_LIST"
124 | bash-menu-menu x
125 | fi
126 | return
127 | ;;
128 | -x|x|delete)
129 | DELINDEX=$2
130 | shift
131 | shift
132 | if [ "$DELINDEX" == "" ]; then
133 | bash-menu-showList $FILES_LIST
134 | bash-menu-promptAndDeleteFromDirlist
135 | else
136 | bash-menu-deleteFromList $FILES_LIST $DELINDEX
137 | bash-menu-showList $FILES_LIST
138 | fi
139 | return
140 | ;;
141 | *)
142 | bash-menu-log "Selecting option: $1"
143 | CHOICE=$1
144 | shift
145 | break
146 | ;;
147 | esac
148 | done
149 |
150 | if [ "$CHOICE" == "" ] ; then
151 | bash-menu-showList $FILES_LIST
152 | while true ; do
153 | echo -ne "${DM_PROMPTSTART}choose dir>${DM_END} "
154 | read WHICHDIR
155 | if [ "$WHICHDIR" == "?" ]; then
156 | bash-menu-miniHelp 1
157 | else
158 | break
159 | fi
160 | done
161 | #options: Directory Menu
162 | case "$WHICHDIR" in
163 | -c|c|connect|-s|s|space)
164 | space
165 | return
166 | ;;
167 | -e|e|edit)
168 | echo " Edit directory list: $FILES_LIST"
169 | $EDITOR $FILES_LIST
170 | return
171 | ;;
172 | -h|h|help)
173 | bash-menu-doHelp
174 | return
175 | ;;
176 | -i|i|info)
177 | bash-menu-showInfo
178 | return
179 | ;;
180 | -m|m|menu)
181 | bash-menu-menu
182 | return
183 | ;;
184 | -x|x|delete)
185 | bash-menu-promptAndDeleteFromDirlist
186 | return
187 | ;;
188 | '')
189 | return
190 | ;;
191 | *)
192 | bash-menu-chooseFromList $FILES_LIST $WHICHDIR
193 | return
194 | ;;
195 | esac
196 | else
197 | bash-menu-showList $FILES_LIST $CHOICE
198 | bash-menu-chooseFromList $FILES_LIST $CHOICE
199 | fi
200 | }
201 |
202 | ############## Support Functions ################################
203 |
204 | function bash-menu-miniHelp() {
205 | local DM_UNDERLINE_MENU='\033[04;m'
206 | local DM_BOLD='\033[01;m'
207 | local ST="${DM_NORMAL}${DM_BOLD}${DM_UNDERLINE_MENU}"
208 | local N="${DM_NORMAL}"
209 | local B="${DM_BOLD}${DM_UNDERLINE_MENU}"
210 | local SP=`bash-menu-showSpaceLine`
211 | local SPACE="${N}[$SP${N}]${DM_END}"
212 | case "$1" in
213 | 1)
214 | #directory
215 | echo -e " ${ST}c${N}onnect ${B}e${N}dit ${B}h${N}elp ${B}i${N}nfo ${B}m${N}enu ${ST}s${N}pace${SPACE} ${ST}x${N}|${B}d${N}elete${DM_END}"
216 | return
217 | ;;
218 | 2)
219 | #menu
220 | echo -e " ${ST}a${N}dd ${ST}c${N}onnect ${B}e${N}dit ${B}h${N}elp ${B}i${N}nfo ${ST}l${N}ist ${ST}s${N}pace${SPACE} ${ST}x${N}|${B}d${N}elete${DM_END}"
221 | return
222 | ;;
223 | 3)
224 | #space
225 | echo -e " ${B}e${N}dit ${B}h${N}elp ${B}i${N}nfo ${ST}l${N}ist ${B}m${N}enu ${DM_END}"
226 | return
227 | ;;
228 | '')
229 | return
230 | ;;
231 | esac
232 | }
233 |
234 | function bash-menu-doHelp() {
235 | if [ "$#" != "0" ]; then
236 | #options: Help Menu Sub-options
237 | case "$1" in
238 | -a|a|aliases)
239 | bash-menu-showAliases
240 | return
241 | ;;
242 | -i|i|info)
243 | bash-menu-showInfo
244 | return
245 | ;;
246 | -o|o|options)
247 | bash-menu-showOptions
248 | return
249 | ;;
250 | '')
251 | ;;
252 | *)
253 | echo "help option not found: '$1'. Showing help main topic."
254 | esac
255 | fi
256 | echo "Usage: "
257 | echo " Change to a directory in $FILES_LIST"
258 | echo " Run a command in $DYNAMIDE_MENU_LIST"
259 | echo " Choose a space in $DYNAMIDE_SPACES_LIST"
260 | echo
261 | echo "Options: "
262 | echo " d display the directory list for choice"
263 | echo " d {number} cd to the numbered directory"
264 | echo " d -a {dirname} add a directory to the list"
265 | echo " d -c connect to another space"
266 | echo " ALIASES: -c, c, connect, -s, s, space"
267 | echo " d -x show the delete menu"
268 | echo " d -x {number} delete numbered directory"
269 | echo " d -e edit the directory menu"
270 | echo " ALIASES: -e, e, edit"
271 | echo " d -em edit the command menu"
272 | echo " d -es edit the spaces menu"
273 | echo " d -i information"
274 | echo " d -l list the directory list"
275 | echo " d -lm list the command menu list"
276 | echo " d -ls list the spaces list"
277 | echo " d -m show command menu"
278 | echo " d -ma add the last shell command to menu"
279 | echo " d -ma {command} add a command line (spaces OK) to menu"
280 | echo " d -v ... turn on debugging, exec other flags"
281 | echo " d -q ... only print required information to stdout, exec other flags"
282 | echo " d -h [topic] show help. Optional topics: info, options, aliases "
283 | echo " ALIASES: -h, h, help"
284 | echo
285 | echo " d help options show more help on how to use options"
286 | echo " d help aliases show all option aliases"
287 | echo
288 | echo " Documentation: https://github.com/dynamide/bash-menu/blob/master/README.md"
289 | echo " Homepage: http://dynamide.org/bash-menu"
290 | echo " Copyright: (c) 2015 Laramie Crocker"
291 |
292 | }
293 |
294 | function bash-menu-showInfo(){
295 | echo "info - current config:"
296 | echo " \$DYNAMIDE_MENU: $DYNAMIDE_MENU"
297 | echo " \$DYNAMIDE_MENU_SPACE_INDEX: $DYNAMIDE_MENU_SPACE_INDEX"
298 | echo " \$DYNAMIDE_SPACES_LIST: $DYNAMIDE_SPACES_LIST"
299 | echo " \$DYNAMIDE_DIRLIST_DEFAULT: $DYNAMIDE_DIRLIST_DEFAULT"
300 | echo " \$DYNAMIDE_DIRLIST_LIST: $DYNAMIDE_DIRLIST_LIST"
301 | echo " ==>"
302 | echo " Using files list: $FILES_LIST"
303 | echo " Using menu list: $DYNAMIDE_MENU_LIST"
304 | }
305 |
306 | function bash-menu-showOptions() {
307 | echo "info - options and aliases"
308 | echo
309 | echo " Options can use the hyphenated, short, or long forms on the command-line:"
310 | echo " d -h options"
311 | echo " d h o"
312 | echo " d help options"
313 | echo " d m e #Launches your EDITOR on the command menu list"
314 | echo " d a /var/myDir #Adds /var/myDir to the directory list"
315 | echo " and in sub-menus (here > means hit the ENTER key) :"
316 | echo " d > m > e"
317 | echo " d > h > o"
318 | echo
319 | echo " You can go back and forth from the m list to the s list to the l or m lists, and so on:"
320 | echo " d > m > s > m > l"
321 | echo
322 | echo " To see all option aliases, type either of these: "
323 | echo " d h a"
324 | echo " d help aliases"
325 | }
326 |
327 | function bash-menu-showAliases() {
328 | echo "info - option aliases"
329 | echo
330 | echo " Synonyms: "
331 | echo " connect = space"
332 | echo " d = list"
333 | echo
334 | echo " All option aliases are shown below, grepped from the source."
335 | echo " Each option is separated from its aliases by the pipe character: |"
336 | echo
337 | cat $DYNAMIDE_MENU/options-doco
338 | }
339 |
340 | function bash-menu-showSpaceLine() {
341 | local SHOWINDEX=$1
342 | local DM_BOLD='\033[01;m'
343 | local line=`bash-menu-getFromList $DYNAMIDE_SPACES_LIST $DYNAMIDE_MENU_SPACE_INDEX`
344 | regex=".*/spaces/(.*)"
345 | [[ $line =~ $regex ]]
346 | name="${BASH_REMATCH[1]}"
347 | local IDX=''
348 | local SPNUM=''
349 | if [ "$SHOWINDEX" == "t" ]; then
350 | IDX=" ${DM_ADDLINE}s: ${DM_END}"
351 | SPNUM=" ${DM_BOLD}[$DYNAMIDE_MENU_SPACE_INDEX]${DM_END}"
352 | echo -e "${IDX}${DM_BOLD}${name}${DM_END}${SPNUM}"
353 | else
354 | echo -ne "${DM_BOLD}${name}${DM_END}"
355 | fi
356 | }
357 |
358 | function bash-menu-log() {
359 | if [ "$DYNAMIDE_DEBUG_DIRLIST" == "v" ]; then
360 | echo "$1"
361 | fi
362 | }
363 |
364 | function bash-menu-underlineMsg() {
365 | if [ "$1" == "-f" ];then
366 | shift
367 | else
368 | if [ "$DYNAMIDE_DEBUG_DIRLIST" == "q" ]; then
369 | return
370 | fi
371 | fi
372 | echo -en "${DM_UNDERLINE}"
373 | echo "$1"
374 | echo -en "${DM_END}"
375 | }
376 |
377 | function bash-menu-showList() {
378 | DM_MENU_SPACE_NAME=`bash-menu-showSpaceLine`
379 | local BEFORE=`eval "echo $DM_MENU_BEFORE"`
380 | if [ -n "$BEFORE" ]; then
381 | echo -e "$BEFORE"
382 | fi
383 | if [ "$DYNAMIDE_DEBUG_DIRLIST" == "q" ]; then
384 | return
385 | fi
386 | if [ "${DM_MENUOPTS_SHOWSPACE}" == "t" ]; then
387 | bash-menu-showSpaceLine t
388 | fi
389 | unset FILES[@]
390 | local FILES_LIST=$1
391 | local SHOW_INDEX=$2
392 |
393 | local i=0
394 | while read line; do
395 | FILES[i]="$line"
396 | ((i++))
397 | done < "$FILES_LIST"
398 |
399 | if [ "$SHOW_INDEX" == "LAST" ] ; then
400 | ((SHOW_INDEX=$i-1 ))
401 | fi
402 |
403 | #first blank line: echo
404 | local COUNTER=0
405 | local L=0
406 | while [ $COUNTER -lt ${#FILES[@]} ]; do
407 | local file="${FILES[$COUNTER]}"
408 | if [ "$file" != "" ] ; then
409 | if [ "${file:0:3}" == "---" ] ; then
410 | if [ "${file:3}" != "" ] ; then
411 | echo "NOOP" > /dev/null
412 | echo -e " ${DM_LINENUM}${file:3}${DM_END}"
413 | else
414 | echo
415 | fi
416 | else
417 | if [ "$COUNTER" == "$SHOW_INDEX" ] ; then
418 | echo -e " ${DM_ADDLINE}$L: ${DM_ADDLINE_TEXT}$file ${DM_END}"
419 | else
420 | echo -e " ${DM_LINENUM}$L: ${DM_LINETEXT}$file ${DM_END}"
421 | fi
422 | ((L++))
423 | fi
424 | else
425 | echo " $COUNTER: WARNING: blank link in menu file: $FILES_LIST"
426 | ((L++))
427 | fi
428 | ((COUNTER++))
429 | done
430 |
431 | if [ "$DM_MENU_AFTER" != "" ]; then
432 |
433 | local AFTER=`eval "echo $DM_MENU_AFTER"`
434 | echo "$AFTER"
435 | fi
436 | }
437 |
438 | function bash-menu-chooseFromList() {
439 | local FILES_LIST=$1
440 | local SHOW_INDEX=$2
441 | local L=0
442 | while read file; do
443 | if [ "$file" != "" ]; then
444 | if [ "${file:0:3}" != "---" ] ; then
445 | if [ "$L" == "$SHOW_INDEX" ] ; then
446 |
447 | local STR=`echo $file`
448 | local filename=$(eval "echo $STR")
449 | if [ "$file" != "$filename" ]; then
450 | bash-menu-log "Expanding $file -> $filename"
451 | fi
452 |
453 | if [ -e "$filename" ] ; then
454 | bash-menu-underlineMsg "$filename"
455 | if [ "$DYNAMIDE_DEBUG_DIRLIST" == "q" ]; then
456 | builtin cd "$filename"
457 | else
458 | bash-menu-log "Changing dir to $filename"
459 | cd "$filename"
460 | fi
461 | else
462 | echo -n "File does not exist: "
463 | bash-menu-underlineMsg -f "$filename"
464 | fi
465 | return
466 | fi
467 | ((L++))
468 | fi
469 | fi
470 | done < "$FILES_LIST"
471 | echo
472 | }
473 |
474 | function bash-menu-addToDirlist() {
475 | NEWDIR=$1
476 | FILES_LIST=$2
477 |
478 | if [ "$NEWDIR" == "" ] || [ "$NEWDIR" == "." ]; then
479 | NEWDIR=`pwd`
480 | else
481 | if [ "${NEWDIR:0:3}" != "---" ]; then
482 | local FULLPATH=`echo -n "$(builtin cd "$(dirname "$NEWDIR")"; pwd)/$(basename "$NEWDIR")"`
483 | if [ -d "$FULLPATH" ]; then
484 | NEWDIR="$FULLPATH"
485 | else
486 | FULLPATH="`pwd`/$NEWDIR"
487 | if [ ! -d "$FULLPATH" ]; then
488 | echo "WARNING: Adding directory without expansion: '$1'"
489 | else
490 | NEWDIR="$FULLLPATH"
491 | fi
492 | fi
493 | fi
494 | fi
495 | echo "$NEWDIR">>$FILES_LIST
496 | bash-menu-showList $FILES_LIST "LAST"
497 | }
498 |
499 | function bash-menu-promptAndDeleteFromDirlist() {
500 | echo -ne "${DM_PROMPTSTART}choose index to delete>${DM_END} "
501 | read DELINDEX
502 | bash-menu-deleteFromList $FILES_LIST $DELINDEX
503 | bash-menu-showList $FILES_LIST
504 | }
505 |
506 | function bash-menu-deleteFromList() {
507 | local DIRLIST=$1
508 | local DEL_INDEX=$2
509 | if [ "$DEL_INDEX" == "" ]; then
510 | bash-menu-log "NOT deleting, since index was not specified"
511 | return
512 | fi
513 | local TS=`date +%H%M`
514 | cp $DIRLIST "$DIRLIST.bak.$TS"
515 | bash-menu-log "Backup file created: $DIRLIST.bak.$TS"
516 | local L=0
517 | while read line; do
518 | if [ "$line" != "" ]; then
519 | if [ "$L" == "$DEL_INDEX" ] ; then
520 | bash-menu-log "[$L]: removing $line"
521 | ## removing $file by not writing it out here.
522 | echo -e "\n ${DM_ADDLINE}$L: ${DM_ADDLINE_TEXT}$line ${DM_END}"
523 | else
524 | bash-menu-log "[$L]: preserving $line"
525 | echo "$line" >> "$DIRLIST.tmp"
526 | fi
527 | if [ "${line:0:3}" != "---" ]; then
528 | ((L++))
529 | fi
530 | fi
531 | done < "$DIRLIST"
532 | mv "$DIRLIST.tmp" "$DIRLIST"
533 | }
534 |
535 | function bash-menu-getFromList() {
536 | local DIRLIST=$1
537 | local FIND_INDEX=$2
538 | local BARE=$3
539 | if [ "$FIND_INDEX" == "" ]; then
540 | return 1
541 | fi
542 | local L=0
543 | while read line; do
544 | if [ "$line" != "" ]; then
545 | if [ "${line:0:3}" != "---" ]; then
546 | if [ "$L" == "$FIND_INDEX" ] ; then
547 | if [ "$BARE" == "bare" ]; then
548 | echo "$line"
549 | else
550 | echo "[$L]: $line"
551 | fi
552 | fi
553 | ((L++))
554 | fi
555 | fi
556 | done < "$DIRLIST"
557 | }
558 |
559 |
560 | # arg1 : menu item index
561 | # arg2 : command being run
562 | function bash-menu-logCommandRun() {
563 | case "$DYNAMIDE_DEBUG_DIRLIST" in
564 | v)
565 | local iid=$1
566 | shift
567 | echo -n "Running menu item[$iid]: "; bash-menu-underlineMsg "$*"
568 | ;;
569 | q)
570 | ;;
571 | f)
572 | shift
573 | bash-menu-underlineMsg "$*"
574 | ;;
575 | esac
576 | }
577 |
578 | function bash-menu-ma() {
579 | local CDCMD=''
580 | echo "1: -$1- all: $* -"
581 | if [ "$1" == "-cd" ]; then
582 | shift
583 | CDCMD="cd `pwd`; "
584 | echo "CDCMD: $CDCMD"
585 | fi
586 |
587 | if [ "$1" == "" ]; then
588 | set -x
589 | set -o history
590 | var=$(history -p !-1)
591 | #set +o history
592 | echo " Adding to menu list: $CDCMD$var"
593 | echo "$CDCMD$var">>$DYNAMIDE_MENU_LIST
594 | set +x
595 | bash-menu-showList $DYNAMIDE_MENU_LIST "LAST"
596 | return
597 | fi
598 | local NEWCMD=$*
599 | local MMTMP=`echo "$NEWCMD" | xargs` ##expand the command
600 | echo "$CDCMD$MMTMP">>$DYNAMIDE_MENU_LIST
601 | bash-menu-showList $DYNAMIDE_MENU_LIST "LAST"
602 | }
603 |
604 | function bash-menu-promptAdd() {
605 | echo -ne "${DM_PROMPTSTART}enter command to add>${DM_END} "
606 | read WHICHSPACE
607 | if [ "$WHICHSPACE" == "" ] ; then
608 | return;
609 | fi
610 | bash-menu-ma "$WHICHSPACE"
611 | }
612 |
613 | function bash-menu-menu() {
614 | local WHICHITEM
615 |
616 | if [ "$1" == "" ] ; then
617 | bash-menu-showList "$DYNAMIDE_MENU_LIST"
618 | while true ; do
619 | echo -ne "${DM_PROMPTSTART}choose command>${DM_END} "
620 | read WHICHITEM
621 | if [ "$WHICHITEM" == "?" ]; then
622 | bash-menu-miniHelp 2
623 | else
624 | break
625 | fi
626 | done
627 | if [ "$WHICHITEM" == "" ] ; then
628 | return;
629 | fi
630 | else
631 | WHICHITEM="$*"
632 | shift
633 | fi
634 |
635 | local CMD=$(echo "$WHICHITEM" | awk '{ print $1 }')
636 | local ARGS=$(echo "$WHICHITEM" | awk '{out=$2; for(i=3;i<=NF;i++){out=out" "$i}; print out}') #print everything but the first arg, $1.
637 | #options: Command Menu
638 | case "$CMD" in
639 | -a|a|add)
640 | bash-menu-promptAdd
641 | return
642 | ;;
643 | -c|c|connect|-s|s|space)
644 | space "$ARGS"
645 | return
646 | ;;
647 | -em|e|edit)
648 | echo " Edit menu: $DYNAMIDE_MENU_LIST"
649 | $EDITOR $DYNAMIDE_MENU_LIST
650 | return
651 | ;;
652 | -d|d|list|-l|l|list)
653 | bash-menu-d
654 | return
655 | ;;
656 | -h|help)
657 | bash-menu-doHelp "$ARGS"
658 | return
659 | ;;
660 | -i|i|info)
661 | bash-menu-showInfo
662 | return
663 | ;;
664 | -x|x|delete)
665 | echo -ne "${DM_PROMPTSTART}choose index to delete>${DM_END} "
666 | read DELINDEX
667 | bash-menu-deleteFromList $DYNAMIDE_MENU_LIST $DELINDEX
668 | bash-menu-showList "$DYNAMIDE_MENU_LIST"
669 | return
670 | ;;
671 | esac
672 |
673 | if [[ $WHICHITEM =~ ^-?[0-9]+$ ]] ; then # WHICH_ITEM is an integer.
674 | local L=0
675 | while read line; do
676 | if [ "$line" != "" ] && [ "${line:0:3}" != "---" ] ; then
677 | if [ "$L" == "$WHICHITEM" ] ; then
678 | bash-menu-logCommandRun $WHICHITEM $line $*
679 | history -s "$line $*"
680 | eval "$line $*"
681 | return
682 | fi
683 | ((L++))
684 | fi
685 | done < "$DYNAMIDE_MENU_LIST"
686 | fi
687 | }
688 |
689 | function space() {
690 | bash-menu-log "DYNAMIDE_DIRLIST_LIST: $DYNAMIDE_DIRLIST_LIST"
691 | bash-menu-log "DYNAMIDE_SPACES_LIST: $DYNAMIDE_SPACES_LIST"
692 |
693 | if [ "$1" == "-q" ]; then
694 | shift
695 | elif [ "$1" == "" ]; then
696 | bash-menu-showList "$DYNAMIDE_SPACES_LIST" "$DYNAMIDE_MENU_SPACE_INDEX"
697 | fi
698 |
699 | if [ "$1" == "" ] ; then
700 | while true ; do
701 | echo -ne "${DM_PROMPTSTART}choose space>${DM_END} "
702 | read WHICHSPACE
703 | if [ "$WHICHSPACE" == "?" ]; then
704 | bash-menu-miniHelp 3
705 | else
706 | break
707 | fi
708 | done
709 | if [ "$WHICHSPACE" == "" ] ; then
710 | return;
711 | fi
712 | else
713 | WHICHSPACE=$1
714 | fi
715 |
716 | local CMD=$(echo "$WHICHSPACE" | awk '{ print $1 }')
717 | #local ARGS=$(echo "$WHICHSPACE" | awk '{$1=""; print $0}') #print everything but the first arg, $1, but with a whitespace in front.
718 | local ARGS=$(echo "$*" | awk '{out=$2; for(i=3;i<=NF;i++){out=out" "$i}; print out}') #print everything but the first arg, $1.
719 | #options: Space Menu
720 | case "$CMD" in
721 | -h|h|help)
722 | bash-menu-doHelp "$ARGS"
723 | return
724 | ;;
725 | -es|e|edit)
726 | echo " Edit space: $DYNAMIDE_SPACES_LIST"
727 | $EDITOR $DYNAMIDE_SPACES_LIST
728 | return
729 | ;;
730 | -m|m|menu)
731 | bash-menu-menu "$ARGS"
732 | return
733 | ;;
734 | -d|d|list|-l|l|list)
735 | bash-menu-d
736 | return
737 | ;;
738 | -i|i|info)
739 | bash-menu-showInfo
740 | return
741 | ;;
742 | esac
743 |
744 | if [[ $WHICHSPACE =~ ^-?[0-9]+$ ]] ; then # WHICHSPACE is an integer.
745 | local L=0
746 | while read line; do
747 | if [ "$line" != "" ] ; then
748 | if [ "${line:0:3}" == "---" ] ; then
749 | bash-menu-log "separator"
750 | else
751 | if [ "$L" == "$WHICHSPACE" ] ; then
752 | local STR=`echo $line`
753 | local filename=$(eval "echo $STR")
754 | if [ "$line" != "$filename" ]; then
755 | bash-menu-log "Expanding $line -> $filename"
756 | fi
757 | if [ -e "$filename" ] ; then
758 | export DYNAMIDE_DIRLIST_LIST="$filename/directories.list"
759 | export DYNAMIDE_MENU_LIST="$filename/menu.list"
760 | bash-menu-log "Changing to space[$WHICHSPACE] $filename"
761 | echo "$WHICHSPACE" > "$DYNAMIDE_MENU/space.index"
762 | export DYNAMIDE_MENU_SPACE_INDEX="$WHICHSPACE"
763 | return
764 | else
765 | echo "Space file does not exist: $filename"
766 | fi
767 | fi
768 | ((L++))
769 | fi
770 | fi
771 | done < "$DYNAMIDE_SPACES_LIST"
772 | fi
773 | }
774 |
775 |
--------------------------------------------------------------------------------