1
0
Fork 0
mirror of https://github.com/sbrl/bin.git synced 2018-01-10 21:33:46 +00:00
This commit is contained in:
Starbeamrainbowlabs 2016-02-05 20:09:08 +00:00
parent 4e22905074
commit 14f1762da3
2 changed files with 59 additions and 3 deletions

View file

@ -145,6 +145,8 @@ alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo
#_Z_OWNER=sbrl #_Z_OWNER=sbrl
#. /home/sbrl/bin/z.sh #. /home/sbrl/bin/z.sh
# Add pd
. ~/bin/pd-setup.sh
# Alias definitions. # Alias definitions.
# You may want to put all your additions into a separate file like # You may want to put all your additions into a separate file like
@ -165,6 +167,3 @@ if ! shopt -oq posix; then
. /etc/bash_completion . /etc/bash_completion
fi fi
fi fi

57
pd-setup.sh Executable file
View file

@ -0,0 +1,57 @@
#!/usr/bin/env bash
# From http://unix.stackexchange.com/a/31181/64687
### Help ###
: '
# same as pushd +1
$ pd 1
# show a prompt, choose by number
$ pd
0 ~/Dropbox/Projects/ds/test
1 /Project/Warnest/docs
2 /tmp
? 2
/tmp ~/Dropbox/Projects/ds/test /Project/Warnest/docs
# or choose by substring match
$ pd
0 /tmp
1 ~/Dropbox/Projects/ds/test
2 /Project/Warnest/docs
? doc
/Project/Warnest/docs /tmp ~/Dropbox/Projects/ds/test
# substring without prompt
$ pd test
~/Dropbox/Projects/ds/test /Project/Warnest/docs /tmp
'
function pd()
{
if [[ $# -ge 1 ]];
then
choice="$1"
else
dirs -v
echo -n "? "
read choice
fi
if [[ -n $choice ]];
then
declare -i cnum="$choice"
if [[ $cnum != $choice ]];
then #choice is not numeric
choice=$(dirs -v | grep $choice | tail -1 | awk '{print $1}')
cnum="$choice"
if [[ -z $choice || $cnum != $choice ]];
then
echo "$choice not found"
return
fi
fi
choice="+$choice"
fi
pushd $choice
}