Code Monkey home page Code Monkey logo

Comments (25)

gpakosz avatar gpakosz commented on May 17, 2024

Works for me.

image

from .tmux.

gpakosz avatar gpakosz commented on May 17, 2024

Double check upgrading didn't break awk.

from .tmux.

luisdavim avatar luisdavim commented on May 17, 2024

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; }

from .tmux.

gpakosz avatar gpakosz commented on May 17, 2024

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

from .tmux.

luisdavim avatar luisdavim commented on May 17, 2024

it's expanded by awk not bash

from .tmux.

luisdavim avatar luisdavim commented on May 17, 2024

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.

from .tmux.

luisdavim avatar luisdavim commented on May 17, 2024

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; }

from .tmux.

gpakosz avatar gpakosz commented on May 17, 2024

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

from .tmux.

gpakosz avatar gpakosz commented on May 17, 2024

Which version of awk are you using?

from .tmux.

luisdavim avatar luisdavim commented on May 17, 2024
$ awk -V
GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.5, GNU MP 6.1.1)

from .tmux.

gpakosz avatar gpakosz commented on May 17, 2024

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

from .tmux.

luisdavim avatar luisdavim commented on May 17, 2024

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.

from .tmux.

luisdavim avatar luisdavim commented on May 17, 2024

but that line should have printf instead of a print:

awk "BEGIN { print \"%d\" (50) * 100 }"

returns %d5000

from .tmux.

luisdavim avatar luisdavim commented on May 17, 2024

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.

from .tmux.

gpakosz avatar gpakosz commented on May 17, 2024

Try without a ~/.tmux.conf.local.

Also look around where tmux_conf_battery_bar_length is defined in your buggy .tmux.conf.local file.

from .tmux.

luisdavim avatar luisdavim commented on May 17, 2024

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.

from .tmux.

gpakosz avatar gpakosz commented on May 17, 2024

Can you tell me which palette you're using then so that I can understand the problem in detail on my side please?

from .tmux.

luisdavim avatar luisdavim commented on May 17, 2024

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

from .tmux.

luisdavim avatar luisdavim commented on May 17, 2024

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.

from .tmux.

gpakosz avatar gpakosz commented on May 17, 2024

Thanks for helping debugging this 👍

from .tmux.

luisdavim avatar luisdavim commented on May 17, 2024

No problem :)

from .tmux.

gpakosz avatar gpakosz commented on May 17, 2024

Meh, force pushed as I forgot to silence the linter :(

from .tmux.

luisdavim avatar luisdavim commented on May 17, 2024

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...

from .tmux.

gpakosz avatar gpakosz commented on May 17, 2024

I could but doesn't that mean you should clone my configuration elsewhere?

from .tmux.

gpakosz avatar gpakosz commented on May 17, 2024

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

from .tmux.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.