You are not logged in.

#1 2015-10-23 14:48:54

Matt3o
Member
From: Firenze, Italy
Registered: 2007-09-13
Posts: 177

lil help with lemonbar?

I'm trying to configure an openbox machine and I spent quite some time on the lemonbar. Since I mostly don't know what I'm doing I'd appreciate your feedback.

The whole thing can be found here http://pastebin.com/hLxCSeTp

This would be a preview http://i.imgur.com/MjRetBq.png

I'm sure it can be improved, maybe always using printf, but anyway, seems to work.

I created 3 main loops, the clock that updates every 10 seconds, the system (ram/cpu/temperature/...) updated every 3 secs and the amixer volume every 1 sec.

I was wondering if it is worth the effort, it would of course be easier to put everything into a single loop and update every sec or 0.5 (or even less). I'm sure I could also get rid of the named pipe in that scenario.

Am I doing it right? Any other suggestion?

thanks

Offline

#2 2015-10-23 15:34:17

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,544
Website

Re: lil help with lemonbar?

From my first look, I'd suggest using bash's built in conditional [[ ]] rather than the test binary [ ].  Also all the ifs can be removed from the volume function as the following does the same thing:

volume() {
	while true; do
	VOLUME=$(awk -F"[][%]" '/dB/ { print $2 }' <(amixer get Master))
	echo -n "V$C1"
	echo -n "VOLUME:$CE %{A:amixer set Master 4%-:}[%{A}"
	let n=$VOLUME/10+1;
	printf "%${n}s" | tr ' ' '='
	printf "$C1%$((10-${n}))s$CE" | tr ' ' '.'
	echo "%{A:amixer set Master 4%+:}]%{A}"
	sleep 1
	done
}

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2015-10-23 15:55:23

Matt3o
Member
From: Firenze, Italy
Registered: 2007-09-13
Posts: 177

Re: lil help with lemonbar?

thanks for the suggestions. I get an error on the

printf "$C1%$((10-${n}))s$CE" | tr ' ' '.'

line though. shouldn't the $C1 and $CE be escaped somehow?

Offline

#4 2015-10-23 16:42:47

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,544
Website

Re: lil help with lemonbar?

That depends what's in C1 and CE.  I didn't use your full script.  But looking back the % in C1 and CE will need to be escaped so it is not read as a format specifier by printf.  You might be able to do

printf "%$C1%((10-$n))s%$CE" | ...

Or you could do

printf "%s%((10-$n))s%s" "$C1" "" "$C3" | ...

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB