4

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.

egmont
  • 8,225
sotirov
  • 3,169

1 Answers1

4

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?

sotirov
  • 3,169
  • 2
    That would've been a single clean line of dconf write /org/gnome/terminal/legacy/.../key value to set that key and another dconf reset /org/gnome/terminal/legacy/.../keyto reset ... Only if gnome-terminal developers had provided a cleaner way to get the current profile's name ... +1 – Raffa Nov 13 '23 at 15:49
  • @Raffa Could you please elaborate how you imagine that "cleaner way" that gnome-terminal developers should have provided? The software provides a nice graphical UI where the vast majority of users can achieve their goal. For the rest, there are tools (dconf/gsettings) that allow to modify the backing storage consistently across all GNOME apps. Yes, it takes two steps: one to query the default profile's ID (assuming that's the one OP wants to operate on) and one to set a property of that profile. It's not feasible to introduce a single command solution for everyone's each and every wish. – egmont Nov 13 '23 at 16:52
  • 2
    @egmont It’s a minor thing but could be better and that is the default profile isn’t workable in e.g. dconf … things seem to break when you get to that point in the path and you need to substitute default with the ID … Wouldn’t it be much easier to be able to simply do something like dconf write /org/gnome/terminal/legacy/profiles/default/scrollback-lines 250000 where default actually resolves to the default profile … Or something in these lines. – Raffa Nov 13 '23 at 18:46
  • 1
    @egmont For example and although not optimal but gnome-terminal used to have an option —save-config snd that could be used to get the current profile's ID but now it’s removed in newer versions … and of course I agree that most users might not need such a thing, but extra options are always a plus – Raffa Nov 13 '23 at 18:53
  • Thanks for your answers. I'm afraid dconf doesn't have the concept of "symlinks" where "default" could point to another location. Identifying profiles by their name, rather than an ID, would result in way more problems as soon as the name tries to contain a special character. Moving the settings of at least two entire profiles to new locations when the default is changed, so that the default one is always under a fixed path, sounds quite a twisted logic to me. – egmont Nov 13 '23 at 19:01
  • I'm not familiar with the former "save/load config" options, but I'm quite certain that editing the dumped file with scripts (because apparently OP wants a non-interactive solution for this problem) would be way more cumbersome than the two gsettings or dconf commands above. – egmont Nov 13 '23 at 19:02
  • It was never a goal (rightly so, I believe) to make manual operations on the backing data storage be as simple as they can theoretically be. I believe it's simple enough so that whatever you're looking for can be achieved by only a few commands. In this very case, two commands. Refactoring the code and the prefs storage layout (let alone the migration cost for all users) so that a set of predetermined use cases (like this one) take one command instead of two, or claiming that it should have been implemented like that to begin with, sounds absolutely unreasonable to me. But maybe it's just me. – egmont Nov 13 '23 at 19:07
  • 1
    @egmont It could've been exported as an environment variable for example no excuses here. It could’ve been made available in many different more simple ways … and as I said, it’s a minor thing and gnome-terminal is a great app nonetheless. – Raffa Nov 13 '23 at 19:11
  • 1
    Env vars cannot be changed later on, while the profile can be switched. So an env var cannot reliably reflect the profile. And it would only solve half of the problem, the other half would still require going to dconf/gsettings. Also, presumably OP's goal is to make the setting during some automated install procedure, not necessarily running from gnome-terminal. After all, if already in gnome-terminal, opening the UI prefs and changing the setting there is presumably way more efficient than having to remember or look up and then type some commands. So no, this wouldn't have helped here. – egmont Nov 13 '23 at 19:24
  • 1
    @egmont I have to say that if you were a salesman, I would have bought whatever you’re trying to sell to me from your third comment :-D … You are very convincing in a good way … The thing is that I believe more options and shorter steps in maintaining a piece of software are essential, especially one that is both widely used and has been refined over the years … I get unhappy when all of a sudden I find myself looking for alternatives to my long used app just because it lacks a very trivial feature that I happened to have needed even once. This is merely an option after all. – Raffa Nov 13 '23 at 19:42
  • I'm not a salesman, but a former gome-terminal co-developer. There are already 3 layers where you can edit gnome-terminal's settings (dconf where you can change individual values or even do a full dump+edit+restore; gsettings which I'm not familiar with, and the UI). Should the project introduce a 4th solution, a command line one specific to gnome-terminal, with the aim of being slightly more simpler than dconf or gsettings, guessing all the things that users will want to do in 1 step instead of 2? Sounds utterly pointless to me, and also takes away development time from actual useful things. – egmont Nov 13 '23 at 20:50
  • @egmont Technically, these are 3 commands, not two. I am also using tr to remove the quotes from the id. You are absolutely correct in your assumption that I was looking for a non-interactive solution that can be used in automated install procedure, not necessarily running from gnome-terminal. Thank you for your work on gome-terminal, it's a great app. I understand that developers time is limited. – sotirov Nov 14 '23 at 06:13
  • What @Raffa suggest sounds like a nice quality of life feature. While doing my research on this topic, I found a lot of other posts where people are looking for similar solution to change other profile settings like: font, terminal size, colors, etc. – sotirov Nov 14 '23 at 06:15
  • I firmly disagree with you, guys. You find it inconvenient to strip off two apostrophes, so you'd prefer gnome-terminal to provide an explicit option for printing its default profile's ID. But then how about the desire for converting a profile name to its ID? How about other settings that print a string in single quotes? Or print a maybe-boolean without the "@mb" prefix? How about arrays, don't you want other output formats as well, e.g. one entry per line, without [] or '' or ,? How about getting a certain index only from an array? ... – egmont Nov 14 '23 at 11:36
  • ... And once you have these, you can perform half of your desired steps in gnome-terminal but have to resort to dconf/gsettings for the other half. Why not complete it? Also add operations like setting a property for all profiles, or all profiles except the ones listed in command line, because you have a conceptual problem with having to write any bit of shell script glue? Where to stop going down this rabbit hole? And then of course repeat it for every app, presumably in a consistent way, because you don't only want to configure gnome-terminal ... – egmont Nov 14 '23 at 11:38
  • ... It's absolutely unreasonable, and not because lack of developer time. Those very few people who wish to programatically edit the settings can already do that, using either dconf or gsettings. If you think having to add a tr is too much of inconvenience, then either adding one single new cmdline option for your particular use case, or adding hundreds of them for all possible similar use cases, are all wrong approaches, the right approach would be to ask dconf or gsettings developers to add such a command line option into their tools. – egmont Nov 14 '23 at 11:41