[locked]colr

Submitted scripts and programs
Forum rules
Your own work only.
User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

[locked]colr

Unread post by dkeg » Sat Mar 14, 2015 11:55 pm

Do you tend toward continuity between your terminal applications? With every xcolor change, you are left picking up the pieces elsewhere to ensure sycnchronicity? Or lets say you change your font and want to carry it over everywhere.

Simple demo of it in action

Work hard; Complain less

User avatar
Dr_Chroot
Alfalfa
Posts: 1100
Joined: Mon Jun 09, 2014 9:49 pm
Location: among the sagebrush
Contact:

Re: colr

Unread post by Dr_Chroot » Sun Mar 15, 2015 12:31 am

Simply astounding, dkeg. Thank you; I believe this tool shall invariably prove to be a great asset to the bbq as a collective :)
Fight internet censorship.
EFF | Tor Project | Bitcoin

"There have been times throughout American history where what is right is not the same as what is legal. Sometimes to do the right thing you have to break the law." - Edward Snowden

User avatar
stark
MILF
Posts: 521
Joined: Sat Sep 27, 2014 6:38 pm
Location: Arpanet
Contact:

Re: colr

Unread post by stark » Sun Mar 15, 2015 9:26 am

Excellent dkeg! Thanks so much for sharing colr.
If you can do it go ahead and do it, if you can't do it then don't even criticize it. - gingerdesu

User avatar
wuxmedia
Grasshopper
Posts: 6063
Joined: Wed Oct 17, 2012 11:32 am
Location: FR
Contact:

Re: colr

Unread post by wuxmedia » Sun Mar 15, 2015 11:59 am

nice theme-ing tool. kudos dkeg
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: colr

Unread post by dkeg » Sun Mar 15, 2015 1:28 pm

Glad to hear.

Work hard; Complain less

User avatar
stark
MILF
Posts: 521
Joined: Sat Sep 27, 2014 6:38 pm
Location: Arpanet
Contact:

Re: colr

Unread post by stark » Mon Apr 27, 2015 4:16 pm

So dkeg, as you mentioned you wanted a cleaner version of colr, i *ripped off* code from z3bra's cdump and whipped two versions of the function style2 and it pulls the colors from `xrdb -query` so saves you editing the script everytime you change colors :)

EDIT: Remove seq. Thanks pidsley :D

Without array but more readable:

Code: Select all

getcolf ()
{
	for NUM in {0..7}; do
		colf=$(xrdb -query | grep "^\*color${NUM}:" | cut -d '#' -f2)
		printf "$colf\n"
	done
}

getcolb ()
{
	for NUM in {0..7}; do
		colb=$(xrdb -query | grep "^\*color$((${NUM} + 8)):" | cut -d '#' -f2)
		printf "$colb\n"
	done
}

read bg fg <<< $(xrdb -query | grep -E "(back|fore)ground" | cut -d '#' -f2)

read blkf redf grnf ylwf bluf magf cynf whtf <<< $(getcolf)
read blkb redb grnb ylwb blub magb cynb whtb <<< $(getcolb)

#echo "$bg $fg"
#echo "$blkf $redf $grnf $ylwf $bluf $magf $cynf $whtf"
#echo "$blkb $redb $grnb $ylwb $blub $magb $cynb $whtb"
exit 0

With an array:

Code: Select all

getcolf ()
{
	for NUM in {0..7}; do
		colf[$NUM]=$(xrdb -query | grep "^\*color${NUM}:" | cut -d '#' -f2)
		printf "${colf[$NUM]}\n"
	done
}

getcolb ()
{
	for NUM in {0..7}; do
		colb[$NUM]=$(xrdb -query | grep "^\*color$((${NUM} + 8)):" | cut -d '#' -f2)
		printf "${colb[$NUM]}\n"
	done
}
If you can do it go ahead and do it, if you can't do it then don't even criticize it. - gingerdesu

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: colr

Unread post by dkeg » Tue Apr 28, 2015 12:27 am

