aboutsummaryrefslogtreecommitdiffstats
path: root/cdlog.sh
diff options
context:
space:
mode:
Diffstat (limited to 'cdlog.sh')
-rw-r--r--cdlog.sh35
1 files changed, 33 insertions, 2 deletions
diff --git a/cdlog.sh b/cdlog.sh
index 017a9f0..e1a6181 100644
--- a/cdlog.sh
+++ b/cdlog.sh
@@ -1,7 +1,9 @@
# License at bottom.
-# Configuration variables
+# Globals
+declare -A cdlog_alias # cd aliases
+# Configuration variables
cdlog_autocs=${cdlog_autocs-y} # cd behaves like cs if match
# Update after FIFO change.
@@ -146,7 +148,21 @@ cdlog.recover()
cdlog.chdir()
{
local cur=$PWD
- local i=10
+ local i
+ local def
+
+ if [ $# -eq 2 -a "$1" = -P ] ; then
+ case $2 in
+ ( */* )
+ ;;
+ ( * )
+ def=${cdlog_alias[$2]}
+ if [ -n "$def" ] ; then
+ set -- -P "$def"
+ fi
+ ;;
+ esac
+ fi
if command cd "$@" && [ "$PWD" != "$cur" ]; then
# only if we successfully change to a different
@@ -303,6 +319,20 @@ cdlog.mcd()
return $res
}
+cdlog.alias()
+{
+ local ali=
+ local def=
+
+ if [ $# -ne 2 ] ; then
+ printf "cdlog.alias: two arguments required\n"
+ return 1
+ fi
+
+ cdlog_alias[$1]=$2
+ return 0
+}
+
# Aliases.
alias cd='cdlog.chdir -P'
alias pd='cdlog.pop'
@@ -312,6 +342,7 @@ alias cll='cdlog -l'
alias mcd='cdlog.mcd'
alias mcs='cdlog.mcd -s'
alias cdr='cdlog.recover'
+alias cdalias='cdlog.alias'
# Better completion for $x[Tab]
shopt -s direxpand