10

Over time, I become invested in my terminal sessions: tabs, command history, window layout and title, etc. Eventually, a reboot requires me to start all over again which wastes my time.

The two terminal emulators with which I'm familiar had at least partial capability here, but the functionality has since been removed: konsole lost this functionality somewhere along the way to KDE4. gnome-terminal lost the --save-config option as "obsolete" somewhere before version 3.10.2, i.e. the answer here no longer applies: Save multiple gnome-terminal layout?

I want to capture the current state of all terminal sessions and restore them after a reboot. A scripted solution would be fine, so long as it does not require manual updates to track session changes.

8
  • 1
    Define "state". For example, if you are reading a file with less, do you want that same file to be remembered next time you open your terminal or do you just want the tabs/panes set up and the relevant programs launched? Would something like my answer here work for you?
    – terdon
    May 20, 2014 at 22:14
  • 1
    State means: windows, tabs, command history, window layout, window & tab titles. I do not need to save state for arbitrary processes running in the terminal session, e.g. "less". Even bash needs some coaxing here, since command history is not saved per instance without some tricks. I'll check your link. The closest I've found so far is Konsole bookmarks.
    – srking
    May 20, 2014 at 23:54
  • In that case, terminator can do it as I explain in the link I gave in my previous comment. Let me know if you need anything else and I'll tweak it accordingly and post as a new answer here. If not, I will vote to close this as a duplicate.
    – terdon
    May 20, 2014 at 23:59
  • 1
    @terdon, Thanks, I'm glad to know about terminator. After briefly experimenting, there are shortcomings for me: (1) does not save bash history per shell, and (2) can't rename tabs? I suspect I can't do what I want without rolling some fragile scripts.
    – srking
    May 21, 2014 at 0:49
  • 1
    @terdon: Yes, bash-isms are required for history save/restore, but this could work when each bash shell has its own unique HISTFILE. The terminal program could help in this regard by allowing history setup commands to run at startup. It looks like Terminator allows per-shell startup, but it's a brain and labor intensive process for novice users. A canned solution guided via a GUI would be ideal.
    – srking
    May 21, 2014 at 16:23

6 Answers 6

2

this isn't exactly what you asked for but tmux has such capabilities.

Just make sure to install the tmux-resurrect plugin along with it, which allows for restoring the tmux environment (windows, splits, and certain running programs) after a restart.

On the bright side, tmux will work with all

1

Here is an xfce terminal fork, with possibility to save/restore session just from menu: https://github.com/repu1sion/xfce4-terminal

1
  • I'm using the most recent xfce4-terminal 0.8.10-1 from Arch Linux, and these menus are missing. The link you gave is pretty strange: why doesn't it have any releases? Jan 7, 2021 at 14:43
1

https://github.com/Eugeny/terminus saves open tabs & remembers the correct directory for each

1

The excellent Guake Terminal allows you to do this, there is an option to remember your set of tabs between restarts.

It's currently listed as an 'experimental' feature in the settings, but after using this feature for a few months, I've never had a problem.

0

I guess that this is not really an answer to your question, but this is how I had it set up:

A bunch of scripts which would open different "Gnome-Terminal presets".

For example, in this script, I open gnome-terminal with three tabs, and call SSH with parameters in each one.

#!/bin/sh
PATH=/usr/bin:/bin 

gnome-terminal \
--tab -t CustomTabText1 -e 'sh -c "ssh hostname.one"' \
--tab -t CustomTabText2 -e 'sh -c "ssh hostname.two"' \
--tab -t CustomTabText3 -e 'sh -c "ssh hostname.three"'

I also used ssh config file heavily to reflect specific host SSH parameters. Of course, if you need an exception, just pass the parameters to SSH in the gnome-terminal script, which will take precedence over the SSH config file.

1
  • For running simple commands such as "ssh machine" you do not need running a shell (sh -c). It is needed to perform redirections and pipelining, wildcard expansion, conditionals etc. but not for running plain commands. Nov 6, 2014 at 10:22
0

Now with vscode extension Terminal Keeper you can customize your saved terminal sessions with json config like

 "default": [
            [
                {
                    "name": "docker:ros",
                    "commands": [
                        "ssh r99"
                    ],
                    "autoExecuteCommands": true
                },
                {
                    "name": "docker:k8s",
                    "commands": [
                        ""
                    ]
                },
                {
                    "name": "docker:nats",
                    "commands": [
                        ""
                    ]
                },
                {
                    "name": "docker:fleet",
                    "commands": [
                        ""
                    ]
                }
            ],
            [
                {
                    "name": "db:postgre",
                    "commands": [
                        ""
                    ]
                },
                {
                    "name": "db:redis",
                    "commands": [
                        ""
                    ]
                },
                {
                    "name": "db:hyper",
                    "commands": [
                        ""
                    ]
                },
                {
                    "name": "db:mysql",
                    "commands": [
                        ""
                    ]
                }
            ],
            [
                {
                    "name": "api:delivery",
                    "commands": [
                        ""
                    ]
                },
                {
                    "name": "api:feedback",
                    "commands": [
                        ""
                    ]
                },
                {
                    "name": "api:service",
                    "commands": [
                        ""
                    ]
                }
            ],
            {
                "name": "test",
                "commands": [
                    ""
                ]
            },
            {
                "name": "debug",
                "commands": [
                    ""
                ]
            }
        ],

pretty easily.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .