]> git.wh0rd.org - home.git/commitdiff
add history to `cd` by default
authorMike Frysinger <vapier@gentoo.org>
Thu, 29 Dec 2016 23:28:40 +0000 (18:28 -0500)
committerMike Frysinger <vapier@gentoo.org>
Thu, 29 Dec 2016 23:28:40 +0000 (18:28 -0500)
.profile.d/aliases.sh

index f7d6f6e9f05575faaad849ef10cba404fb17c1af..3ee83b7f206b561e5c1e5e1922b97fca2e6e8d3a 100644 (file)
@@ -44,11 +44,41 @@ adk_path() {
 pd() {
        if [[ $# -eq 0 ]] ; then
                popd
+       elif [[ $# -eq 1 && $1 == "--" ]] ; then
+               dirs -v
        else
                pushd "$@"
        fi
 }
 
+cd_history() {
+       if [[ $# -eq 1 ]] ; then
+               case $1 in
+               -h)
+                       command dirs "$1" |& tail -1
+                       command cd "$1" |& tail -1
+                       return
+                       ;;
+               --help)
+                       command dirs "$1"
+                       command cd "$1"
+                       return
+                       ;;
+               -[clpv])
+                       command dirs "$1"
+                       return
+                       ;;
+               -[0-9]*)
+                       set -- "$(dirs "+${1:1}")"
+                       ;;
+               esac
+       fi
+       if command cd "$@" ; then
+               pushd -n "${PWD}" >/dev/null
+       fi
+}
+alias cd='cd_history'
+
 if [[ ${TERM} != "dumb" ]] ; then
        export GREP_COLORS=ne #470810
        alias grep='grep --colour=auto -d skip'