Skip to content

Instantly share code, notes, and snippets.

@adrianlungu
Created November 1, 2019 14:19
Show Gist options
  • Save adrianlungu/f2de59158ee569fb3f540c2b49985fb9 to your computer and use it in GitHub Desktop.
Save adrianlungu/f2de59158ee569fb3f540c2b49985fb9 to your computer and use it in GitHub Desktop.
Bash history for iTerm - 2019
# ITERM SESSION ID seems to have puctuation in it, replace with slash
export SESSION_ID=${ITERM_SESSION_ID//:/-}
# Unique history file per shell session.
export HISTSIZE=500
# Get only the window/tab indices as ID (w0t0p0) as the Session ID can change
# after updates/restarts/etc...
export HISTFILE="${HOME}/.bash-history-${SESSION_ID:0:6}"
# export HISTFILE="~/bash_history/.bash-history"
# export HISTFILE=$HOME/.bash_hist_${HOSTNAME/.*/}_$(basename $(tty))
export SAVEHIST=500
# New - remove if not working properly
# export HISTCONTROL=ignoreboth
# export HISTCONTROL=ignoredups
# For iTerm2 to show the directory it's in
if [[ ${SESSION_ID} ]]; then
# Display the current git repo, or directory, in iterm tabs.
get_iterm_label() {
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
local directory
directory=${PWD##*/}
echo -ne "\\033];$directory\\007"
else
local branch
local branchdir
branchdir=$(basename "$(git rev-parse --show-toplevel)")
branch=$(git branch 2>/dev/null | grep -e '\* ' | sed "s/^..\(.*\)/{\1}/")
echo -ne "\\033];$branchdir $branch\\007"
fi
}
export PROMPT_COMMAND=get_iterm_label;"${PROMPT_COMMAND}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment