├── .gitignore ├── README.md ├── make.sh └── src ├── battery.c ├── brightness.c ├── refresh_rate.c ├── resolution.c ├── term_size.c └── uptime.c /.gitignore: -------------------------------------------------------------------------------- 1 | a.out 2 | build/* 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nfu - Neofetch Utils 2 | 3 | A small set of C binaries for use in custom fetch scripts. 4 | 5 | ## Building 6 | 7 | - Run `./make.sh`. 8 | - Programs are stored in `./build/`. 9 | -------------------------------------------------------------------------------- /make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Simple build script. 4 | mkdir -p build 5 | 6 | for file in src/*.c; do 7 | file2="${file##*/}" 8 | gcc -Wall -Wextra "$file" -o "build/${file2%%.c}" 2>/dev/null || \ 9 | gcc -Wall -Wextra -lX11 -lXrandr "$file" -o "build/${file2%%.c}" 10 | done 11 | 12 | printf '%s\n' 'Binaries are in ./build/' 13 | -------------------------------------------------------------------------------- /src/battery.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | struct dirent *de; 7 | char path[] = "/sys/class/power_supply/"; 8 | DIR *dr = opendir(path); 9 | 10 | if (!dr) return 1; 11 | 12 | while ((de = readdir(dr)) != NULL) { 13 | char full_path[256] = ""; 14 | int perc; 15 | 16 | // Construct the file path. 17 | strncat(full_path, path, strlen(path)); 18 | strncat(full_path, de->d_name, strlen(de->d_name)); 19 | strncat(full_path, "/capacity", 10); 20 | 21 | FILE *f = fopen(full_path, "r"); 22 | if (!f) continue; 23 | 24 | fscanf(f, "%d", &perc); 25 | fclose(f); 26 | 27 | printf("%s: %d%%\n", de->d_name, perc); 28 | } 29 | 30 | closedir(dr); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /src/brightness.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | struct dirent *de; 7 | char path[] = "/sys/class/backlight/"; 8 | DIR *dr = opendir(path); 9 | int i = 0; 10 | 11 | if (!dr) return 1; 12 | 13 | while ((de = readdir(dr)) != NULL) { 14 | char full_path[256] = ""; 15 | int perc; 16 | 17 | // Construct the file path. 18 | strncat(full_path, path, strlen(path)); 19 | strncat(full_path, de->d_name, strlen(de->d_name)); 20 | strncat(full_path, "/brightness", 12); 21 | 22 | FILE *f = fopen(full_path, "r"); 23 | if (!f) continue; 24 | 25 | fscanf(f, "%d", &perc); 26 | fclose(f); 27 | 28 | printf("%s%d: %d%%\n", "BRI", i++, perc/10+1); 29 | } 30 | 31 | closedir(dr); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /src/refresh_rate.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | Display *dpy = XOpenDisplay(NULL); 7 | Window root = RootWindow(dpy, 0); 8 | XRRScreenConfiguration *conf = XRRGetScreenInfo(dpy, root); 9 | 10 | printf("%dhz\n", XRRConfigCurrentRate(conf)); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/resolution.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | Display* d = XOpenDisplay(NULL); 6 | Screen* s = DefaultScreenOfDisplay(d); 7 | 8 | printf("%dx%d\n", s->width, s->height); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /src/term_size.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | struct winsize w; 7 | ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); 8 | printf("%dx%d\n", w.ws_row, w.ws_col); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /src/uptime.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | FILE *f = fopen("/proc/uptime", "r"); 5 | int d, h, m, s; 6 | 7 | if (!f) return 1; 8 | 9 | fscanf(f, "%d", &s); 10 | fclose(f); 11 | 12 | d = s/60/60/24; 13 | h = s/60/60%24; 14 | m = s/60%60; 15 | 16 | // Only print fields if they aren't '0'. 17 | if (d^0) printf("%dd ", d); 18 | if (h^0) printf("%dh ", h); 19 | if (m^0) printf("%dm ", m); 20 | 21 | printf("\n"); 22 | return 0; 23 | } 24 | --------------------------------------------------------------------------------