You are not logged in.

#1 2017-03-24 04:18:36

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

[solved] [???x?] find x and replace ? that is just before x

I am trying to get workspaces, from i3-msg, parse the output and send it to conky. So in current form it is something like this.

#!/bin/bash

i3-msg -t get_workspaces | jshon -a -e name -u -p -e focused -u -p -e urgent | xargs | sed "s/false false//g;s/true false/\${color green}@\$color/g;s/false true/\${color red}??\$color/g;s/true true/@/g"

which gives me this output

1:[T] ${color green}@$color 2:[B] ${color red}??$color

image.jpg

Where green "@" is used to mark workspace before the symbol as active.(red "??" is for urgent workspace)
What I want to do is instead of using @ with green color, mark the workspace with green color, that is

${color green}1:[T]$color

(as I described in title)

Last edited by Docbroke (2017-03-24 10:18:32)

Offline

#2 2017-03-24 08:53:19

parchd
Member
Registered: 2014-03-08
Posts: 421

Re: [solved] [???x?] find x and replace ? that is just before x

How about just not resetting the colour?

i.e.

sed "s/false false//g;s/true false/\${color green}/g;s/false true/\${color red}??\$color/g;s/true true/@/g"

Offline

#3 2017-03-24 09:24:31

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: [solved] [???x?] find x and replace ? that is just before x

That will give green color to all workspaces after the active workspace, this is not desired as active workspace can be first/second...or/last in the output.
Just to clarify here is the output of my current script after removing all 'sed' lines.

$ i3-msg -t get_workspaces | jshon -a -e name -u -p -e focused -u -p -e urgent | xargs
1:[T] true false 2:[B] false true 3:[M] false true

However this output will keep changing according to the situation (workspace in use)
true false = active workspace
false true = urgent workspace
false false = inactive workspace
true true = this is transient output (for a second) when user switches to urgent workspace

Offline

#4 2017-03-24 09:44:01

parchd
Member
Registered: 2014-03-08
Posts: 421

Re: [solved] [???x?] find x and replace ? that is just before x

Ah, I misunderstood the original post. I thought it was the one after the @ that needed to be green.
I don't think sed can do lookaheads, otherwise that would be a possible answer.

How about:

sed 's/\([0-9]:\[.\]\) true false/$color{green}\1$color/g'

Note: I've made the assumption that workspaces only have a single digit, and that only a single character appears in the square brackets.

Last edited by parchd (2017-03-24 09:45:41)

Offline

#5 2017-03-24 10:05:18

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: [solved] [???x?] find x and replace ? that is just before x

Yes this works perfect.
I was confused about how to bring previous workspace in replace output as I had no ideas about use of "\1" with sed.
Note: here is my final script. I did correct one typo in your suggestion. (use of { in color green)

#!/bin/bash

i3-msg -t get_workspaces | jshon -a -e name -u -p -e focused -u -p -e urgent | xargs | sed 's/\([0-9]:\[.\]\) true false/${color green}\1$color/g;s/false false//g;s/\([0-9]:\[.\]\) false true/${color red}\1$color/g;s/\([0-9]:\[.\]\) true true/${color green}\1$color/g'

image.jpg

thanks

Last edited by Docbroke (2017-03-24 10:07:27)

Offline

#6 2017-03-24 10:08:58

parchd
Member
Registered: 2014-03-08
Posts: 421

Re: [solved] [???x?] find x and replace ? that is just before x

Glad I could help smile Sorry about the typo.

Offline

Board footer

Powered by FluxBB