├── .gitignore ├── spaces.list ├── make-options-doco ├── spaces └── default │ ├── directories.list │ └── menu.list ├── ack-ignore-dirs ├── bash-menu.workflow ├── tests ├── restreplay │ ├── run-markdown-api │ ├── testing.workflow │ ├── githubapi │ │ ├── markdown.xml │ │ └── q │ │ │ └── README.md │ └── markdown-output.html └── test-title.bash ├── menu.js ├── NOTICE ├── options-doco ├── catall ├── .bash_profile ├── colors.bash ├── aliases ├── functions.bash ├── git-branch-status ├── ps1.bash ├── LICENSE ├── README.md └── d.bash /.gitignore: -------------------------------------------------------------------------------- 1 | space.index 2 | .d.bash.marks -------------------------------------------------------------------------------- /spaces.list: -------------------------------------------------------------------------------- 1 | $DYNAMIDE_MENU/spaces/default 2 | -------------------------------------------------------------------------------- /make-options-doco: -------------------------------------------------------------------------------- 1 | grep '^ *-\|\#options:' ./d.bash > options-doco 2 | cat options-doco -------------------------------------------------------------------------------- /spaces/default/directories.list: -------------------------------------------------------------------------------- 1 | /tmp 2 | /var/log 3 | ~/bin 4 | --- 5 | $HOME/.m2 6 | $DYNAMIDE_HOME/bin 7 | $DYNAMIDE_MENU 8 | -------------------------------------------------------------------------------- /spaces/default/menu.list: -------------------------------------------------------------------------------- 1 | hostname 2 | pwd 3 | date 4 | ls -la 5 | --- 6 | mvn -DskipTests -o install 7 | ls $DYNAMIDE_HOME 8 | -------------------------------------------------------------------------------- /ack-ignore-dirs: -------------------------------------------------------------------------------- 1 | ##NOTE: you can show just filenames only using the switch -l 2 | ## e.g. ack -l foo 3 | export ACK_IGNORE_DIRS=' --ignore-dir=.idea --ignore-dir=dist --ignore-dir=app/bower_components --ignore-dir=.idea' -------------------------------------------------------------------------------- /bash-menu.workflow: -------------------------------------------------------------------------------- 1 | Generate doco: 2 | options and their aliases are documented by grepping for them: 3 | ./make-options-doco 4 | which generates 5 | ./options-doco 6 | 7 | Update the TOC on dynamide.org: 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/restreplay/run-markdown-api: -------------------------------------------------------------------------------- 1 | #long options: restreplay -testdir . -control githubapi/markdown.xml -testGroup main -test markdown 2 | 3 | pushd ~/.bash-menu/tests/restreplay 4 | 5 | restreplay -d . -c githubapi/markdown.xml -g main -t markdown 6 | -------------------------------------------------------------------------------- /menu.js: -------------------------------------------------------------------------------- 1 | var sys = require('sys') 2 | 3 | var exec = require('child_process').exec; 4 | 5 | function puts(error, stdout, stderr) { sys.puts(stdout) } 6 | 7 | exec("ls -la", puts); 8 | 9 | exports.world = function() { 10 | console.log('Hello World'); 11 | } 12 | -------------------------------------------------------------------------------- /tests/test-title.bash: -------------------------------------------------------------------------------- 1 | title 2 | title -host 3 | title -host -user 4 | title -host myhost -user 5 | title -host myhost -user -title Title1 6 | title -user -host myhost -title Title2 7 | title -host myhost -user -window 8 | title -host myhost -user -window -title Title3 9 | title -title Title5 -host myhost -user -window 10 | title -title Title5 -host myhost -user FooUser -window 11 | title -clear 12 | title -host -window 13 | title -h 14 | title -clear 15 | -------------------------------------------------------------------------------- /tests/restreplay/testing.workflow: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ================================================================================ 5 | Use RestReplay to hit the github API to render our README.md file 6 | ================================================================================ 7 | 2015-02-20 8 | pushd ~/.bash-menu/tests/restreplay 9 | 10 | restreplay -d . -c githubapi/markdown.xml -g main -t markdown 11 | 12 | 13 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | NOTICE 2 | ============================ 3 | 4 | Some files and ideas came from public sources. 5 | 6 | git-branch-status :: 7 | 8 | hosted at https://gist.github.com/Mark-Booth/5058384 9 | forked from https://gist.github.com/lth2h/4177524 @ ae184f1 by mark.booth 10 | forked from https://gist.github.com/jehiah/1288596 @ e357c1e by lth2h 11 | ideas from https://github.com/kortina/bakpak/blob/master/bin/git-branches-vs-origin-master 12 | 13 | Not much code, but some ideas came from this: 14 | 15 | https://github.com/necolas/dotfiles 16 | 17 | Similarly, some ideas from here: 18 | 19 | https://github.com/jondavidjohn/dotfiles/blob/aad34fe2b41d12d7796f7c0deb8ecf8296015e6e/general/.bash_profile#L101-L121 20 | 21 | -------------------------------------------------------------------------------- /tests/restreplay/githubapi/markdown.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | bGFyYW1pZTpPZmZUb0dpdER5bmFtaWRl 5 | 6 | 7 | 8 | POST 9 | 10 |
text/x-markdown
11 |
application/vnd.github.v3+json
12 |
13 | https://api.github.com/markdown/raw 14 | githubapi/q/README.md 15 | 16 | 20 | 21 |
22 |
23 |
24 | -------------------------------------------------------------------------------- /options-doco: -------------------------------------------------------------------------------- 1 | #options: Command-Line 2 | -h|h|help|--help) 3 | -v|v) 4 | -q|q) 5 | -a|a|add) 6 | -c|c|connect) 7 | -s|s|space) 8 | -e|e|-edit) 9 | -em|em) 10 | -es|es) 11 | -i|i|info) 12 | -l|l|list) 13 | -lm|lm) 14 | -ls|ls) 15 | -m|m|menu) 16 | -ma|ma) 17 | -mx|mx) 18 | -x|x|delete) 19 | #options: Directory Menu 20 | -c|c|connect 21 | -s|s|space) 22 | -e|e|edit) 23 | -h|h|help) 24 | -i|i|info) 25 | -m|m|menu) 26 | -x|x|delete) 27 | #options: Help Menu Sub-options 28 | -a|a|aliases) 29 | -i|i|info) 30 | -o|o|options) 31 | #options: Command Menu 32 | -a|a|add) 33 | -c|c|connect) 34 | -s|s|space) 35 | -em|e|edit) 36 | -d|d|list) 37 | -l|l|list) 38 | -h|help) 39 | -i|i|info) 40 | -x|x|delete) 41 | #options: Space Menu 42 | -h|h|help) 43 | -es|e|edit) 44 | -m|m|menu) 45 | -d|d|list) 46 | -l|l|list) 47 | -i|i|info) 48 | -------------------------------------------------------------------------------- /catall: -------------------------------------------------------------------------------- 1 | case "$1" in 2 | -h|--h|--help) 3 | shift 4 | echo "Usage: catall [-n] {directory}" 5 | echo " Prints out n lines for all text files in a directory." 6 | exit 7 | esac 8 | 9 | LIMIT= 10 | if [ "$1" == "-n" ]; then 11 | shift 12 | LIMIT="$1" 13 | shift 14 | fi 15 | 16 | DM_CATALL_BASENAME="" 17 | 18 | if [ -d "$*" ]; then 19 | DM_CATALL_BASENAME="$*" 20 | fi 21 | 22 | 23 | for thefile in `ls $*` 24 | do 25 | if [ "$DM_CATALL_BASENAME" != "" ]; then 26 | thefile="$DM_CATALL_BASENAME/$thefile" 27 | fi 28 | T=`file -b $thefile |grep text` 29 | if [ "$T" != "" ] ; then 30 | if [ -f "$thefile" ] ; then 31 | if [ "$LIMIT" != "" ]; then 32 | echo -e "\033[01;32;40m======================== $thefile ==========[$LIMIT lines]====================\033[0m " 33 | head -n "$LIMIT" "$thefile" 34 | echo "..." 35 | else 36 | echo -e "\033[01;32;40m======================== $thefile ==============================\033[0m " 37 | cat "$thefile" 38 | fi 39 | fi 40 | fi 41 | done -------------------------------------------------------------------------------- /.bash_profile: -------------------------------------------------------------------------------- 1 | export DYNAMIDE_MENU=~/.bash-menu 2 | 3 | source $DYNAMIDE_MENU/colors.bash 4 | source $DYNAMIDE_MENU/functions.bash 5 | source $DYNAMIDE_MENU/aliases 6 | source $DYNAMIDE_MENU/d.bash 7 | source $DYNAMIDE_MENU/ps1.bash 8 | title -u -host 9 | 10 | #=========================================================== 11 | # You can customize bash-menu by overriding these here, 12 | # or in your own .bash_profile *after* sourcing this file. 13 | #=========================================================== 14 | 15 | #You can insert a blank line before your menus with this: 16 | DM_MENU_BEFORE=' ' 17 | #You can insert a blank line after your menus with this: 18 | DM_MENU_AFTER=' ' 19 | #You can also define a line of text for before and after. (note: \n won't work). 20 | DM_MENU_BEFORE='----------------------------------$DM_MENU_SPACE_NAME------------' 21 | DM_MENU_AFTER='---------------------------------------------------' 22 | #You can override both by setting to null: 23 | DM_MENU_BEFORE= 24 | DM_MENU_AFTER= 25 | 26 | #Show the current space as the first item in the menu ( =t to show, =f to override) 27 | DM_MENUOPTS_SHOWSPACE=f 28 | -------------------------------------------------------------------------------- /colors.bash: -------------------------------------------------------------------------------- 1 | # \033[ATTRIBUTE;TEXT;BACKGROUNDm 2 | export DM_END='\033[0m' 3 | export DM_PROMPTSTART='\033[1;m' 4 | export DM_UNDERLINE='\033[04;35m' 5 | export DM_ADDLINE='\033[1;34m' 6 | export DM_ADDLINE_TEXT='\033[01;34m' 7 | export DM_LINENUM='\033[1;32m' 8 | export DM_LINETEXT='\033[1;33m' 9 | export DM_REVERSE='\033[07;33m' 10 | export DM_BOLD='\033[01;33m' 11 | export DM_NORMAL='\033[00;33m' 12 | 13 | 14 | 15 | 16 | 17 | ########################## bash color codes #################################### 18 | # Attribute codes: 19 | # 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed 20 | # 21 | # Text color codes: 22 | # 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white 23 | # 24 | # Background color codes: 25 | # 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white 26 | # 27 | # In the example above, me used the ANSI escape sequence 28 | # \e[attribute code;text color codem 29 | # to display a blue text. Therefore, we have to use -e option in calling echo to escape the input. 30 | # Note that the color effect had to be ended by 31 | # \e[0m 32 | # 33 | # To have a background, we must use the background color codes. 34 | # The sequence then becomes \e[attribute code;text color code;background color codem. 35 | 36 | -------------------------------------------------------------------------------- /aliases: -------------------------------------------------------------------------------- 1 | HISTCONTROL="erasedups" 2 | 3 | theUname=`uname -s` 4 | regex=".*(Darwin).*" 5 | [[ $theUname =~ $regex ]] 6 | name="${BASH_REMATCH[1]}" 7 | if [ "$name" != "" ]; then 8 | alias ls='CLICOLOR_FORCE=1 /bin/ls -GF' 9 | alias lat='CLICOLOR_FORCE=1 /bin/ls -latG|less -R' 10 | alias dir='CLICOLOR_FORCE=1 /bin/ls -loaTGF' 11 | alias dirt='{ echo "======Newest Files First==========" && CLICOLOR_FORCE=1 /bin/ls -loaTtGF; } | less -R '; 12 | else 13 | alias lat='CLICOLOR_FORCE=1 /bin/ls -latG --color|less -R' 14 | alias dir='CLICOLOR_FORCE=1 /bin/ls -loa --color' 15 | alias dirt='{ echo "======Newest Files First==========" && CLICOLOR_FORCE=1 /bin/ls -loa --color; } | less -R '; 16 | fi 17 | 18 | alias ci='git commit' 19 | alias co='git checkout' 20 | alias st='git status' 21 | alias h='history|grep ' 22 | alias o='open' 23 | alias catall='$DYNAMIDE_MENU/catall' 24 | 25 | source $DYNAMIDE_MENU/ack-ignore-dirs 26 | alias ack='ack $ACK_IGNORE_DIRS' 27 | 28 | #export LSCOLORS='gxfxcxdxbxegedabagacad' 29 | export LSCOLORS='Exfxcxdxbxegfdabaggcgd' 30 | export GIT_EDITOR=vim 31 | export VISUAL=vim 32 | export EDITOR=vim 33 | 34 | export DYNAMIDE_MENU_DEFAULT_GITBRANCH=develop 35 | 36 | ## bash-menu directory chooser and command menu: 37 | alias d='bash-menu-d' 38 | alias da='bash-menu-d -a' 39 | alias m='bash-menu-d -m' 40 | alias ma='bash-menu-d -ma' 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /functions.bash: -------------------------------------------------------------------------------- 1 | ### NOTE: tab completion is controlled here: ~/.inputrc 2 | ### aliases file, and this file, are pulled in by ~/.bash_profile 3 | ### 4 | ### Installation: 5 | ### from .bash_profile, do: source $DYNAMIDE_MENU/functions.bash 6 | ### from .bash_profile, do: source $DYNAMIDE_MENU/d.bash #My custom directory changer. 7 | 8 | RED="\[\033[0;31m\]" 9 | YELLOW="\[\033[0;33m\]" 10 | GREEN="\[\033[0;32m\]" 11 | NO_COLOR="\[\033[0m\]" 12 | ##BAKBLK='\e[40m' # Black - Background 13 | BAKBLK='\e[44m' # Black - Background ## Laramie 20140604 '\e[44m' is the new '\e[40m' 14 | 15 | function parse_git_branch () { 16 | git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' 17 | } 18 | 19 | function parse_git_status () { 20 | MOJO=`$DYNAMIDE_MENU/git-branch-status -p 2> /dev/null` 21 | if [ -z "$MOJO" ] ; then 22 | FOO="" 23 | else 24 | echo -n " :$MOJO" 25 | fi 26 | } 27 | 28 | ..() { 29 | if [ "$#" == "0" ] ; then cd ..; return 0; fi 30 | for i in $(seq $1); do cd ..; done; 31 | } 32 | 33 | function cd() { 34 | builtin cd $*; 35 | 'ls' -G; 36 | } 37 | 38 | function date() { 39 | /bin/date "$@" 40 | if [ "$#" == "0" ] ; then 41 | echo " CWD: `pwd`" 42 | echo " STAMP: `/bin/date +%Y%m%d`" 43 | ## newline works: /bin/date "+DATE: %Y-%m-%d%nTIME: %l:%M %p %Z" 44 | /bin/date "+ DATE: %Y-%m-%d" 45 | CURR=`/bin/date "+%l:%M %p"` 46 | echo -e " TIME: \033[1;32;40m$CURR \033[0m" 47 | fi 48 | } 49 | 50 | -------------------------------------------------------------------------------- /git-branch-status: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # hosted at https://gist.github.com/Mark-Booth/5058384 3 | # forked from https://gist.github.com/lth2h/4177524 @ ae184f1 by mark.booth 4 | # forked from https://gist.github.com/jehiah/1288596 @ e357c1e by lth2h 5 | # ideas from https://github.com/kortina/bakpak/blob/master/bin/git-branches-vs-origin-master 6 | 7 | # this prints out some branch status 8 | # (similar to the '... ahead' info you get from git status) 9 | 10 | # example: 11 | # $ git branch-status -a 12 | # dns_check (ahead 1) | (behind 112) origin/master 13 | # master (ahead 2) | (behind 0) origin/master 14 | # $ git branch-status 15 | # master (ahead 2) | (behind 0) origin/master 16 | 17 | ## Laramie 20140611 changed master to $DYNAMIDE_MENU_DEFAULT_GITBRANCH . 18 | 19 | usage="$(basename "$0") [-hamv] -- Summarise status of branch(es) 20 | 21 | Where: 22 | -h shows this help text 23 | -a shows all branches, not just the current one 24 | -m shows branch(es) with respect to origin/$DYNAMIDE_MENU_DEFAULT_GITBRANCH 25 | -v verbose, show output even if counts are zero 26 | -b BRANCH shows branch(es) with respect to a given branch 27 | -s FROM/TO shows branch(es) with respect to a branch substitution 28 | Note: Any branches which don't match FROM will be ignored 29 | -l shows only when the left side is ahead 30 | -r shows only when the left side is behind (right is ahead) 31 | -u UPSTREAM selects an upstream other than origin for -b and -m options 32 | 33 | For example 34 | $(basename "$0") -am 35 | $(basename "$0") -s 8.34/8.36" 36 | 37 | while getopts 'hamvb:ps:lru:' option; do 38 | case "$option" in 39 | h) echo "$usage" 40 | exit 41 | ;; 42 | a) filter=refs/heads 43 | ;; 44 | p) ps1format=true 45 | ;; 46 | m) upstreambranch=$DYNAMIDE_MENU_DEFAULT_GITBRANCH 47 | ;; 48 | v) verbose=true 49 | ;; 50 | b) upstreambranch=$OPTARG 51 | ;; 52 | s) remotesubstitute=$OPTARG 53 | ;; 54 | l) aheadonly=true 55 | ;; 56 | r) behindonly=true 57 | ;; 58 | u) upstream=$OPTARG 59 | ;; 60 | :) echo "Option -$OPTARG requires an argument." >&2 61 | echo "$usage" >&2 62 | exit 1 63 | ;; 64 | ?) printf "Invalid option: -$OPTARG" >&2 65 | echo "$usage" >&2 66 | exit 1 67 | ;; 68 | esac 69 | done 70 | shift $((OPTIND - 1)) 71 | 72 | [ $filter ] || filter=$(git symbolic-ref -q HEAD) 73 | [ $upstream ] || upstream=origin 74 | 75 | git for-each-ref --format="%(refname:short) %(upstream:short)" $filter | \ 76 | while read local remote 77 | do 78 | if [ $remotesubstitute ] ; then 79 | remote=$(echo $remote | sed "s/${remotesubstitute}/") 80 | elif [ $upstreambranch ] ; then 81 | remote=$upstream/$upstreambranch 82 | fi 83 | [ "$remote" ] || continue 84 | [ "$(git ls-remote . $remote)" ] || continue 85 | DELTAS=$(git rev-list --left-right ${local}...${remote} --) 86 | LEFT_AHEAD=$(echo "$DELTAS" | grep -c '^<') 87 | RIGHT_AHEAD=$(echo "$DELTAS" | grep -c '^>') 88 | if [ $ps1format ] ; then 89 | if [ $LEFT_AHEAD -gt 0 ] || [ $RIGHT_AHEAD -gt 0 ] ; then 90 | echo -n "$LEFT_AHEAD,$RIGHT_AHEAD" 91 | fi 92 | elif [ -z $aheadonly ] && [ -z $behindonly ] ; then 93 | if [ $LEFT_AHEAD -gt 0 ] || [ $RIGHT_AHEAD -gt 0 ] || [ $verbose ] ; then 94 | echo "$local (ahead $LEFT_AHEAD) | (behind $RIGHT_AHEAD) $remote" 95 | fi 96 | elif [ $aheadonly ] ; then 97 | if [ $LEFT_AHEAD -gt 0 ] || [ $verbose ] ; then 98 | echo "$local (ahead $LEFT_AHEAD) | $remote" 99 | fi 100 | elif [ $behindonly ] ; then 101 | if [ $RIGHT_AHEAD -gt 0 ] || [ $verbose ] ; then 102 | echo "$local | (behind $RIGHT_AHEAD) $remote" 103 | fi 104 | else 105 | printf "Specifying both -l and -r makes no sense" >&2 106 | echo "$usage" >&2 107 | exit 1 108 | fi 109 | done 110 | -------------------------------------------------------------------------------- /ps1.bash: -------------------------------------------------------------------------------- 1 | ##export PS1="\[\e]0;\w\a\]\n\[\e[0;92m\e[40m\]\u@\h \[\e[1;95m\]\w\[\e[1;33m\]\$(parse_git_branch)\[\e[0m\]\n\$ " 2 | function setTitle() { 3 | case "$1" in 4 | --help) 5 | echo 6 | echo " title [-user [{username}]|-nouser] [-nohost|-host|-host {myhostname}] [-title {mytitle}] [-window]" 7 | echo " title -clear" 8 | echo 9 | echo " Set the title and optional user and hostname in your bash PS1 prompt." 10 | echo " Options:" 11 | echo " -u, -user - includes user login in prompt" 12 | echo " -u, -user {myusername} - uses the supplied override (for display only)" 13 | echo " -a, -anon, -nouser - excludes user login from prompt" 14 | echo " -h, -host - uses the system hostname" 15 | echo " -h, -host {myhostname} - uses the supplied hostname override" 16 | echo " -n, -nohost - hides display of the hostname" 17 | echo " -n, -window - reports the TITLE to the shell window" 18 | echo " -t, -title {mytitle} - sets a description at the left of the info line" 19 | echo 20 | echo " -clear - clears the PS1 of title, user, and host" 21 | echo 22 | echo " Examples:" 23 | echo " title -t mytitle " 24 | echo -e " - sets the title and removes the user and hostname display\n" 25 | echo " title -host myhost -t mytitle " 26 | echo -e " - sets the title and overrides the hostname with 'myhost'\n" 27 | echo " title -h -t mytitle " 28 | echo -e " - sets the title and uses the system hostname\n" 29 | echo " title -u -h -t mytitle " 30 | echo -e " - sets the title and uses the shell user and system hostname\n" 31 | echo " title -anon -n -t mytitle " 32 | echo -e " - sets the title, no user or hostname (same as title -t mytitle)\n" 33 | echo " title -u myDisplayName -h myhost -title 'My Title'" 34 | echo -e " - sets a long title, overrides the hostname and user\n" 35 | return 36 | ;; 37 | esac 38 | local DYNAMIDE_SHOW_HOST_PS1= 39 | local DYNAMIDE_SHOW_USER_PS1= 40 | TITLE= 41 | SPaCE= 42 | USER_HOST= 43 | DYNAMIDE_TITLE_SESSION= 44 | 45 | if [ "$1" == "-clear" ]; then 46 | shift 47 | DYNAMIDE_SHOW_USER_PS1= 48 | DYNAMIDE_SHOW_HOST_PS1= 49 | TITLE= 50 | SPaCE= 51 | USER_HOST= 52 | fi 53 | 54 | while test $# -gt 0; do 55 | case "$1" in 56 | -u|-user) 57 | shift 58 | if [ "$1" == "" ]; then #no more args. 59 | export DYNAMIDE_SHOW_USER_PS1="\u" 60 | continue 61 | fi 62 | echo "$1" |grep '^-' > /dev/null 63 | if [ "$?" -eq 0 ]; then 64 | export DYNAMIDE_SHOW_USER_PS1='\u' 65 | else 66 | export DYNAMIDE_SHOW_USER_PS1="$1" 67 | shift 68 | fi 69 | ;; 70 | -a|-anon|-nouser) 71 | shift 72 | export DYNAMIDE_SHOW_USER_PS1="" 73 | ;; 74 | -h|-host) 75 | shift 76 | if [ "$1" == "" ]; then 77 | export DYNAMIDE_SHOW_HOST_PS1='\h' 78 | continue 79 | fi 80 | echo "$1" |grep '^-' > /dev/null 81 | if [ "$?" -eq 0 ]; then 82 | export DYNAMIDE_SHOW_HOST_PS1='\h' 83 | else 84 | export DYNAMIDE_SHOW_HOST_PS1="$1" 85 | shift 86 | fi 87 | ;; 88 | -t|-title) 89 | shift 90 | if [ "$1" == "" ]; then 91 | echo "WARNING: -title was specified without an argument" 92 | return 93 | fi 94 | 95 | echo "$1" |grep '^-' > /dev/null 96 | if [ "$?" -eq 0 ]; then 97 | echo "WARNING: -title was specified without an argument, next option found: $1" 98 | else 99 | export TITLE="$1" 100 | shift 101 | fi 102 | ;; 103 | -n|-nohost) 104 | shift 105 | export DYNAMIDE_SHOW_HOST_PS1='' 106 | ;; 107 | -w|-window) 108 | shift 109 | export DYNAMIDE_TITLE_SESSION='\033]0;$TITLE\007' 110 | ;; 111 | *) 112 | echo "Unknown option: $1" 113 | shift 114 | ;; 115 | esac 116 | done 117 | 118 | ##echo "Options set: TITLE $TITLE DYNAMIDE_SHOW_HOST_PS1 $DYNAMIDE_SHOW_HOST_PS1 DYNAMIDE_SHOW_USER_PS1 $DYNAMIDE_SHOW_USER_PS1" 119 | 120 | local USER_HOST= 121 | 122 | if [ "$DYNAMIDE_SHOW_HOST_PS1" != "" ] && [ "$DYNAMIDE_SHOW_USER_PS1" != "" ];then 123 | USER_HOST="$DYNAMIDE_SHOW_USER_PS1@$DYNAMIDE_SHOW_HOST_PS1" 124 | elif [ "$DYNAMIDE_SHOW_USER_PS1" != "" ]; then 125 | USER_HOST="$DYNAMIDE_SHOW_USER_PS1" 126 | elif [ "$DYNAMIDE_SHOW_HOST_PS1" != "" ]; then 127 | USER_HOST="$DYNAMIDE_SHOW_HOST_PS1" 128 | fi 129 | 130 | if [ "$USER_HOST" != "" ];then 131 | USER_HOST="[$USER_HOST]" 132 | fi 133 | 134 | local SPaCE= 135 | if [ "$TITLE" != "" ] && [ "$USER_HOST" != "" ];then 136 | SPaCE=' ' 137 | fi 138 | export PS1="\[\e]0;\w\a\]\n\[\e[0;92m\]\[\e[1;33m\]$TITLE$SPaCE$USER_HOST \[\e[1;95m\]\w\[\e[1;33m\] (\$(parse_git_branch)\[\e[1;34m\]\$(parse_git_status)\e[1;33m\])${DYNAMIDE_TITLE_SESSION}\n$ \[\e[0m\]" 139 | 140 | ##export PS1="\[\e]0;\w\a\]\n\[\e[0;92m\]\[\e[1;33m\]$TITLE$DYNAMIDE_SHOW_HOST_PS1 \[\e[1;95m\]\w\[\e[1;33m\]\$(parse_git_branch)\[\e[0m\]\n\$\033]0;$TITLE\007" 141 | ## The last bit, \033]0;$TITLE\007, exports the title to the shell for reporting in window titles, works with iterm2 if you check "let session report title." 142 | } 143 | 144 | setTitle 145 | alias title='setTitle' 146 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /tests/restreplay/githubapi/q/README.md: -------------------------------------------------------------------------------- 1 | # bash-menu 2 | 3 | 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 `. 58 | 59 | ``` 60 | history 61 | 473 cd /src/myproject 62 | 474 ./ant 63 | 475 cd /var/log/foobar 64 | 476 dir 65 | 477 rm /var/log/foobar/* 66 | 478 /usr/local/bin/restartdb 67 | ``` 68 | 69 | Now just grab the ones you want, then bring up the command list in EDITOR: 70 | 71 | ``` 72 | ma !477 73 | ma !473 74 | ma !474 75 | ma !478 76 | d m e 77 | ``` 78 | 79 | #### Spelunking Workflow 80 | 81 | You work in many directories, and often use paths like `./exec-foo`. To use your history, you need to know which directory you were in. If you `cd` or `pushd` incrementally, your history is not much help here. If you use **bash-menu** to store the path and the command together, you have a re-useable item that is quicker to create than a script, but more reliable than using `history`. 82 | 83 | ``` 84 | cd ~/bin 85 | dir 86 | cd tomcat7.dm 87 | dir 88 | cd conf 89 | vi server.xml 90 | cd .. 91 | bin/startup.sh 92 | ma -cd 93 | ``` 94 | 95 | Now when you type `m` you'll see something like this item at the bottom of your command menu: 96 | 97 | 7: cd /Users/laramie/bin/tomcat7.dm ; bin/startup.sh 98 | 99 | How did that work? Well, the `ma` command has a built-in option `-cd` to add the `cd ...;` for you. It automatically uses the last item on your history if you specify nothing. It is effectively doing this (which you can also type in if you want): 100 | 101 | ``` 102 | ma cd `pwd` \; !! 103 | ``` 104 | 105 | Now, any time you want to start tomcat, just do 106 | 107 | ``` 108 | m 7 109 | ``` 110 | 111 | #### Polyglot Workflow 112 | 113 | Set up each project with scripts and buildfiles in the appropriate directories. Mark these scripts and directories using **bash-menu** in one *space*, using menu separators to group commands by area. The menus serve to remind you where the key build directories are, and the commands you'll need once you are there. 114 | 115 | #### Contractor Workflow 116 | 117 | You work on multiple projects, and have many command-lines, scripts, directories, and builds to remember. Store each project under a `space`, and switch between spaces using **bash-menu**. the command `d s` brings up the space menu from the command-line, and from a **bash-menu** directory or command menu prompt, you can just type `s`. When you change spaces, your directory list and your command menu change. When you are in another terminal or another project, just navigate to the space you want. 118 | 119 | ## Getting the source 120 | 121 | On [GitHub](https://github.com/dynamide/bash-menu), mash on the "Download ZIP" button, and extract to `~/.bash-menu`, or use wget or curl: 122 | 123 | cd ~ 124 | curl -o master.zip https://codeload.github.com/dynamide/bash-menu/zip/master 125 | unzip master.zip 126 | mv bash-menu-master/ ~/.bash-menu/ 127 | 128 | Or, checkout **bash-menu** from GitHub: 129 | 130 | cd ~ 131 | git clone https://github.com/dynamide/bash-menu.git .bash-menu 132 | 133 | or 134 | 135 | cd ~ 136 | git clone git@github.com:dynamide/bash-menu.git .bash-menu 137 | 138 | Then pull in the **bash-menu** from your bash profile, by sourcing in the bash menu, e.g. 139 | 140 | | _~/.bash_profile_ | 141 | | :------------- | 142 | | source ~/.bash-menu/.bash_profile | 143 | 144 | You can source with `.` or `source`. 145 | 146 | 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. 147 | 148 | The next time you log in, you'll have a custom prompt, and some new commands. Try the main command `d` for example. 149 | 150 | Here is a sample bash prompt on two lines with current working directory, and git status: 151 | 152 | 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 |

