Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: assume no pkgs when dir is empty or does not exist #58

Merged

Conversation

lilyinstarlight
Copy link
Contributor

Description

I have cargo installed but do not have any packages installed with cargo. Because it is installed, it does a check anyway for the number of files in ~/.cargo/bin/*, which does not exist for me and so is not expanded by bash and looks like one entry: a literal ~/.cargo/bin/* (which also happens if the directory exists but is empty)

This causes neofetch to erroneously report that I have 1 cargo package installed when there is none (see output below)

This PR fixes this by ensuring that the first element passed to the internal dir function exists before counting the number of arguments to get number of packages, and fixes both the case when the directory does not exist and fixes when the directory is empty

Output

Without Fix

No ~/.cargo/bin
lily@bina 
--------- 
OS: NixOS 23.05.20221229.677ed08 (Stoat) x86_64 
Host: Laptop (12th Gen Intel Core) A6 
Kernel: 6.1.1 
Uptime: 50 mins 
Packages: 5877 (nix-system), 625 (nix-user), 1 (cargo) 
Shell: fish 3.5.1 
Editor: vi NVIM v0.8.1 
Resolution: 2256x1504 
WM: sway 
Theme: Materia-Fooster [GTK2/3] 
Icons: Papirus-Dark [GTK2/3] 
Cursor: Bibata-Modern-Classic [GTK2/3] 
Terminal: alacritty 
CPU: 12th Gen Intel i7-1260P (16) @ 4.7GHz 
Memory: 3.29 GiB / 31.07 GiB (10%) 
Network: Wifi 
Empty ~/.cargo/bin
lily@bina 
--------- 
OS: NixOS 23.05.20221229.677ed08 (Stoat) x86_64 
Host: Laptop (12th Gen Intel Core) A6 
Kernel: 6.1.1 
Uptime: 50 mins 
Packages: 5877 (nix-system), 625 (nix-user), 1 (cargo) 
Shell: fish 3.5.1 
Editor: vi NVIM v0.8.1 
Resolution: 2256x1504 
WM: sway 
Theme: Materia-Fooster [GTK2/3] 
Icons: Papirus-Dark [GTK2/3] 
Cursor: Bibata-Modern-Classic [GTK2/3] 
Terminal: alacritty 
CPU: 12th Gen Intel i7-1260P (16) @ 4.7GHz 
Memory: 3.30 GiB / 31.07 GiB (10%) 
Network: Wifi 
One package installed to ~/.cargo/bin
lily@bina 
--------- 
OS: NixOS 23.05.20221229.677ed08 (Stoat) x86_64 
Host: Laptop (12th Gen Intel Core) A6 
Kernel: 6.1.1 
Uptime: 55 mins 
Packages: 5877 (nix-system), 625 (nix-user), 1 (cargo) 
Shell: fish 3.5.1 
Editor: vi NVIM v0.8.1 
Resolution: 2256x1504 
WM: sway 
Theme: Materia-Fooster [GTK2/3] 
Icons: Papirus-Dark [GTK2/3] 
Cursor: Bibata-Modern-Classic [GTK2/3] 
Terminal: alacritty 
CPU: 12th Gen Intel i7-1260P (16) @ 4.7GHz 
Memory: 3.30 GiB / 31.07 GiB (10%) 
Network: Wifi 

With Fix

No ~/.cargo/bin
lily@bina 
--------- 
OS: NixOS 23.05.20221229.677ed08 (Stoat) x86_64 
Host: Laptop (12th Gen Intel Core) A6 
Kernel: 6.1.1 
Uptime: 52 mins 
Packages: 5877 (nix-system), 625 (nix-user) 
Shell: fish 3.5.1 
Editor: vi NVIM v0.8.1 
Resolution: 2256x1504 
WM: sway 
Theme: Materia-Fooster [GTK2/3] 
Icons: Papirus-Dark [GTK2/3] 
Cursor: Bibata-Modern-Classic [GTK2/3] 
Terminal: alacritty 
CPU: 12th Gen Intel i7-1260P (16) @ 4.7GHz 
Memory: 3.25 GiB / 31.07 GiB (10%) 
Network: Wifi 
Empty ~/.cargo/bin
lily@bina 
--------- 
OS: NixOS 23.05.20221229.677ed08 (Stoat) x86_64 
Host: Laptop (12th Gen Intel Core) A6 
Kernel: 6.1.1 
Uptime: 52 mins 
Packages: 5877 (nix-system), 625 (nix-user) 
Shell: fish 3.5.1 
Editor: vi NVIM v0.8.1 
Resolution: 2256x1504 
WM: sway 
Theme: Materia-Fooster [GTK2/3] 
Icons: Papirus-Dark [GTK2/3] 
Cursor: Bibata-Modern-Classic [GTK2/3] 
Terminal: alacritty 
CPU: 12th Gen Intel i7-1260P (16) @ 4.7GHz 
Memory: 3.30 GiB / 31.07 GiB (10%) 
Network: Wifi 
One package installed to ~/.cargo/bin
lily@bina 
--------- 
OS: NixOS 23.05.20221229.677ed08 (Stoat) x86_64 
Host: Laptop (12th Gen Intel Core) A6 
Kernel: 6.1.1 
Uptime: 53 mins 
Packages: 5877 (nix-system), 625 (nix-user), 1 (cargo) 
Shell: fish 3.5.1 
Editor: vi NVIM v0.8.1 
Resolution: 2256x1504 
WM: sway 
Theme: Materia-Fooster [GTK2/3] 
Icons: Papirus-Dark [GTK2/3] 
Cursor: Bibata-Modern-Classic [GTK2/3] 
Terminal: alacritty 
CPU: 12th Gen Intel i7-1260P (16) @ 4.7GHz 
Memory: 3.23 GiB / 31.07 GiB (10%) 
Network: Wifi 

@hykilpikonna hykilpikonna merged commit 0538e02 into hykilpikonna:master Jan 4, 2023
@hykilpikonna
Copy link
Owner

Merged, thank you!

@lilyinstarlight lilyinstarlight deleted the fix/empty-pkg-dirs branch January 4, 2023 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants