BTS

Issue1333

Title grml zshrc used on Linux 3.2 (e.g. Wheezy) shows before each prompt "batterylinux:6: no such file or directory: /sys/class/power_supply/BAT0/capacity"
Priority wish Status resolved
Superseder Nosy List abe
Assigned To Topics configs, grml-etc-core, zsh

Created on 2014-12-07.00:52:16 by abe, last changed 2017-01-27.15:32:36 by mika.

Messages
msg6073 (view) Author: mika Date: 2017-01-27.15:32:36
We believe that your issue has been closed by the upload of
Version 0.13.2 of grml-etc-core from Michael Prokop <mika@grml.org>.
The explanation is attached below

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Format: 1.8
Date: Fri, 27 Jan 2017 16:17:15 +0100
Source: grml-etc-core
Binary: grml-etc-core
Architecture: source all
Version: 0.13.2
Distribution: grml-testing
Urgency: medium
Maintainer: Michael Prokop <mika@grml.org>
Changed-By: Michael Prokop <mika@grml.org>
Description:
 grml-etc-core - core etcetera files for the Grml system
Changes:
 grml-etc-core (0.13.2) grml-testing; urgency=medium
 .
   * [b2556e7] zshrc: fall back to journalctl with llog + tlog aliases
     if /var/log/syslog doesn't exist
   * [875b6d6] zshrc: support systems without capacity file in
     batterylinux() [Closes: issue1333] Thanks to Axel Beckert
     for the patch
Checksums-Sha1:
 835c6a9b05fb7e6330c366924772e87d401fc68a 1577 grml-etc-core_0.13.2.dsc
 c02c58238d408ecdf8bd82186899005828cd25d5 162379 grml-etc-core_0.13.2.tar.gz
 9081aa9b29ffec02305d6896d38d37e744a8240b 147644 grml-etc-core_0.13.2_all.deb
 bcc4945c5f5d04e89928388885525aa06d0041d7 4779 grml-etc-core_0.13.2_amd64.buildinfo
Checksums-Sha256:
 51c107ca93941e0f880f1ba2ea46e8c2d37847fd952194255e8f97a3f761890f 1577 grml-etc-core_0.13.2.dsc
 94027ca0373ff77166438e78dd598069aab006e1ecbe24ac96de7534d7c1f306 162379 grml-etc-core_0.13.2.tar.gz
 21c2f0d4aac2068ba44246333021e83582130749eae58ff773395fd69b62c7e3 147644 grml-etc-core_0.13.2_all.deb
 e873aec985c6c81534b48f97bebb06d31eb04cedd24123822c55244cd3fd49f2 4779 grml-etc-core_0.13.2_amd64.buildinfo
Files:
 b44351d68d01fc3111023a2560ecf7ce 1577 grml optional grml-etc-core_0.13.2.dsc
 61df1741c5c60d0b2364a180dc364517 162379 grml optional grml-etc-core_0.13.2.tar.gz
 a1b5a94ce80941c5d1fdd5d27082a3c9 147644 grml optional grml-etc-core_0.13.2_all.deb
 423e6f505616913896ba00b501ff69ba 4779 grml optional grml-etc-core_0.13.2_amd64.buildinfo

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBCAAGBQJYi2TbAAoJEJaoeHK36jc364QP/1a461w+qvst1gclFOhxlzVQ
vl2Zt544vklSB5OBYYj6jMXN2BultiNvANoG+QwDsTfYb4i3qGEo82VneJ7RnTMR
P4KavdvcKc/E43W4XjARvZ21FKJz+GP182iO/0m1MzADtmH+ztIy/ntwXt/mQXIP
wEGBjr3kXOR7tlR1aKf7v0LERPG9sfEGVFxHLz18sxycTDyE2Yaq1uGMEXZU9c2B
mcz16KwTxBG1GbogStqYFp7g0mTq4ZwIUjaOiPYKJQ0wKLpm/EeYKjnaFbW5Mtoi
Xq6BAZPly6auJ++4L8VSnyYiVx6zjrveDb6H+8EU7RmeVXgvAcxJeb1APpBdQTac
zM803R4oh40WbOzGhb9arjpLENbKx1J8CoP0Ez1JQTHwuK8RmG0Kxc8++G1seqGo
l3jY/eKUE5iG6TbxrdLddNFFLbOKR4Rgh/Gvh6rkB13rPkyIF5KqYR8ZxTpuGVx9
6yTIT9TvvXUF44yTPgo8YHpemRzsHnAGr3XaH6PCsBE/vMiiVz8yUNHSYvLGd4+9
zv+QIWJFOaIUwynzyw6eLgxqx+8m+t7xXMINOARKZebXsSasxO8oC0paam7C4lPp
dhajCmhn+8yOs9u5cuW6bzIN0p8X2cRALp47jpGsfawvS23d2IoC09bxfj0265Pc
zxshynf9hYkmUNZ9LOWz
=gGKw
-----END PGP SIGNATURE-----
msg6070 (view) Author: mika Date: 2017-01-27.14:29:24
I've just applied your patch in git regarding the battery/capacity issue. I
can't reproduce the zsh 4.3.17 on any of my systems, if you still explore that
with our recent grml-zshrc please reopen/report a new bug. Thanks!

