Ubuntu – Some fast way to save and restore tabs of Terminal

command lineconfigurationgnome-terminaltabs

I have a Terminal window with a dozen named tabs open.

I would like to save the current configuration and have it restored with names and directories.

Is there a way to do this?

Best Answer

To save configuration into /tmp/cfg:

gnome-terminal --save-config=/tmp/cfg

To load it back:

gnome-terminal --load-config=/tmp/cfg 

UPDATE

After playing around with bash I created following script which stores tab names into file /tmp/test as well:

#!/usr/bin/env bash

gnome-terminal --save-config=/tmp/test

LINES=($(grep -n '\[Terminal' /tmp/test | cut -d: -f1))
for ((i=0; i<$(grep '\[Terminal' /tmp/test | wc -l); i++))
do
    TITLE=$(xprop -id $WINDOWID WM_NAME | sed -e 's/WM_NAME(STRING) = "//' -e 's/"$//';xdotool key ctrl+Page_Down;)
    sed -ri "$((${LINES[$i]}+$i))s/.*/&\nTitle=$TITLE/" /tmp/test 
done

To assign names properly you have to run it from first tab of your terminal. Loading same as before:

gnome-terminal --load-config=/tmp/test

EXPLANATION:

I can use following to get tab name:

xprop -id $WINDOWID WM_NAME

I can use following to jump to next tab:

xdotool key ctrl+Page_Down;

I'm getting number of tabs after grepping configuration file I saved before:

$(grep '\[Terminal' /tmp/test | wc -l)

So I can iterate over tabs inside a loop. I have to add "Title=titlename" entry for each tab configuration section in file saved before. To do so, first I'm creating an array of line numbers where I'll be adding lines.

LINES=($(grep -n '\[Terminal' /tmp/test | cut -d: -f1))

I'm adding "Title=titlename" line inside of loop iterating over tabs:

sed -ri "$((${LINES[$i]}+$i))s/.*/&\nTitle=$TITLE/" /tmp/test