Created
November 10, 2022 14:18
-
-
Save viktordw/0976f9322554ead469404fae82e0af12 to your computer and use it in GitHub Desktop.
Original URL: https://fex.belwue.de/fstools/bash.html#history
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare -a DIRS | |
savedir() { | |
local i | |
for ((i=1;i<=9;i++)); do | |
test "$1" = "${DIRS[$i]}" && return | |
done | |
for ((i=9;i>1;i--)); do | |
DIRS[$i]="${DIRS[((i-1))]}" | |
done | |
DIRS[1]="$1" | |
} | |
showdirs() { | |
local i=1 | |
while [ "${DIRS[$i]}" ]; do | |
echo "$i: ${DIRS[$i]}" | |
((i++)) | |
done | |
} | |
gotodir() { | |
local d | |
showdirs | |
printf "goto: " | |
read -n 1 d | |
echo | |
cd "${DIRS[$d]}" | |
} | |
PROMPT_COMMAND=prompt_command | |
prompt_command() { savedir "$OLDPWD"; } | |
alias cdh=gotodir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment