Skip to content

Instantly share code, notes, and snippets.

@viktordw
Created November 10, 2022 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viktordw/0976f9322554ead469404fae82e0af12 to your computer and use it in GitHub Desktop.
Save viktordw/0976f9322554ead469404fae82e0af12 to your computer and use it in GitHub Desktop.
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