You are not logged in.
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
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)
Arch is home!
https://github.com/Docbroke
Offline
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
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
Arch is home!
https://github.com/Docbroke
Offline
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
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'
thanks
Last edited by Docbroke (2017-03-24 10:07:27)
Arch is home!
https://github.com/Docbroke
Offline
Glad I could help Sorry about the typo.
Offline