2 | bash-menu

3 | 4 |

5 | 6 |

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 |

17 | Introduction

18 | 19 |

dynamide bash-menu is a menu system for bash which keeps lists of

20 | 21 | 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 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 | 41 | 42 |

43 | Getting the source

44 | 45 |

On GitHub, mash on the "Download ZIP" button, and extract to ~/.bash-menu, or use wget or curl:

46 | 47 |
 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 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 |
~/.bash_profile
source ~/.bash-menu/.bash_profile
79 | 80 |

You can source with . or source.

81 | 82 |

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.

83 | 84 |

The next time you log in, you'll have a custom prompt, and some new commands. Try the main command d for example.

85 | 86 |

Here is a sample bash prompt on two lines with current working directory, and git status:

87 | 88 |

89 | 90 |

91 | Optional Installation Locations

92 | 93 |

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.

94 | 95 |

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.

96 | 97 |

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.

98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 |
~/.my-menu/.bash_profile
DYNAMIDE_MENU=~/.my-menu
...
114 | 115 |

2) Then, in your ~/.bash_profile source in the bash-menu control file we just edited:

116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 |
~/.bash_profile
source ~/.my-menu/.bash_profile
129 | 130 |

131 | Help in bash-menu

132 | 133 |

To see help, run with -h or h which will dump out usage.

