From cf68f8b6de8cf24dabbe6bdd7ce107d589665a2e Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 29 Dec 2016 18:28:40 -0500 Subject: [PATCH] add history to `cd` by default --- .profile.d/aliases.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.profile.d/aliases.sh b/.profile.d/aliases.sh index f7d6f6e..3ee83b7 100644 --- a/.profile.d/aliases.sh +++ b/.profile.d/aliases.sh @@ -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' -- 2.39.5