-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmacfetch.c
57 lines (55 loc) · 1.65 KB
/
macfetch.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "util.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/utsname.h>
#define SIZE(a) (sizeof a / sizeof *a)
struct utsname uts;
char *kernel(Map *map){
char *out;
asprintf(&out, "%s %s %s", uts.machine, uts.sysname, uts.release);
return out;
}
int main(int argc, char *argv[]){
Map map;
struct {
unsigned logo : 1;
unsigned uh : 1;
unsigned gui : 1;
} pref;
int opt;
char *(*funs[])(Map *map) = {ver, kernel, model, cpu, gpu, fs, mem, uptime, pkgs, shell, theme};
char *labels[] = {"os", "kernel", "model", "cpu", "gpu", "disk", "memory", "uptime", "pkgs", "shell", "theme"},
*guispaces[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "};
uname(&uts);
while ((opt = getopt(argc, argv, "ghlu")) != -1){
switch(opt){
case 'h':
puts("macfetch -ghlu\n-g format the spacing so it aligns in the GUI dialog window\n-h: display help and exit\n-l don't display logo\n-u don't display user@hostname");
return 0;
case 'l':
pref.logo = 1;
break;
case 'u':
pref.uh = 1;
break;
case 'g':
pref.gui = 1;
break;
}
}
if(!pref.uh)
printf("%s%s@%s\n", pref.logo?"":" ", getenv("USER"), uts.nodename);
char longestelementlength = 0, temp = 0;
for (int i = 0; i < SIZE(labels); ++i)
if((temp = strlen(labels[i])) > longestelementlength)
longestelementlength = temp;
char *space = malloc(longestelementlength);
memset(space, ' ', longestelementlength);
for (int i = 0; i < SIZE(labels); ++i){
if(!pref.logo) printf("%s", apple[i]);
printf("%s: %s%s\n", labels[i], pref.gui?guispaces[i]:space + strlen(labels[i]), funs[i](&map));
}
return 0;
}