Save and restore session of the Gnome Terminal
INFO: Unfortunately „–save-config” option is no longer supported in the new versions of gnome-terminal so this script will not work.
I use terminal quite often in my work. I have a specific way how I work with terminal. I usually have about 10 tabs open in different directories so I can quickly switch between them. I felt quite frustrated when I was in the middle of something, but I had to reboot the PC for some reason. It is because it means I would need to set-up my perfect multi-tab terminal from scratch.
Fortunately I found very easy solution for this issue. This article describes easy way to save and restore the terminal session.
It is a basic solution. It allows you to restore all the tabs from the Gnome Terminal in the working directories, but it will not restore the content of the terminals.
- Download and extract save-terminal and load-terminal files.
- Save both files in
.terminal-sessiondirectory in your home directory.
add following line to your
~/.bashrcfile export PATH=$PATH:~/bin
Every time you want to save a session execute (in any tab):
It will create a new file in the
.terminal-session directory containing information about all currently opened Gnome Terminal tabs.
When you want to restore all tabs from the last saved session execute:
It will load the Gnome Terminal session from the latest file from
Both save-terminal and load-terminal scripts use
gnome-terminal commands with
gnome-terminal command should be available on any GNU Linux distribution with Gnome packages installed.
Main responsibility of the save-terminal and load-terminal scripts is to properly save the file and then choose the latest file to load the terminal session from it. These scripts are extremely simple.
TERMINAL_SESSIONS_DIR=~/.terminal-sessions gnome-terminal --save-config=$TERMINAL_SESSIONS_DIR/$(date +"%m%d%Y-%H%M%S") </pre> <p></p> This code will create new file in the ~/.terminal-sessions directory with the current time as a file name. **load-session**: TERMINAL_SESSIONS_DIR=~/.terminal-sessions NEWEST_FILENAME=$(ls -t $TERMINAL_SESSIONS_DIR | head -1) echo $NEWEST_FILENAME gnome-terminal --load-config=$TERMINAL_SESSIONS_DIR/$NEWEST_FILENAME</pre> <p></p> This code will find the newest file from the ~/.terminal-sessions directory and use it to load Gnome Terminal session using gnome-terminal. Complete source code can be found in [GitHub repository].