Some fast way to save and restore tabs of Terminal?

Solution 1:

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 

Solution 2:

An alternative is to just use Byobu. Press F2 to open new terminals inside it. Use F3 and F4 to switch left and right between terminals.

Close the GUI window anytime you want. When you reopen Byobu all your terminals are restored :)

Solution 3:

I've also looked for that feature in Gnome terminal but couldn't find it. The best option I found so far is to use konsole. It allows you to bookmark your tabs, so that you can get back to them by choosing them from a bookmarks menu. I hope this helps.

Solution 4:

I found a way to do it that I think is faster.

  1. Creates a profile with the title and the name you want like Yoga said.
  2. Type:

    gnome-terminal --tab-with-profile=PROFILENAME1 --tab-with-profile=PROFILENAME2 ... --tab-with-profile=PROFILENAME999
    

I made an alias with this command and it worked pretty fine for me. I just type workflow and a Terminal appears with 3 tabs and the titles that I chose in the profile definition that are placed into the tabs.

On my .bashrc file I placed:

alias workflow='gnome-terminal --tab-with-profile=Git --tab-with-profile=Run | sublime-text &'

Solution 5:

I tried the below options after restoring the saved settings and the Title is also restored properly.

  1. Go Settings->Profiles and select on the Current Profile you are using
  2. Click on Edit and Go to "Title and command" Tab
  3. Make Initial Title Blank
  4. Select "Keep Initial Title" Option in the drop down box below.

This option avoid your initial title set to be overwritten.

Hope This helps and a great script indeed. Save a lot of time whenever u reboot and I can happily reboot my virtual box frequently.

Thanks!!