Last active
February 16, 2025 22:21
-
-
Save appsmatics/ff27e885460bd345eabe1c5f70c4438b to your computer and use it in GitHub Desktop.
Gnome Terminal History
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
#!/usr/bin/bash | |
# Start a gnome-terminal with a named history file | |
# Keeps a separate history for each terminal session in a $HOME/histories/ folder | |
# HISTCONTROL=erasedups:ignoreboth ensures only unique entries | |
# Tested with Ubuntu 20 and 22 only! | |
# To sync to another machine, cp the .histories/ 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 ~/.histories/)" gt.sh | |
HISTDIR="$HOME/.histories" | |
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