updated on Sun Jan 22 20:01:29 UTC 2012
[aur-mirror.git] / ypb.sh / navigus.sh
blobeeb5c0c60d9be3b4f12127b332dc36d394e0aea7
1 ### why the heck something like this in not on by default? ###
3 # avigu.sh help
4 function N_avigush_help() {
5 echo "#
6 # [h | help]
7 # [l | list] : list dirs
9 # [s | switch] [args] : push current, then 'cd args'
10 # [g | go] <num> : go to <num> directory from list
11 # [n | navigate] <num> : push current, then 'N g <num>'
12 # better be in range with that <num>
13 # [e | erase] <num> : remove <num>th dir from list
14 # [c | clear] : clear current list completely
16 # [d | dump] [file] : dump dirs to <file> or ~/.avigush
17 # [r | restore] [file] : restore from <file> or ~/.avigush
21 # list dirs
22 function N_avigush_list() {
23 dirs -l -p -v | egrep -v "^.*0[[:blank:]]+/"
26 # switch to dir saving current
27 function N_avigush_switch() {
28 pushd . > /dev/null ; cd "$@" ;
31 # go to Nth dir in stack
32 function N_avigush_go() {
33 # Zsh knows not the 'dirs +/-N' but 'cd +/-N'
34 cd $(N l | egrep "^.*$1[[:blank:]]+/" | sed 's|^[^/]*||')
37 # go to Nth while pushing current for later... n as in navigate
38 function N_avigush_navigate() {
39 pushd . > /dev/null ; N g $(($1+1)) ;
42 # erase Nth
43 function N_avigush_erase() {
44 popd +$1 > /dev/null
47 # clear
48 function N_avigush_clear() {
49 dirs -c
52 # save to default or some file
53 function N_avigush_dump() {
54 local FILE=${1:-$HOME/.avigush}
55 echo "# dump($FILE)" ;
56 N l | sort -rg |
57 sed 's,^[^/]*,,g' 2>/dev/null > "$FILE" &&
58 echo "# taken" ||
59 echo "# doops" ;
62 # restore from file, bash sucks monkey ballz... forealz!
63 function N_avigush_restore() {
64 local CWD=$(pwd)
65 local FILE=${1:-$HOME/.avigush}
66 [ -r "$FILE" ] || {
67 echo "# file($FILE) not readable" ; return ;
69 echo "# load($FILE)" ;
70 IFS=$'\n' ; for d in `cat $FILE` ; do
71 # echo "-$d-" ;
72 [ -d "$d" ] &&
73 cd "$d" &&
74 pushd . > /dev/null ;
75 done && echo "# done" ||
76 echo "# oops" ;
77 cd $CWD ;
80 function N() {
81 case "$1" in
82 h|help) N_avigush_help ;;
83 l|list) N_avigush_list ;;
84 s|switch) shift ; N_avigush_switch "$@" ;;
85 g|go) shift ; N_avigush_go "$@" ;;
86 n|navigate) shift ; N_avigush_navigate "$@" ;;
87 e|erase) shift ; N_avigush_erase "$@" ;;
88 c|clear) N_avigush_clear ;;
89 d|dump) shift ; N_avigush_dump "$@" ;;
90 r|restore) shift ; N_avigush_restore "$@" ;;
91 *) N_avigush_help ;;
92 esac
95 # BIGFATNOTE: unlimited number of dirs regex might cut smth off.