pulls the colors from `xrdb -query` so saves you editing the script everytime you change colors :)
Thank you stark, but I think there requires some clarification. My original script is automatic. In various scripts, I am sourcing this script and setting color/font variables.
so if I change my .Xresource file; whatever file that is sourcing the colr script automatically with no manual intervention. Same if I change font. So all popup notifications and dmenu follow suit. The only manual piece is killing and restarting bar, which I set as an alias - 'rebar'.

You posted some interesting options stark, but I'm not sure if this is the right solution. Consolidating the loop into all colors, 0-15, and passing into a single array is what I'm looking to do.

Work hard; Complain less

User avatar
stark
MILF
Posts: 521
Joined: Sat Sep 27, 2014 6:38 pm
Location: Arpanet
Contact:

Re: colr

Unread post by stark » Tue Apr 28, 2015 6:44 am

^ Apologies, for the misstatement. The thing is I have very messy configs, ( even the color files have some commented out colors ) so this works for me. I hope this doesn't seem to be too offensive or aggressive just expressing how I handle my messy configs :)
If you can do it go ahead and do it, if you can't do it then don't even criticize it. - gingerdesu

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: colr

Unread post by dkeg » Tue Apr 28, 2015 11:00 am

well there my friend, use this as motivation to organize!

Work hard; Complain less

User avatar
stark
MILF
Posts: 521
Joined: Sat Sep 27, 2014 6:38 pm
Location: Arpanet
Contact:

Re: colr

Unread post by stark » Wed Apr 29, 2015 7:37 am

Well looks like this and the above method works with both style1 and style2 ! :D
Everything is in an array, bg is in 16 and fg is in 17.

EDIT: Sourcing didn't work so added a case, so no need for sourcing, just put colr in $HOME/bin or any $PATH.

Code: Select all

#!/bin/bash
getcol ()
{
	for NUM in {0..15}
	do
		col[$NUM]=$(xrdb -query | grep "^\*color${NUM}:" | cut -d '#' -f2)
	done

	read col[16] col[17] <<< $(xrdb -query | grep -E "(back|fore)ground" | cut -d '#' -f2)
}

getcol
	case $1 in
		blkf) echo "${col[0]}";;
		redf) echo "${col[1]}";;
		grnf) echo "${col[2]}";;
		ylwf) echo "${col[3]}";;
		bluf) echo "${col[4]}";;
		magf) echo "${col[5]}";;
		cynf) echo "${col[6]}";;
		whtf) echo "${col[7]}";;
		blkb) echo "${col[8]}";;
		redb) echo "${col[9]}";;
		grnb) echo "${col[10]}";;
		ylwb) echo "${col[11]}";;
		blub) echo "${col[12]}";;
		magb) echo "${col[13]}";;
		cynb) echo "${col[14]}";;
		whtb) echo "${col[15]}";;
		  bg) echo "${col[16]}";;
		  fg) echo "${col[17]}";;
		   *) echo "${col[*]}";;
	esac
exit 0
Example usage in dmenu scripts:

Code: Select all

nb=$(colr bg)
sb=$(colr bg)
nf=$(colr whtf)
sf=$(colr fg)

DMENU="/usr/bin/dmenu -nb '#$nb' -sb '#$sb' -nf '#$nf' -sf '#$sf'"
Last edited by stark on Thu Apr 30, 2015 7:11 am, edited 2 times in total.
If you can do it go ahead and do it, if you can't do it then don't even criticize it. - gingerdesu

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: colr

Unread post by dkeg » Wed Apr 29, 2015 11:29 am

Looks nice.
Thank you.

Work hard; Complain less

User avatar
stark
MILF
Posts: 521
Joined: Sat Sep 27, 2014 6:38 pm
Location: Arpanet
Contact:

Re: colr

Unread post by stark » Wed Apr 29, 2015 4:45 pm

^ Actually Thank You for this overall idea and ofcourse this is possible due to z3bra's cdump and memory script so Thank You z3bra :)
If you can do it go ahead and do it, if you can't do it then don't even criticize it. - gingerdesu