134 | 135 |

d -h

136 | 137 |

To see help on options:

138 | 139 |

d h options

140 | 141 |

To see all the options and their alternate spellings, see:

142 | 143 |

d h aliases

144 | 145 |

To see the current configuration, see:

146 | 147 |

d h info

148 | 149 |

150 | Using bash-menu

151 | 152 |

To get started, just type d at your new prompt. From there you can choose a listed item by typing it's number.

153 | 154 |

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.

161 | 162 |

163 | 164 |

165 | Sub-commands

166 | 167 |

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

170 | 171 |

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.

178 | 179 |

The edit sub-command is context-sensitive, and will launch your EDITOR or VISUAL editor to let you edit the correct menu.

180 | 181 |

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.

186 | 187 |

Here are all the sub-command options and their equivalents (-c and -s are completely equivalent):

188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 |
optioncmdcmdcontext
-aaadddirectory, command
-ccconnectdirectory, command
-ddlistcommand, space
-eeedit*
-hhhelp*
-iiinfo*
-lllistcommand, space
-mmmenudirectory, space
-ssspacedirectory, command
-xxdeletedirectory, command
-oooptionshelp
-aaaliaseshelp
-iiinfohelp
279 | 280 |

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:

285 | 286 |
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 |

312 | Using the title command

