Skip to content

Instantly share code, notes, and snippets.

@iwalton3
Created April 22, 2021 16:51
Show Gist options
  • Save iwalton3/3f9bfce510f959782404be25cab1c871 to your computer and use it in GitHub Desktop.
Save iwalton3/3f9bfce510f959782404be25cab1c871 to your computer and use it in GitHub Desktop.
Quick "cd from anywhere" alias
function c {
while read -r _ dir
do
if [[ -e "$dir" ]]
then
echo "$dir"
cd "$dir"
break
fi
done < <(cat ~/.full_history | tail -n 10000 \
| cut -f 3 | sort | uniq -dc | sort -hr | grep "/$1$")
}
function _c {
local IFS=$'\n'
COMPREPLY=( $(cat ~/.full_history | tail -n 10000 \
| cut -f 3 | sort | uniq -dc | sort -hr \
| sed 's/.*\///g' | grep "^$2") )
}
complete -F _c c
tabChar=$'\t'
function prompt_command {
echo "$(date +%Y-%m-%d--%H-%M-%S)$tabChar$(hostname)$tabChar$PWD$tabChar$(history 1)" >> ~/.full_history
}
export PROMPT_COMMAND=prompt_command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment