Skip to content

Commit 50e9a58

Browse files
RichardBronoskyclaude
authored andcommitted
fix: Prevent get_battery from throwing "file not found"
Check if battery capacity and status files exist before attempting to read them. This prevents errors on systems where the battery path exists but the required files are missing. Fixes dylanaraps#2129 (cherry-picked from dylanaraps#2130) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 9ccb489 commit 50e9a58

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

neofetch

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,8 @@ get_distro() {
10861086

10871087
else
10881088
for release_file in /etc/*-release; do
1089-
distro+=$(< "$release_file")
1089+
distro=$(< "$release_file")
1090+
break
10901091
done
10911092

10921093
if [[ -z $distro ]]; then
@@ -3678,6 +3679,7 @@ get_battery() {
36783679
# We use 'prin' here so that we can do multi battery support
36793680
# with a single battery per line.
36803681
for bat in "/sys/class/power_supply/"{BAT,axp288_fuel_gauge,CMB}*; do
3682+
[[ -f ${bat}/capacity && -f ${bat}/status ]] || continue
36813683
capacity="$(< "${bat}/capacity")"
36823684
status="$(< "${bat}/status")"
36833685

@@ -3823,8 +3825,7 @@ get_gpu_driver() {
38233825
gpu_driver="${gpu_driver%, }"
38243826

38253827
if [[ "$gpu_driver" == *"nvidia"* ]]; then
3826-
gpu_driver="$(< /proc/driver/nvidia/version)"
3827-
gpu_driver="${gpu_driver/*Module }"
3828+
gpu_driver="$(< /sys/module/nvidia/version)"
38283829
gpu_driver="NVIDIA ${gpu_driver/ *}"
38293830
fi
38303831
;;

0 commit comments

Comments
 (0)