diralias, j - Directory aliases and quick directory navigation

This commit is contained in:
Adolfo Perez Alvarez 2022-05-25 16:04:40 +02:00
parent 9cffb845c4
commit 8e49bcb05d
2 changed files with 45 additions and 0 deletions

32
diralias Normal file
View File

@ -0,0 +1,32 @@
function diralias
{
typeset -i i=0
case $# in
0)
while (( i < ${#DIRALIASNAM[@]} ))
do
printf "%s\t%s\n" ${DIRALIASNAM[i]} "${DIRALIASVAL[i]}"
let i++
done
;;
1)
while [[ $i -lt ${#DIRALIASNAM[@]} && $1 != ${DIRALIASNAM[i]} ]]
do
let i++
done
(( i == ${#DIRALIASNAM[@]} )) && print $1 || print ${DIRALIASVAL[i]}
;;
2)
while [[ $i -lt ${#DIRALIASNAM[@]} && $1 != ${DIRALIASNAM[i]} ]]
do
let i++
done
DIRALIASNAM[i]=$1
DIRALIASVAL[i]="$2"
;;
*)
exit 64
;;
esac
}

13
j Normal file
View File

@ -0,0 +1,13 @@
function j
{
typeset da
da=$(diralias $1)
if print $da | grep '^!' >/dev/null
then
if ! da=$(eval $(print "$da" | sed 's/^!//') 2>/dev/null)
then
return 65
fi
fi
'cd' "$da"
}