313 | 314 |

bash-menu comes with a custom PS1 bash prompt. This prompt can show you:

315 | 316 | 323 | 324 |

To see all the options, type

325 | 326 |

title -h

327 | 328 |

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

339 | 340 |

Here is what it looks like when you are ahead:

341 | 342 |

343 | 344 |

If you type git status you'll see why:

345 | 346 |

347 | 348 |

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:

353 | 354 |

355 | 356 |

To customize your prompt, call title in your ~/.bash_profile after you source in ~/.bash-menu/.bash_profile:

357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 |
~/.bash_profile
source ~/.bash-menu/.bash_profile
source ~/.laramie/.bash_profile
373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 |
~/.laramie/.bash_profile
DYNAMIDE_SPACES_LIST=~/.laramie/spaces.laramie.list
title -user -nohost -title Lappy -window
389 | 390 |

391 | Editing

392 | 393 |

You can edit your menus in two ways:

394 | 395 | 399 | 400 |

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 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 |
Sub-commands:
d xlaunches the delete menu for directory lists
d x 3deletes directory list item 3
d mxlaunches the delete menu for commands
d mx 3deletes command menu item 3
d m xlaunches the delete menu for commands, using submenu
d maadd to the command menu, using command-line
d m aadd to the command menu, using submenu
d elaunch EDITOR for directory lists
d m elaunch EDITOR for the command menu
d slaunch the space chooser
458 | 459 |

460 | Examples

461 | 462 |

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)

478 | 479 |
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

528 | 529 |
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.

539 | 540 |

541 | 542 |

mvn is a popular build tool. You can see where it begins to run with the line "[INFO] Scanning for projects...

543 | 544 |

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.

549 | 550 |
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 | --------------------------------------------------------------------------------