User avatar
stark
MILF
Posts: 521
Joined: Sat Sep 27, 2014 6:38 pm
Location: Arpanet
Contact:

Re: colr

Unread post by stark » Sun May 10, 2015 4:27 pm

An ugly, faster version:

Code: Select all

#!/bin/sh

bg() { xrdb -query | grep "background" | cut -d '#' -f2;}
fg() { xrdb -query | grep "foreground" | cut -d '#' -f2;}

blkf() { xrdb -query | grep "^\*color0:" | cut -d '#' -f2;  }
redf() { xrdb -query | grep "^\*color1:" | cut -d '#' -f2;  }
grnf() { xrdb -query | grep "^\*color2:" | cut -d '#' -f2;  }
ylwf() { xrdb -query | grep "^\*color3:" | cut -d '#' -f2;  }
bluf() { xrdb -query | grep "^\*color4:" | cut -d '#' -f2;  }
magf() { xrdb -query | grep "^\*color5:" | cut -d '#' -f2;  }
cynf() { xrdb -query | grep "^\*color6:" | cut -d '#' -f2;  }
whtf() { xrdb -query | grep "^\*color7:" | cut -d '#' -f2;  }
blkb() { xrdb -query | grep "^\*color8:" | cut -d '#' -f2;  }
redb() { xrdb -query | grep "^\*color9:" | cut -d '#' -f2;  }
grnb() { xrdb -query | grep "^\*color10:" | cut -d '#' -f2; }
ylwb() { xrdb -query | grep "^\*color11:" | cut -d '#' -f2; }
blub() { xrdb -query | grep "^\*color12:" | cut -d '#' -f2; }
magb() { xrdb -query | grep "^\*color13:" | cut -d '#' -f2; }
cynb() { xrdb -query | grep "^\*color14:" | cut -d '#' -f2; }
whtb() { xrdb -query | grep "^\*color15:" | cut -d '#' -f2; }


	case $1 in
		blkf) printf $(blkf);;
		redf) printf $(redf);;
		grnf) printf $(grnf);;
		ylwf) printf $(ylwf);;
		bluf) printf $(bluf);;
		magf) printf $(magf);;
		cynf) printf $(cynf);;
		whtf) printf $(whtf);;
		blkb) printf $(blkb);;
		redb) printf $(redb);;
		grnb) printf $(grnb);;
		ylwb) printf $(ylwb);;
		blub) printf $(blub);;
		magb) printf $(magb);;
		cynb) printf $(cynb);;
		whtb) printf $(whtb);;
		  bg) printf $(bg);;
		  fg) printf $(fg);;
		   *) printf "Unknown Option";;
	esac
exit 0
If you can do it go ahead and do it, if you can't do it then don't even criticize it. - gingerdesu

pidsley
Hermit
Posts: 2513
Joined: Wed Oct 17, 2012 12:31 pm

Re: colr

Unread post by pidsley » Sun May 10, 2015 4:43 pm

^ Why query all the colors every time you call the script, if you don't do anything except print one? Get rid of the query block at the top, and just do the query in the case statement.

Code: Select all

case $1 in
      blkf) xrdb -query | grep "^\*color0:" | cut -d '#' -f2;;
      redf) xrdb -query | grep "^\*color1:" | cut -d '#' -f2;;
      bg) xrdb -query | grep "background" | cut -d '#' -f2;;
and so on...

You could also use awk to avoid using two pipes to call grep and cut.

Code: Select all

     redf) xrdb -query | awk -F# '/^\*color1:/ {print $2}';;
Not trying to be annoying, just trying to help.
"The prettier the user interface, and the fewer odd replies the system allows you to make, the dumber you once appeared in the mind of the designer." -- Ellen Ullman

User avatar
stark
MILF
Posts: 521
Joined: Sat Sep 27, 2014 6:38 pm
Location: Arpanet
Contact:

Re: colr

Unread post by stark » Sun May 10, 2015 5:11 pm

^ Awesome ! I Need to learn awk properly.

