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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// __ _ __ _ _
// / _| | | / _| | | | |
// | |_ __ _| | _____| |_ ___| |_ ___| |__
// | _/ _` | |/ / _ \ _/ _ \ __/ __| '_ \
// | || (_| | < __/ || __/ || (__| | | |
// |_| \__,_|_|\_\___|_| \___|\__\___|_| |_|
// Note: I have tried to make this as user friendly as possable/
//----------------------------------------------------------------------------------|
// Welcome to fakefetch |
//----------------------------------------------------------------------------------|
// This is just neofetch but |
// You do it yourself, now in C! |
//----------------------------------------------------------------------------------|
// This is Libre code, you can do whatever you want with it since |
// it is under the GPL |
// ---------------------------------------------------------------------------------|
// Function to execute shell commands and get the output |
// ---------------------------------------------------------------------------------|
char* execute_command(const char* command) {
char* result = malloc(128 * sizeof(char));
FILE* fp;
if ((fp = popen(command, "r")) == NULL) {
printf("Error opening pipe!\n");
return NULL;
}
if (fgets(result, 128, fp) == NULL) {
printf("Error reading pipe!\n");
return NULL;
}
pclose(fp);
// Remove newline character
result[strcspn(result, "\n")] = '\0';
return result;
}
int main() {
// ---------------------------------------------------------------------------------------------------//
// Colour codes
// ---------------------------------------------------------------------------------------------------//
// Define colours by changing the last two letters to Xterm number
const char* PURPLE = "\033[38;5;92m";
const char* MAGENTA = "\033[38;5;98m";
const char* RESET = "\033[0m";
// Set colours
const char* Text = MAGENTA;
const char* Background = PURPLE;
// ---------------------------------------------------------------------------------------------------//
// Get system information
char* USERNAME = execute_command("whoami");
char* HOSTNAME = execute_command("uname -n");
char* DISTRO = execute_command("lsb_release -sd | sed 's/\"//g'");
char* CPU_INFO = execute_command("lscpu | grep 'Model name' | awk '{$1=$2=\"\"; print $0}' | sed 's/^[ \\t]*//'");
char* CORES = execute_command("lscpu | grep 'Core(s) per socket' | awk '{print $NF}'");
char* GPU_INFO = execute_command("lspci | grep -i 'VGA\\|3D' | sed 's/.*: //; s/ (.*//'");
char* UPTIME = execute_command("uptime -p | sed 's/up //'");
// Terminal and package manager
const char* TERMINAL = "Alacritty"; //Still need to work on the terminal bit
char* PACKAGE_MANAGER = execute_command(
"if command -v pacman &> /dev/null; then echo Pacman; "
"elif command -v apt-get &> /dev/null; then echo APT; "
"else echo Unknown; fi"
);
// ---------------------------------------------------------------------------------------------------//
// Print output
// ---------------------------------------------------------------------------------------------------//
printf("%s :: %s\n", Background, RESET);
printf("%s .==. %s\n", Background, RESET);
printf("%s ==== %s\n", Background, RESET);
printf("%s -===== %s@%s%s\n", Background, USERNAME, HOSTNAME, RESET);
printf("%s -====== ========================================%s\n", Background, RESET);
printf("%s :========- OS → %s%s%s\n", Background, Text, DISTRO, RESET);
printf("%s :.:-=======- GPU → %s%s%s\n", Background, Text, GPU_INFO, RESET);
printf("%s :==---=======- PM → %s%s%s\n", Background, Text, PACKAGE_MANAGER, RESET);
printf("%s :==============- Term → %s%s%s\n", Background, Text, TERMINAL, RESET);
printf("%s :================- Uptime → %s%s%s\n", Background, Text, UPTIME, RESET);
printf("%s :==================- ========================================%s\n", Background, RESET);
printf("%s :========----========- %s\n", Background, RESET);
printf("%s -========. .========- %s\n", Background, RESET);
printf("%s -======== ========= %s\n", Background, RESET);
printf("%s -========: :======---. %s\n", Background, RESET);
printf("%s -=========: .=======-:. %s\n", Background, RESET);
printf("%s =========--: .--=======-: %s\n", Background, RESET);
printf("%s .=====-:.. ..:-=====%s\n", Background, RESET);
printf("%s .==-:. .:-==:%s\n", Background, RESET);
// Free up memory
free(USERNAME);
free(HOSTNAME);
free(DISTRO);
free(CPU_INFO);
free(CORES);
free(GPU_INFO);
free(UPTIME);
free(PACKAGE_MANAGER);
return 0;
}
|