Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
Very interesting feature, but I do not think that's available. –  Nickolas Jun 20 '13 at 16:34
    
What terminal application are you using? Gnome terminal? Konsole? etc. –  gertvdijk Jun 20 '13 at 20:24
    
@gertvdijk: The one called "Terminal". I believe it is the gnome one. –  false Jun 20 '13 at 20:33
add comment

5 Answers

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 
share|improve this answer
    
Thanks, I just tried it out: the pwd's are perfectly restored, but the tab-titles are lost. They are not stored in the config. –  false Jun 20 '13 at 20:41
    
@false, I updated my answer. –  Nykakin Jun 20 '13 at 22:35
    
You may want to look into the screen command. I don't use it, but I believe it can save and restore all sorts of sessions - even remote ones. –  Joe Jun 27 '13 at 2:01
    
12.04: When opening, the tab names appear for a brief instant then disappear :-( –  Nicolas Raoul Sep 24 '13 at 8:21
    
By the way, I first had to run sudo apt-get install xdotool. –  Nicolas Raoul Sep 24 '13 at 8:24
show 3 more comments

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 :)

share|improve this answer
add comment

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!!

share|improve this answer
add comment

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

  1. Creates a Profile with title and 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 &'
share|improve this answer
add comment

I Tried one more option,

I Changed my default Title for Terminal to use the Intital value in .bashrc, rather than changing the profile settings.

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="$PS1"
    ;;
*)
    ;;
esac

If You do this, there is no need to change your Terminal Profile. When you execute "gnome-terminal --load-config" all the tab names are restored properly. And you can also change as you like it and save the tabs again!!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.