3

Gnome Terminal allows to have different profiles. Is it possible to get the profile name under which that terminal started from the command line?

2

This doesn't seem to be possible, however you can find out the default terminal title, so all you need to do to distinguish between tabs or profiles is to configure different default titles.

The control sequence ESC [ 2 1 t asks the terminal to insert its title on the terminal input stream. (See Xterm control sequences for more information about escape sequences for xterm and similar programs). Specifically, the terminal (if it supports this feature; gnome-terminal does) responds with ESC ] l title ESC \.

Here's a bash function that sets the variable whose name is passed as the first argument to the xterm title, if available. It times out after one second if the terminal doesn't support the feature, and returns a non-zero error code.

read_xterm_title () {
  # Clear IFS so that read doesn't do any word splitting.
  local IFS= read_xterm_title_header=
  # $1 is expected to be a parameter name. Do a crude format check.
  if [[ $1 = '' || $1 = *[!0-9_A-Za-z]* ]]; then return 120; fi
  eval $1=
  # Expect "ESC ] l title ESC \\"
  read -p $'\e[21t' -s -t 1 -r -n 3 read_xterm_title_header &&
  [[ $read_xterm_title_header = $'\e]l' ]] &&
  read -p '' -s -t 1 -r -d $'\e' $1 &&
  read -s -t 1 -r -n 1
}
read_xterm_title title
case $title in ...
|improve this answer|||||
1

You used to be able to do this with gconftool2 and then with dconf and now you have to do with gsettings but it's a GUID, so something like this may be what you want:

gsettings get org.gnome.Terminal.ProfilesList default | tr -d \'

and in context of setting a variable:

gsettings set org.gnome.Terminal.Legacy.Profile:/org/gnome/terminal/legacy/profiles:/:$(gsettings get org.gnome.Terminal.ProfilesList default | tr -d \')/ cursor-blink-mode off

per https://wiki.archlinux.org/index.php/GNOME/Tips_and_tricks

|improve this answer|||||
0

This seems to do the trick:

gsettings get org.gnome.Terminal.Legacy.Profile:$dconfdir/":"$1/ visible-name

Stolen from here.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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