From 8954f87cd06d91ca4a7d5d3860b6e6032083d58b Mon Sep 17 00:00:00 2001 From: q Date: Thu, 15 Jan 2015 20:51:02 +0200 Subject: [PATCH] hcd or historycd to jump to previous visited folders --- qcd_function | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/qcd_function b/qcd_function index d4180b5..8458481 100644 --- a/qcd_function +++ b/qcd_function @@ -15,11 +15,26 @@ function cd_history () { } alias cd=cd_history +function hcd() { + local d + + if [ -z "$1" ] + then tail -n 20 "$HOME/.bash_cdhistory" | head -n 19 | cut -d: -f2 | tac | cat -n | sed 's,^ \+,,' | tac + return + fi + d=$( tail -n 20 "$HOME/.bash_cdhistory" | head -n 19 | cut -d: -f2 | tac | cat -n | sed 's,^ \+,,' | grep -h "^$1 " ) + d=${d/* /} + if [ ! -z "$d" ] + then \cd "$d" + fi +} + function qcd() { local OPTIND local OPTARG local opt local case + local d while getopts ae:hiILl:m opt do case "$opt" in