Oh and it's not querying all the colors at all according to `bash -x colr bg`. If I make them variables then it queries all the colors no matter the argument which is why I have kept them as functions. I learned this today. I just wanted to keep the case statements clean otherwise I would've definitely kept them in the case statements.

And please never hesitate to post corrections / suggestions / improvements, I'm always looking forward to learn from others :)
If you can do it go ahead and do it, if you can't do it then don't even criticize it. - gingerdesu

pidsley
Hermit
Posts: 2513
Joined: Wed Oct 17, 2012 12:31 pm

Re: colr

Unread post by pidsley » Sun May 10, 2015 5:16 pm

^ Oh you're right (about the functions). Sorry.

As for awk, just remember it can grep/sed/cut (and much more) and any time you process text try to find a way to awk it -- this is how I learn (not "learned" because I keep finding new ways to use it ;)
"The prettier the user interface, and the fewer odd replies the system allows you to make, the dumber you once appeared in the mind of the designer." -- Ellen Ullman

User avatar
stark
MILF
Posts: 521
Joined: Sat Sep 27, 2014 6:38 pm
Location: Arpanet
Contact:

Re: colr

Unread post by stark » Sun May 10, 2015 5:29 pm

^ And when you're almost done learning awk, someone comes along and says "sed it !" - That's what she sed.

Not editing the above code as anyone can learn from my mistake :)

Code: Select all

#!/bin/sh

bg() { xrdb -query | awk -F# '/background/ {print $2}';}
fg() { xrdb -query | awk -F# '/foreground/ {print $2}';}

blkf() { xrdb -query | awk -F# '/^\*color0:/ {print $2}';  }
redf() { xrdb -query | awk -F# '/^\*color1:/ {print $2}';  }
grnf() { xrdb -query | awk -F# '/^\*color2:/ {print $2}';  }
ylwf() { xrdb -query | awk -F# '/^\*color3:/ {print $2}';  }
bluf() { xrdb -query | awk -F# '/^\*color4:/ {print $2}';  }
magf() { xrdb -query | awk -F# '/^\*color5:/ {print $2}';  }
cynf() { xrdb -query | awk -F# '/^\*color6:/ {print $2}';  }
whtf() { xrdb -query | awk -F# '/^\*color7:/ {print $2}';  }
blkb() { xrdb -query | awk -F# '/^\*color8:/ {print $2}';  }
redb() { xrdb -query | awk -F# '/^\*color9:/ {print $2}';  }
grnb() { xrdb -query | awk -F# '/^\*color10:/ {print $2}'; }
ylwb() { xrdb -query | awk -F# '/^\*color11:/ {print $2}'; }
blub() { xrdb -query | awk -F# '/^\*color12:/ {print $2}'; }
magb() { xrdb -query | awk -F# '/^\*color13:/ {print $2}'; }
cynb() { xrdb -query | awk -F# '/^\*color14:/ {print $2}'; }
whtb() { xrdb -query | awk -F# '/^\*color15:/ {print $2}'; }

	case $1 in
		blkf) printf $(blkf);;
		redf) printf $(redf);;
		grnf) printf $(grnf);;
		ylwf) printf $(ylwf);;
		bluf) printf $(bluf);;
		magf) printf $(magf);;
		cynf) printf $(cynf);;
		whtf) printf $(whtf);;
		blkb) printf $(blkb);;
		redb) printf $(redb);;
		grnb) printf $(grnb);;
		ylwb) printf $(ylwb);;
		blub) printf $(blub);;
		magb) printf $(magb);;
		cynb) printf $(cynb);;
		whtb) printf $(whtb);;
		  bg) printf $(bg);;
		  fg) printf $(fg);;
		   *) printf "Unknown Option";;
	esac
exit 0
If you can do it go ahead and do it, if you can't do it then don't even criticize it. - gingerdesu

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: colr

Unread post by dkeg » Fri May 15, 2015 1:03 pm

colr is dead. Start a new thread.

Work hard; Complain less

Locked