Return which rc file tint2is using

Hi
I am playing with bash scripts
could someone tell me how I would return which .rc is running in tint2, please?

Usually the config file for tint2 is:

~/.config/tint2/tint2rc

3 Likes

If you want to pimp it put @leigh

https://wiki.archlinux.org/title/Tint2

Thanks, but what I mean is how can I obtain that info in a bash script, or in temrinal?

the Openbox menu > preferences > tint2 > running Tint2s gets it somehow:

leigh@archlabs ~ % al-tint2-pipemenu
<openbox_pipe_menu>
 <item label="Tint2Conf">
   <action name="Execute">
     <command>tint2conf</command>
   </action>
 </item>
 <item label="Restart Tint2">
   <action name="Execute">
     <command>al-tint2restart</command>
   </action>
 </item>
 <item label="Stop Tint2">
   <action name="Execute">
     <command>pkill tint2</command>
   </action>
 </item>
<separator/>
<menu id="RunningTint2" label="Running Tint2s">
 <item label="/ArchLabs">
   <action name="Execute">
     <command>exo-open /home/leigh/.config/tint2/ArchLabs.tint2rc</command>
   </action>
 </item>
</menu>
</openbox_pipe_menu>

Then when I run my simple Bash Script for my VirtualBox keybind (I am moving the panel when VB opens as I use it in fullscreen and it hides the panel)

#!/bin/bash
pkill tint2 
tint2 -c /home/leigh/.config/tint2/ArchLabsBottomMonitor2.tint2rc
virtualbox

I get:


leigh@archlabs ~ % al-tint2-pipemenu
<openbox_pipe_menu>
 <item label="Tint2Conf">
   <action name="Execute">
     <command>tint2conf</command>
   </action>
 </item>
 <item label="Restart Tint2">
   <action name="Execute">
     <command>al-tint2restart</command>
   </action>
 </item>
 <item label="Stop Tint2">
   <action name="Execute">
     <command>pkill tint2</command>
   </action>
 </item>
<separator/>
<menu id="RunningTint2" label="Running Tint2s">
 <item label="/ArchLabsBottomMonitor2">
   <action name="Execute">
     <command>exo-open /home/leigh/.config/tint2/ArchLabsBottomMonitor2.tint2rc</command>
   </action>
 </item>
</menu>
</openbox_pipe_menu>

so something must ‘see’ what tint2 is running and then write it to the pipe-menu, or something similar.

I think :smiley:

EDIT: ah, perhaps I can work it out from here

pgrep -a tint2, now I just need to learn sed or awk or something perhaps

Getting there:

leigh@archlabs ~ % pgrep -a tint2                       
7148 tint2 -c /home/leigh/.config/tint2/ArchLabsBottomMonitor2.tint2rc
leigh@archlabs ~ % pgrep -a tint2 | sed 's/^.*tint2\///'
ArchLabsBottomMonitor2.tint2rc

leigh@archlabs ~ % pgrep -a tint2 | sed 's/^.*\///'
ArchLabsBottomMonitor2.tint2rc
1 Like

Sorry I don t know these commands enough for your request or whatever it s called .

How bout the command that @PackRat posted above.

1 Like

I think I got it!

In my auto start I have:

# start the panel
tint2 -c /home/leigh/.config/tint2/ArchLabs.tint2rc &

so …

leigh@archlabs ~ % pgrep -a tint2 | sed 's/^.*\///'
ArchLabs.tint2rc

Then I ran my run my script to change the tint2rc and …


leigh@archlabs ~ % pgrep -a tint2 | sed 's/^.*\///'
ArchLabsBottomMonitor2.tint2rc

I’m sure there are more elegant ways but at least it works

Thanks for attention @altman

2 Likes

So you want to kill the default tint2 panel running on Monitor-1 and start a tint2 panel on Monitor-2 so that vmware can be fullscreen on Monitor-1?

This work for you:

#!/bin/sh
killall -q tint2 ; tint2 -c $HOME/.config/tint2/tint2fboxrc &

vmware &

change the path and name of the tint2 configuration file and use the correct command to start vmawre.

3 Likes

Yes, exactly, but I was trying to toggle between one tint2 and the other as well, hence the need to find which one was running

I was going to have one keybind to swap tint2’s, and another for Virtualbox

Then I found this on Reddit which works for toggling monitor by rewriting to the rc file and restarting from what I can gather (No idea what -SIGUSR1 means tho :smiley: )

@natemaia also suggested to me a similar approach when I was playing with toggling between openbox and i3


sed -i -r 's/(panel_monitor\ \=\ )0/\11/;t;s/(panel_monitor\ \=\ )1/\10/' ~/.config/tint2/ArchLabs.tint2rc
killall -SIGUSR1 tint2 -c /home/leigh/.config/tint2/ArchLabs.tint2rc

but havent quite got it to work for top or bottom yet - since I need to investigate how it works - I dont understand the 11 and 10 in there … yet

sed -i -r 's/(panel_position\ \=\ )top/\11/;t;s/(panel_position\ \=\ )bottom/\10/' ~/.config/tint2/ArchLabs.tint2rc;

Doesnt work, I think because the 11 and 10 are not relevant to top and bottom as they were to 0 and 1

But its fun trying - I will get there

For now I just permanently moved my panel to the bottom of my lower monitor which solves everything most elegantly :rofl: and maybe I will stick with that, but am continuing to try to find the above solution as much out of pig-headed stubbornness as anything - and its fun learning

