You are not logged in.
Pages: 1
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
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
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
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
Pages: 1