Skip to content

Commit dbe523b

Browse files
cfcf
authored andcommitted
add more config options
1 parent bfc49d4 commit dbe523b

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ SRC = src/fetch.c
22
CC ?= cc
33
CFLAGS = -O2 -std=c99 -Wall -Wextra
44
LDFLAGS = -lpthread
5-
DEBUGFLAGS = -g
5+
DEBUGFLAGS = -g -Og -std=c99 -Wall -Wextra
66
PREFIX ?= /usr/local
77

88
all: afetch
@@ -11,10 +11,10 @@ afetch: ${SRC} src/config.h src/colour.h
1111
${CC} ${CFLAGS} ${SRC} ${LDFLAGS} -o afetch
1212

1313
debug:
14-
${CC} ${CFLAGS} ${DEBUGFLAGS} ${SRC} ${LDFLAGS} -o afetch-debug
14+
${CC} ${DEBUGFLAGS} ${SRC} ${LDFLAGS} -o afetch-debug
1515

1616
clean:
17-
rm -rf afetch afetch.dSYM
17+
rm -rf afetch afetch.dSYM afetch-debug afetch-debug.dSYM
1818

1919
install:
2020
mkdir -p ${DESTDIR}${PREFIX}/bin

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
<p align=center>Fast and simple system info (for UNIX based operating systems) written in POSIX compliant C99, that can be configured at compile time by editing the <a href="src/config.h">config.h</a> file. It uses the C Preprocessor to implement config options at compile time. <br> <br>
77

8-
`afetch` is a command line tool that is made to be compiled and run anywhere, as long as you have the POSIX header files and pthreads/ </p>
8+
<h3 align="center"> Why use afetch? </h3>
9+
<p align="center"> afetch is written in C99, meaning that it should be able to be compiled with almost all C compilers. As well as being written in a very fast language, it's multithreaded. This makes it even faster, as well as distinguishing it from similar programs written is POSIX sh. The only limitations it has is the speed of your distros package manager! </p>
910

1011
**Requirements**
1112
* `/etc/os-release` file for package count on Linux
@@ -52,6 +53,8 @@ If on Linux, please show me the contents of the `/etc/os-release` file.
5253

5354
**Configuration options**
5455
* Custom text for each seperate row of info
56+
* Force lowercase text for OS name
57+
* Option to print colour blocks or not
5558
* More to be implemented soon
5659

5760

src/config.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
#define UserText " USER "//
2-
#define OsText " OS "//
3-
#define KernelText " KERNEL "//
4-
#define UptimeText " UPTIME "//
5-
#define ShellText " SHELL "//
6-
#define PackageText " PKGS "//
1+
#define UserText " USER " //
2+
#define OsText " OS " //
3+
#define KernelText " KERNEL " //
4+
#define UptimeText " UPTIME " //
5+
#define ShellText " SHELL " //
6+
#define PackageText " PKGS " //
77

8-
#define PrintColours false //must be either 'true' or 'false'
8+
#define ForceLowerCase false //must be either 'true' or 'false'
9+
10+
#define PrintColours false //must be either 'true' or 'false'
911
#define ColourCharacter "● "
1012

1113
/* Some examples of things you may want to use for your ColourCharacter

src/fetch.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ char *username, *osname, *shellname, *pkgCount;
2020
char *krnlver;
2121
long uptimeH, uptimeM;
2222

23+
char *lowerCase(char *str) {
24+
if (ForceLowerCase == false) return str;
25+
int len = strlen(str);
26+
for (int i=0; i<len;i++){
27+
if (str[i] >= 'A' && str[i] <= 'Z') {
28+
str[i] += 32; }
29+
}
30+
return str;
31+
}
2332

2433

2534
char *pipeRead(const char *exec){
@@ -63,6 +72,12 @@ void *uptime(){
6372

6473
void *user(){
6574
username = getenv("USER");
75+
76+
/* I'm not sure if lower case usernames
77+
are allowed in UNIX-like operating
78+
systems. I'll have to look into it */
79+
//username = lowerCase(username);
80+
6681
return NULL;
6782
}
6883

@@ -79,7 +94,9 @@ void *shell(){
7994
void *os(){
8095
static struct utsname sysInfo;
8196
uname(&sysInfo);
82-
97+
//start
98+
/* This whole section could probably be rewritten - it seems
99+
like a bit of a mess right now */
83100
if (strncmp(sysInfo.sysname, "Linux", 5)==0) {
84101
char *osContents = malloc(512);
85102
char *newContents = malloc(512);
@@ -107,7 +124,7 @@ void *os(){
107124
osname = malloc(512);
108125
strcpy(osname, newContents);
109126
free(newContents);
110-
127+
//end
111128
while (1){
112129
if (strncmp(osname, "Alpine Linux", 12) == 0) {
113130
info.col1 = BBLUE"\n";
@@ -399,6 +416,7 @@ void *os(){
399416
}
400417
pkgCount = pipeRead(info.getPkgCount);
401418

419+
osname = lowerCase(osname);
402420
return NULL;
403421
}
404422

@@ -434,7 +452,7 @@ int main(){
434452
pthread_join(threads[1], NULL); //os function must be run to get info.col1
435453
printf("%s", info.col1);
436454
printf("%s %s%s%s\n", info.col2, UserText ,WHITE, username);
437-
printf("%s %s%s%s\n", info.col3,OsText, WHITE, osname);
455+
printf("%s %s%s%s\n", info.col3, OsText , WHITE, osname);
438456
pthread_join(threads[2], NULL);
439457
printf("%s %s%s%s\n", info.col4,KernelText,WHITE, krnlver);
440458
pthread_join(threads[3], NULL);
@@ -447,6 +465,5 @@ int main(){
447465
pthread_create(&threads[5], NULL, colourDraw, NULL);
448466
pthread_join(threads[5], NULL);
449467
printf("%s", RESET);
450-
451468
return 0;
452469
}

0 commit comments

Comments
 (0)