1 Like

SIGUSR1 is one of the user signals that can be used by a program however it likes, most use it as a restart signal. See here for more info Miscellaneous Signals (The GNU C Library)

Your sed commands look like a lot of unnecessary backslashes, but I may be wrong.

EDIT: I was wrong and totally missed the -r flag, my command below won’t work with this flag but his make more sense to me now. Personally I would just use -i to actually modify the file and avoid -r it just makes things even more confusing.

The 11 and 10 you’re referring to are interpreted as \1 a capture followed by 0 or 1. Regex capture groups allow referring back to them for later use, rather than try to explain it an example will do a better job

echo "panel_position = top center horizontal" |
        sed 's/\(panel_position = \)top/\1bottom/'
# output
panel_position = bottom center horizontal

First we go into substitute mode with s/pattern/replace/
then we make a capture group with \(panel_position = \), the backslashes are needed otherwise it will be a literal (). top is not in the capture group and what we’re really looking to replace.
With the pattern done we move on to the replace, since we captured the whole match and we’re not planning on replacing it we use it with \1 followed by our replacement bottom and we’re done.

When using sed and trying to figure out the command I always use it with no flags, this way you don’t actually modify the file but get the results out in the terminal so you can check for errors and rinse/repeat until you’re happy with it, then add the -i flag to actually do the modification.

5 Likes

You might want to head over to the Lilidog forum and let @sleekmason know what your trying to do. @sleekmason has written a lot of scripts that toggle conky layouts and tint2. He may have something you can use as a base.

@natemaia - good info.

4 Likes

Thanks, that helped me understand

Got it to work :smile:

sed -i -r 's/(panel_monitor\ \=\ )1/\12/;t;s/(panel_monitor\ \=\ )2/\11/' ~/.config/tint2/ArchLabs.tint2rc
sed -i -r 's/(panel_position\ \=\ )top/\1bottom/;t;s/(panel_position\ \=\ )bottom/\1top/' ~/.config/tint2/ArchLabs.tint2rc
killall -SIGUSR1 tint2 -c /home/leigh/.config/tint2/ArchLabs.tint2rc

And following your comments about not using the r flag (I will look that up tomorrow LOL) and following your example as a template, the following also works :smiley:

#!/bin/bash

sed -i 's/\(panel_monitor = \)1/\12/;t;s/\(panel_monitor = \)2/\11/' ~/.config/tint2/ArchLabs.tint2rc

sed -i 's/\(panel_position = \)top/\1bottom/;t;s/\(panel_position = \)bottom/\1top/' ~/.config/tint2/ArchLabs.tint2rc

killall -SIGUSR1 tint2 -c /home/leigh/.config/tint2/ArchLabs.tint2rc

as does


killall -q tint2 ; tint2 -c $HOME/.config/tint2/ArchLabs.tint2rc &
2 Likes

I wouldn’t say don’t use it, like above your commands would have to be modified to work without it but the flag uses extended regex which most folks don’t understand or need for most cases, it can also make some things complex that would otherwise be simple.

2 Likes

I looked here

t label

(test) Branch to label only if there has been a successful substitution since the last input line was read or conditional branch was taken. The label may be omitted, in which case the next cycle is started.

6.4.1 Branching and Cycles

The b,t and T commands can be followed by a label (typically a single letter). Labels are defined with a colon followed by one or more letters (e.g. ‘:x’). If the label is omitted the branch commands restart the cycle.

but cant quite understand what the t does.
I cant see any label in the form ':x and dont really know what ‘restarts the cycle’ means

Does the t stop the sed command going on the the second part if the first part already made the change , to stop it changing it back again?

I think so, to be honest I’m no sed wizard myself so I generally keep things in my realm of know-how.
As far as I can tell it’s doing one of two substitutions based on whether the first pattern matched, like a toggle switch of sorts.

The manual goes on to state

3.6 Commands for sed gurus

In most cases, use of these commands indicates that you are probably better off programming in something like awk or Perl. But occasionally one is committed to sticking with sed, and these commands can enable one to write quite convoluted scripts.

The branch commands are in this section and personally I think they’re right, I would turn to awk myself. It’s included in all *nix systems and allows more control and “proper” programming when you want something a bit more complex than basic search/replace (though it can do this fine as well)

Here’s what I would use

#!/bin/bash

awk '
/^panel_monitor/ { $3 = ($3 = 1) ? 2 : 1 }
/^panel_position/ { $3 = ($3 = "top") ? "bottom" : "top" }; 1
' ~/.config/tint2/ArchLabs.tint2rc > /tmp/tint2rc &&
	mv /tmp/tint2rc ~/.config/tint2/ArchLabs.tint2rc

Could be just me but this is a lot easier to understand what is going on and make changes.

2 Likes

Thanks @natemaia

That looks easier to follow

But I need to look at awk more as it only seems to move in one direction, not toggle

It will be good for me to work it out myself.

1 Like

This bit here is the toggle ($3 = 1) ? 2 : 1
which is a condensed if that toggles the third field between 1 and 2.
It’s called a ternary operator if your interested in looking it up but simplified it is

TRUE/FALSE ? TRUE : FALSE

Which could also be done (in awk) as

if ($3 = 1) {
    $3 = 2;
} else {
    $3 = 1;
}

But that’s a lot of noise for a simple branch.

Have fun :smiley:

1 Like

Thanks @natemaia
I am having fun :smiley:
Reminds me of being a teenager playing with my ZX81, but its all not so basic these days