Closed luisdavim closed 8 years ago
Works for me.
Double check upgrading didn't break awk
.
Hi,
I got it working with these changes:
diff --git a/.tmux.conf b/.tmux.conf
index 2e96dcf..4ae9e5a 100644
--- a/.tmux.conf
+++ b/.tmux.conf
@@ -319,7 +319,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration'
# palette=$(echo "$palette" | awk -v n="$battery_bar_length" '{ for (i = 0; i < n; ++i) printf $(1 + (i * NF / n))" " }')
# eval set -- "$palette"
#
-# full=$(awk "BEGIN { printf \"%.0f\", ($charge) * $battery_bar_length }")
+# full=$(awk 'BEGIN { printf "%.0f", ($charge) * $battery_bar_length }')
# battery_bar="#[bg=$battery_bg]"
# # shellcheck disable=SC2046
# [ "$full" -gt 0 ] && \
@@ -337,7 +337,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration'
# battery_empty_fg=$2
# battery_bg=$3
#
-# full=$(awk "BEGIN { print \"%d\" ($charge) * $battery_bar_length }")
+# full=$(awk 'BEGIN { printf "%d", ($charge) * $battery_bar_length }')
# [ x"$battery_bg" != x"none" ] && \
# battery_bar="#[bg=$battery_bg]"
# [ "$full" -gt 0 ] && \
@@ -348,6 +348,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration'
# battery_bar="$battery_bar#[fg=$battery_empty_fg]"
# fi
#
+# battery_vbar_bg='none'
# if echo "$battery_vbar_palette" | grep -q -E '^heat|gradient(,[#a-z0-9]{7,9})?$'; then
# # shellcheck disable=SC2086
# { set -f; IFS=,; set -- $battery_vbar_palette; unset IFS; set +f; }
I disagree with the first two changes. I don't understand how it can even work since $charge
won't even be expanded inside single quotes
it's expanded by awk not bash
but the problem is not the quotes, it's the print instead of printf and the battery_vbar_bg only being initialized inside of the if.
This also works:
diff --git a/.tmux.conf b/.tmux.conf
index 2e96dcf..55c0732 100644
--- a/.tmux.conf
+++ b/.tmux.conf
@@ -337,7 +337,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration'
# battery_empty_fg=$2
# battery_bg=$3
#
-# full=$(awk "BEGIN { print \"%d\" ($charge) * $battery_bar_length }")
+# full=$(awk "BEGIN { printf \"%d\", ($charge) * $battery_bar_length }")
# [ x"$battery_bg" != x"none" ] && \
# battery_bar="#[bg=$battery_bg]"
# [ "$full" -gt 0 ] && \
@@ -348,6 +348,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration'
# battery_bar="$battery_bar#[fg=$battery_empty_fg]"
# fi
#
+# battery_vbar_bg='none'
# if echo "$battery_vbar_palette" | grep -q -E '^heat|gradient(,[#a-z0-9]{7,9})?$'; then
# # shellcheck disable=SC2086
# { set -f; IFS=,; set -- $battery_vbar_palette; unset IFS; set +f; }
It's expanded by awk not bash
NO. The way it works is it's expanded by Bash. Then expansion is given to Awk. Just try it for yourself...
#!/bin/sh
charge="50 / 100"
battery_bar_length="10"
set -x
full=$(awk "BEGIN { printf \"%.0f\", ($charge) * $battery_bar_length }")
set +x
echo "$full"
echo ---
set -x
full=$(awk 'BEGIN { printf "%.0f", ($charge) * $battery_bar_length }')
set +x
echo "$full"
gives
$ ./test.sh
++ awk 'BEGIN { printf "%.0f", (50 / 100) * 10 }'
+ full=5
+ set +x
5
---
++ awk 'BEGIN { printf "%.0f", ($charge) * $battery_bar_length }'
+ full=0
+ set +x
0
Also, it has to be printf
to truncate the decimal part
Which version of awk
are you using?
$ awk -V
GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.5, GNU MP 6.1.1)
Again, it works for me with a stock 16.10 installed.
$ vagrant init ubuntu/yakkety64; vagrant up --provider virtualbox
$ vagrant ssh
$ cd
$ git clone https://github.com/gpakosz/.tmux.git
$ ln -s .tmux/.tmux.conf
$ tmux
but I think you are right, I get the same result with the test script you pasted above. And I think that with my first diff I would always get a full bar. Use my second diff.
but that line should have printf instead of a print:
awk "BEGIN { print \"%d\" (50) * 100 }"
returns %d5000
I think the difference is my tmux.conf.local you must be landing on the part the has:
full=$(awk "BEGIN { printf \"%.0f\", ($charge) * $battery_bar_length }")
and I'm landing on the elif where it has the:
full=$(awk "BEGIN { printf \"%d\", ($charge) * $battery_bar_length }")
After upgrading my ubuntu I've also made some changes to my .tmux.conf.local and that might have triggered the problem, not the upgrade.
Try without a ~/.tmux.conf.local
.
Also look around where tmux_conf_battery_bar_length
is defined in your buggy .tmux.conf.local
file.
My ~/.tmux.conf.local is valid and tmux_conf_battery_bar_length is set to 5. The problem is that on line 340 you should have a printf instead of a print and that battery_vbar_bg is only set if you are using heat or gradient. Line 340 is also never used if you use heat or gradient.
With the default ~/.tmux.conf.local everything works because you never hit that part of the code.
Can you tell me which palette you're using then so that I can understand the problem in detail on my side please?
I'm using:
tmux_conf_battery_vbar_palette='#d70000,#ff5f00,#5fff00'
you can see my full ~/.tmux.conf.local here: https://github.com/luisdavim/dotfiles/blob/master/files/tmux.conf.local
the battery status freezes to the last state after you apply my ~/.tmux.conf.local, it disappears if you reboot afterwards and starts working again if you apply the changes from my second diff.
Thanks for helping debugging this 👍
No problem :)
Meh, force pushed as I forgot to silence the linter :(
since you are updating stuff, can you add a .gitignore file containing:
plugins/
I use some plugins and I keep them in ~/.tmux the same as this...
I could but doesn't that mean you should clone my configuration elsewhere?
In fact, I think it's a better idea you add ~/.tmux/plugins
to a global ignore file, see https://git-scm.com/docs/gitignore
Hi,
I've just upgraded my ubuntu installation from 16.04 to 16.10 and the battery status is now missing, running:
Returns:
returns 97.