regards and sorry4delay,
Mika
msg4914 (view) Author: abe Date: 2014-12-07.01:37:09
Hi,

On Sun, Dec 07, 2014 at 12:52:16AM +0000, Axel Beckert wrote:
> batterylinux:6: no such file or directory: /sys/class/power_supply/BAT0/capacity

The following patch seems to fix this issue:

diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc
index d3d73b1..ae2f8af 100644
--- a/etc/zsh/zshrc
+++ b/etc/zsh/zshrc
@@ -1674,7 +1674,13 @@ local batteries bat capacity
 batteries=( /sys/class/power_supply/BAT*(N) )
 if (( $#batteries > 0 )) ; then
     for bat in $batteries ; do
-        capacity=$(< $bat/capacity)
+        if [[ -e $bat/capacity ]]; then
+            capacity=$(< $bat/capacity)
+        else
+            typeset -F energy_full=$(< $bat/energy_full)
+            typeset -F energy_now=$(< $bat/energy_now)
+            typeset -i capacity=$(( 100 * $energy_now / $energy_full))
+        fi
         case $(< $bat/status) in
         Charging)
             GRML_BATTERY_LEVEL+=" ^"

There are though some syntax issues if running on Wheezy, too, but
likely due to zsh 4.3.17 and not due to kernel 3.2.x. The following
patch fixes them -- I can open a separate issue for that if wanted:

diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc
index d3d73b1..ae2f8af 100644
--- a/etc/zsh/zshrc
+++ b/etc/zsh/zshrc
@@ -1129,7 +1129,7 @@ help_zle_parse_keybindings()
 
     if [[ -r $HELP_ZLE_CACHE_FILE ]]; then
         local load_cache=0
-        for f ($HELPZLE_KEYBINDING_FILES) [[ $f -nt $HELP_ZLE_CACHE_FILE ]] && load_cache=1
+        for f ($HELPZLE_KEYBINDING_FILES); do [[ $f -nt $HELP_ZLE_CACHE_FILE ]] && load_cache=1; done
         [[ $load_cache -eq 0 ]] && . $HELP_ZLE_CACHE_FILE && return
     fi
 
@@ -2934,7 +2940,7 @@ ssl-cert-info() {
 }
 
 # make sure our environment is clean regarding colors
-for color in BLUE RED GREEN CYAN YELLOW MAGENTA WHITE ; unset $color
+for color in BLUE RED GREEN CYAN YELLOW MAGENTA WHITE ; do unset $color; done
 
 # "persistent history"
 # just write important commands you always need to ~/.important_commands
@@ -3406,7 +3412,7 @@ if check_com -c hg ; then
     #f5# GNU like diff for mercurial
     hgdi() {
         emulate -L zsh
-        for i in $(hg status -marn "$@") ; diff -ubwd <(hg cat "$i") "$i"
+        for i in $(hg status -marn "$@") ; do diff -ubwd <(hg cat "$i") "$i"; done
     }
 
     # build debian package

		Kind regards, Axel
-- 
/~\  Plain Text Ribbon Campaign                   | Axel Beckert
\ /  Say No to HTML in E-Mail and News            | abe@deuxchevaux.org  (Mail)
 X   See http://www.nonhtmlmail.org/campaign.html | abe@noone.org (Mail+Jabber)
/ \  I love long mails: http://email.is-not-s.ms/ | http://noone.org/abe/ (Web)
msg4913 (view) Author: abe Date: 2014-12-07.00:52:16
If I use grml zshrc v0.10.3 on Debian Wheezy (with 3.2.x Linux kernel), I get
the error message 

batterylinux:6: no such file or directory: /sys/class/power_supply/BAT0/capacity
                                       

before each prompt.There is no "capacity" file in /sys/class/power_supply/BAT0/
(which exists) but it is used unconditionally in line 1677 of etc/zsh/zshrc.

It worked fine with grml zshrc v0.7.3.
History
Date User Action Args
2017-01-27 15:32:36mikasetstatus: fixed-in-git -> resolved
messages: + msg6073
2017-01-27 14:29:24mikasetstatus: chatting -> fixed-in-git
messages: + msg6070
2014-12-07 01:37:10abesetstatus: unread -> chatting
messages: + msg4914
2014-12-07 00:52:16abecreate