[locked]colr
Forum rules
Your own work only.
Your own work only.
[locked]colr
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
Simple demo of it in action
Work hard; Complain less
- Dr_Chroot
- Alfalfa
- Posts: 1100
- Joined: Mon Jun 09, 2014 9:49 pm
- Location: among the sagebrush
- Contact:
Re: colr
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
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
Re: colr
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
Re: colr
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:
With an array:
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
Re: colr
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.pulls the colors from `xrdb -query` so saves you editing the script everytime you change colors :)
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
Re: colr
^ 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
Re: colr
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.
Example usage in dmenu scripts:
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
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
Re: colr
^ 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
Re: colr
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
Re: colr
^ 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.
and so on...
You could also use awk to avoid using two pipes to call grep and cut.
Not trying to be annoying, just trying to help.
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;;
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}';;
Re: colr
^ 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 :)
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
Re: colr
^ 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 ;)
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 ;)
Re: colr
^ 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 :)
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