Skip to content

Instantly share code, notes, and snippets.

@appsmatics
Last active January 10, 2024 19:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appsmatics/ff27e885460bd345eabe1c5f70c4438b to your computer and use it in GitHub Desktop.
Save appsmatics/ff27e885460bd345eabe1c5f70c4438b to your computer and use it in GitHub Desktop.
Gnome Terminal History
#!/usr/bin/bash
# Start a gnome-terminal with a named history file
# Keeps a separate history for each terminal session in a $HOME/history/ folder
# HISTCONTROL=erasedups:ignoreboth ensures only unique entries
# Tested with Ubuntu 20 and 22 only!
# To sync to another machine, cp the .history/ folder across :)
# pass the terminal name as arg to this script
# usage gt.sh myproj1-server | myproj1-adminui | myproj2-dbadmin | misc | junk1
# add bash-completion by listing the files in the .history dir
# complete -W "$(ls ~/.history/)" gt.sh
HISTDIR="$HOME/.history"
GT_NAME=""
if [ -z "$1" ]; then
GT_NAME="default"
ls $HISTDIR
exit
else
GT_NAME="$1"
fi
PROFILE_NAME=""
if [ -z "$2" ]; then
PROFILE_NAME="tango-dark"
else
PROFILE_NAME="$2"
fi
[[ -d "$HISTDIR" ]] || mkdir --mode=700 "$HISTDIR"
[[ -d "$HISTDIR" ]] && chmod 700 "$HISTDIR"
export HISTFILE="$HISTDIR/$GT_NAME"
export HISTCONTROL=erasedups:ignoreboth
export HISTSIZE=2000
export HISTFILESIZE=3000
export HISTIGNORE="ls:ll:lla:lal:h:cl:clear:cd:pwd"
# https://unix.stackexchange.com/a/18443
shopt -s histappend
export PROMPT_COMMAND="history -n; history -w; history -c; history -r; $PROMPT_COMMAND"
echo "Starting gnome-terminal $GT_NAME"
echo "Appending history to $HISTFILE"
echo "HISTCONTROL=$HISTCONTROL"
gnome-terminal -p --title=$GT_NAME --profile=$PROFILE_NAME --geometry="140x24+100+750"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment