How to change gnome-terminal scrollback lines from command line

Using Ubuntu 22.04. I want to change gnome-terminal scrollback lines from the command line.

I know it’s possible to do it from Terminal -> Settings (the hamburger button) -> Preference -> Profiles -> Unnamed -> Scrolling, like this:

Preferences - Profile Unnamed

I want to be able to do the same, but from the command line. I am looking for a solution that will work in sync with the GUI option, not overwride it. The idea is that if after some time I forget I set the option from CLI , I should be able to change its value from Preference -> Profiles -> Unnamed -> Scrolling.

Asked By: sotirov

||

This can be done with gsettings.

Limit scrollback to 250,000 lines:

gsettings set org.gnome.Terminal.Legacy.Profile:/org/gnome/terminal/legacy/profiles:/:$(gsettings get org.gnome.Terminal.ProfilesList default | tr -d ')/ scrollback-lines 250000

The maximum scrollback-lines value is 2147483647, and the default is 10000.

Enable unlimited scrollback:

gsettings set org.gnome.Terminal.Legacy.Profile:/org/gnome/terminal/legacy/profiles:/:$(gsettings get org.gnome.Terminal.ProfilesList default | tr -d ')/ scrollback-unlimited true

How it works:

gsettings offers a simple commandline interface to GSettings. It lets
you get, set or monitor an individual key for changes.

The SCHEMA and KEY arguments are required for most commands to specify
the schema id and the name of the key to operate on. The schema id may
optionally have a :PATH suffix. Specifying the path is only needed if
the schema does not have a fixed path.

When setting a key, you also need specify a VALUE The format for the
value is that of a serialized GVariant, so e.g. a string must include
explicit quotes: "’foo’". This format is also used when printing out
values.

We are using org.gnome.Terminal.Legacy.Profile as SCHEMA.

The :PATH we need is /org/gnome/terminal/legacy/profiles:/:[target-profile-id]/ where [target-profile-id] is the id of the profile we are editing. The command gsettings get org.gnome.Terminal.ProfilesList default gets the id of the default profile and tr -d ' removes the ' from the response.

To change terminal scrollback lines, the KEY is scrollback-lines and we set its VALUE to 250000, which is the number of lines we want to be able to scroll back. Depending on whether we want to enable or disable the unlimited scrollback, we use scrollback-unlimited as KEY with true or false as VALUE.

Related:

If you are worried about resource usage, check this post: Gnome terminal scrollback lines?

Answered By: sotirov