Created
November 1, 2019 14:19
-
-
Save adrianlungu/f2de59158ee569fb3f540c2b49985fb9 to your computer and use it in GitHub Desktop.
Bash history for iTerm - 2019
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
# 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