Skip to content

Instantly share code, notes, and snippets.

@lbonanomi
Last active November 15, 2020 18:00
Show Gist options
  • Save lbonanomi/ab13df664ef2054a2e34eeb933d6675d to your computer and use it in GitHub Desktop.
Save lbonanomi/ab13df664ef2054a2e34eeb933d6675d to your computer and use it in GitHub Desktop.
btnMash: hit enter 3-times to be reminded where you are
# source me.
export PROMPT_COMMAND=btnMash
function btnMash {
# Init a counter for prompts-displayed if its missing
[[ -f /tmp/promptsDisplayed ]] || history | tail -1 | awk '{ print $1 }' > /tmp/promptsDisplayed;
# Init a counter for commands
[[ -f /tmp/commandsRun ]] || (history | tail -1 | awk '{ print $1 }' > /tmp/commandsRun)
COMMANDS=$(cat /tmp/commandsRun)
# Increment prompts-displayed counter
echo $(($(cat /tmp/promptsDisplayed)+1 )) > /tmp/promptsDisplayed;
history | tail -1 | awk '{ print $1 }' > /tmp/commandsRun
if [[ $COMMANDS -lt $(cat /tmp/commandsRun) ]]
then
cat /tmp/commandsRun > /tmp/promptsDisplayed
fi
PROMPTS=$(cat /tmp/promptsDisplayed)
if [[ $PROMPTS -ge $(($COMMANDS+3)) ]]
then
lulwat; rm /tmp/promptsDisplayed; return
fi
}
function lulwat {
ID=$(id | awk '{gsub(/[\(-\)]/," ")} { print $2 }');
WHO=$(who -m | awk '{ print $1 }')
[[ "$ID" == "$WHO" ]] && echo "You are: $ID"
[[ "$ID" == "$WHO" ]] || echo "You are: $ID (su-ed from $WHO)"
printf "On: $(hostname):$(pwd)\n"
# If this a git repo, remind me of the remote
git status &>/dev/null && (
printf "$(git remote -vv | awk '{ print $2 }' | head -1) ($(git branch | awk '{ print $2 }'))\n"
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment