Daniel Engel | e56c71a | 2011-03-14 20:36:25 -0400 | [diff] [blame] | 1 | # Directory stack navigation: |
| 2 | # |
| 3 | # Add to stack with: pu /path/to/directory |
| 4 | # Delete current dir from stack with: po |
| 5 | # Show stack with: d |
| 6 | # Jump to location by number. |
| 7 | |
Erich Smith | 55e77de | 2012-05-11 23:27:03 -0400 | [diff] [blame] | 8 | cite about-plugin |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 9 | about-plugin 'directory stack navigation' |
Erich Smith | 55e77de | 2012-05-11 23:27:03 -0400 | [diff] [blame] | 10 | |
Daniel Engel | e56c71a | 2011-03-14 20:36:25 -0400 | [diff] [blame] | 11 | # Show directory stack |
| 12 | alias d="dirs -v -l" |
| 13 | |
| 14 | # Change to location in stack bu number |
| 15 | alias 1="pushd" |
| 16 | alias 2="pushd +2" |
| 17 | alias 3="pushd +3" |
| 18 | alias 4="pushd +4" |
| 19 | alias 5="pushd +5" |
| 20 | alias 6="pushd +6" |
| 21 | alias 7="pushd +7" |
| 22 | alias 8="pushd +8" |
| 23 | alias 9="pushd +9" |
| 24 | |
| 25 | # Clone this location |
| 26 | alias pc="pushd \`pwd\`" |
| 27 | |
| 28 | # Push new location |
| 29 | alias pu="pushd" |
| 30 | |
| 31 | # Pop current location |
| 32 | alias po="popd" |
| 33 | |
| 34 | function dirs-help() { |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 35 | about 'directory navigation alias usage' |
| 36 | group 'dirs' |
Erich Smith | 55e77de | 2012-05-11 23:27:03 -0400 | [diff] [blame] | 37 | |
Daniel Engel | e56c71a | 2011-03-14 20:36:25 -0400 | [diff] [blame] | 38 | echo "Directory Navigation Alias Usage" |
| 39 | echo |
| 40 | echo "Use the power of directory stacking to move" |
| 41 | echo "between several locations with ease." |
| 42 | echo |
| 43 | echo "d : Show directory stack." |
| 44 | echo "po : Remove current location from stack." |
| 45 | echo "pc : Adds current location to stack." |
| 46 | echo "pu <dir>: Adds given location to stack." |
| 47 | echo "1 : Chance to stack location 1." |
| 48 | echo "2 : Chance to stack location 2." |
| 49 | echo "3 : Chance to stack location 3." |
| 50 | echo "4 : Chance to stack location 4." |
| 51 | echo "5 : Chance to stack location 5." |
| 52 | echo "6 : Chance to stack location 6." |
| 53 | echo "7 : Chance to stack location 7." |
| 54 | echo "8 : Chance to stack location 8." |
| 55 | echo "9 : Chance to stack location 9." |
| 56 | } |
Yakkala Yagnesh Raghava | c6e096e | 2011-08-06 00:14:15 +0900 | [diff] [blame] | 57 | |
| 58 | |
| 59 | # ADD BOOKMARKing functionality |
| 60 | # usage: |
| 61 | |
| 62 | if [ ! -f ~/.dirs ]; then # if doesn't exist, create it |
| 63 | touch ~/.dirs |
| 64 | else |
| 65 | source ~/.dirs |
| 66 | fi |
| 67 | |
| 68 | alias L='cat ~/.dirs' |
| 69 | |
| 70 | G () { # goes to distination dir otherwise , stay in the dir |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 71 | about 'goes to destination dir' |
| 72 | param '1: directory' |
Erich Smith | 55e77de | 2012-05-11 23:27:03 -0400 | [diff] [blame] | 73 | example '$ G ..' |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 74 | group 'dirs' |
Erich Smith | 55e77de | 2012-05-11 23:27:03 -0400 | [diff] [blame] | 75 | |
Yakkala Yagnesh Raghava | c6e096e | 2011-08-06 00:14:15 +0900 | [diff] [blame] | 76 | cd ${1:-$(pwd)} ; |
| 77 | } |
| 78 | |
| 79 | S () { # SAVE a BOOKMARK |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 80 | about 'save a bookmark' |
| 81 | group 'dirs' |
Erich Smith | 55e77de | 2012-05-11 23:27:03 -0400 | [diff] [blame] | 82 | |
Yakkala Yagnesh Raghava | dcdfd66 | 2011-08-06 01:01:17 +0900 | [diff] [blame] | 83 | sed "/$@/d" ~/.dirs > ~/.dirs1; |
Yakkala Yagnesh Raghava | c6e096e | 2011-08-06 00:14:15 +0900 | [diff] [blame] | 84 | \mv ~/.dirs1 ~/.dirs; |
| 85 | echo "$@"=\"`pwd`\" >> ~/.dirs; |
| 86 | source ~/.dirs ; |
| 87 | } |
| 88 | |
| 89 | R () { # remove a BOOKMARK |
Erich Smith | 08e439c | 2012-05-13 08:37:31 -0400 | [diff] [blame] | 90 | about 'remove a bookmark' |
| 91 | group 'dirs' |
Erich Smith | 55e77de | 2012-05-11 23:27:03 -0400 | [diff] [blame] | 92 | |
Yakkala Yagnesh Raghava | dcdfd66 | 2011-08-06 01:01:17 +0900 | [diff] [blame] | 93 | sed "/$@/d" ~/.dirs > ~/.dirs1; |
Yakkala Yagnesh Raghava | c6e096e | 2011-08-06 00:14:15 +0900 | [diff] [blame] | 94 | \mv ~/.dirs1 ~/.dirs; |
| 95 | } |
| 96 | |
| 97 | alias U='source ~/.dirs' # Update BOOKMARK stack |
| 98 | # set the bash option so that no '$' is required when using the above facility |
| 99 | shopt -s cdable_vars |