ericmurphyxyz / dotfiles

My Hyprland dotfiles on Arch Linux (btw)
614 stars 73 forks source link

Missing double brackets in "chargingnotify" #4

Closed rainer2208 closed 1 year ago

rainer2208 commented 1 year ago

Hi Eric,

I am using Arch for some time and I like to tinker with code, even though I am not a professional programmer.

Setting up battery notification for i3 was quite a hassle, but your video on youtube and your code examples were what got me going in the end.

I don't know if it's relevant, but I may have encountered just one inconsistency in one of your scripts, CHARGINGNOTIFY, at least when using it on my machine : when plugging the battery in or out, the notification won't show, and when I ran:

   /usr/bin/su rainer -c /home/rainer/.local/bin/chargingnotify 1, 

I received the following error message :

  ```
      -eq unary operator expected  
     ./chargingnotify: line 11: [: -eq: unary operator expected
     ./chargingnotify: line 13: [: -eq: unary operator expected


The solution was to put the respective lines into double brackets, like so:  

           [[ $BATTERY_CHARGING -eq 0 ]];
           [[ $BATTERY_CHARGING -eq 1 ]];

and only then plugin notification would appear .... 

I found the solution [here](https://stackoverflow.com/questions/57984248/eq-unary-operator-expected) on stackoverflow. 

I wasn't sure if it was a good idea to file an issue, since arch users are probably expected to be able to help themselves with small issues ... :-) 
ericmurphyxyz commented 1 year ago

No worries, always feel free to file an issue. I don't want to use double brackets ([[) as it is only available in bash (see this video for more information). I'm assuming that the issue you were running into is because you didn't wrap the script with quotes? If you run the command /usr/bin/su rainer -c '/home/rainer/.local/bin/chargingnotify 1' (note the added single quotes), it should work correctly.

rainer2208 commented 1 year ago

Hi Eric, sorry for the late reply ... many thanks for finding the time to look into the issue. Thanks to your work and explanation, I find the time to delve into, and get the hang of Shell scripting ... :-) . I didn't have an opportunity to watch the video you recommended above, but is definitely on my list. Since the issue seems to be solved, I am closing this ....