Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
Language: Cpp
AlignAfterOpenBracket: BlockIndent
BinPackArguments: false # NOTE: Conflicts with trailing commas
BreakBeforeBraces: Attach
BreakStringLiterals: true
ColumnLimit: 88
IndentWidth: 4
InsertBraces: true
InsertNewlineAtEOF: true
InsertTrailingCommas: Wrapped
LineEnding: LF
PointerAlignment: Right
TabWidth: 4
UseTab: Always
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Initial format
5d000748a10738730dc54cc89aeefa18a53d1370
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
name: Build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Check format
run: |
make format
git diff --exit-code
- name: Build
run: make
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ Mkfile.old
dkms.conf

# Built assets
fetchfetch
bin/*
!bin/.gitkeep
31 changes: 18 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
fetchfetch: art.o args.o stats.o version.o fetchfetch.c
$(CC) -o fetchfetch art.o args.o stats.o version.o fetchfetch.c
bin/fetchfetch: bin/art.o bin/args.o bin/stats.o bin/version.o src/fetchfetch.c
$(CC) -o bin/fetchfetch bin/art.o bin/args.o bin/stats.o bin/version.o src/fetchfetch.c

args.o: args.c args.h
$(CC) -c -o args.o args.c

art.o: art.c art.h
$(CC) -c -o art.o art.c
bin/args.o: src/args.c src/args.h
$(CC) -c -o bin/args.o src/args.c

stats.o: stats.c stats.h version.c version.h
$(CC) -c -o stats.o stats.c
bin/art.o: src/art.c src/art.h
$(CC) -c -o bin/art.o src/art.c

version.o: version.c version.h
$(CC) -c -o version.o version.c
bin/stats.o: src/stats.c src/stats.h src/version.c src/version.h
$(CC) -c -o bin/stats.o src/stats.c

bin/version.o: src/version.c src/version.h
$(CC) -c -o bin/version.o src/version.c

.PHONY: format
format:
clang-format -i src/*

.PHONY: run
run: fetchfetch
./fetchfetch
run: bin/fetchfetch
./bin/fetchfetch

.PHONY: install
install: fetchfetch
cp ./fetchfetch /usr/local/bin/fetchfetch
cp ./bin/fetchfetch /usr/local/bin/fetchfetch
Empty file added bin/.gitkeep
Empty file.
20 changes: 11 additions & 9 deletions args.c → src/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "args.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "args.h"

int right_pad = -1;
bool print_help = false;
Expand All @@ -34,7 +34,8 @@ bool parse_args(int argc, char **argv) {
return false;
}
arg = argv[++i];
// NOTE We're ignoring overflows (the safety check isn't a priority for this tool).
// NOTE We're ignoring overflows (the safety check isn't a priority for this
// tool).
right_pad = (int)strtol(arg, &end, 10);
if (end == arg || right_pad < 0) {
fprintf(stderr, "--pad expected a non-negative integer, got %s\n", arg);
Expand All @@ -49,10 +50,11 @@ bool parse_args(int argc, char **argv) {
return true;
}

const char *help_message = "Usage: fetchfetch [OPTIONS...]\n"
"Fetch the stats of your *fetch tools\n"
"\n"
"Options:\n"
" -p, --pad N Right-pad labels by N spaces to align values\n"
" -h, --help Print this message and exit\n"
" -v, --version Print the version and exit\n";
const char *help_message =
"Usage: fetchfetch [OPTIONS...]\n"
"Fetch the stats of your *fetch tools\n"
"\n"
"Options:\n"
" -p, --pad N Right-pad labels by N spaces to align values\n"
" -h, --help Print this message and exit\n"
" -v, --version Print the version and exit\n";
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 5 additions & 4 deletions fetchfetch.c → src/fetchfetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "args.h"
#include "art.h"
#include "stats.h"
#include "version.h"
#include <stdbool.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[]) {
FetchStat *stats;
Expand All @@ -41,7 +41,8 @@ int main(int argc, char *argv[]) {
}

stats = get_stats();
for (int line_index = 0; line_index < ART_HEIGHT || line_index < STATS_SIZE; line_index++) {
for (int line_index = 0; line_index < ART_HEIGHT || line_index < STATS_SIZE;
line_index++) {
if (line_index < ART_HEIGHT) {
for (int col_index = 0; col_index < ART_WIDTH; col_index++) {
putchar(art[line_index][col_index]);
Expand Down
38 changes: 21 additions & 17 deletions stats.c → src/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "stats.h"
#include "version.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "stats.h"
#include "version.h"

char *app_version_fallback = "Not installed";

Expand All @@ -27,7 +27,7 @@ char *app_version_fallback = "Not installed";
*
* Falls back to "Not installed" if the command fails.
*/
char* app_version(const char *command) {
char *app_version(const char *command) {
FILE *fp;
char redirected_command[50];
// NOTE 50 should be more than enough space for version info.
Expand Down Expand Up @@ -55,14 +55,12 @@ char* app_version(const char *command) {
/**
* Checks if a character is a boundary character.
*/
bool is_boundary(char c) {
return c == ' ' || c == '\n';
}
bool is_boundary(char c) { return c == ' ' || c == '\n'; }

/**
* Splits outputs in the format `"Appname x.y.z\n"` into `"x.y.z"`.
*/
char* extract_named_version(const char *version_info, const char *prefix) {
char *extract_named_version(const char *version_info, const char *prefix) {
int start;
int end;
int len;
Expand All @@ -73,44 +71,50 @@ char* extract_named_version(const char *version_info, const char *prefix) {
}

len = strlen(version_info);
for (start = 0; version_info[start] != '\0' && strncmp(version_info + start, prefix, prefix_len) != 0; start++);
if (start >= len) return NULL; // Prefix not found
for (start = 0; version_info[start] != '\0' &&
strncmp(version_info + start, prefix, prefix_len) != 0;
start++)
;
if (start >= len) {
return NULL; // Prefix not found
}
start += prefix_len;
for (end = start; end < len && !is_boundary(version_info[end]); end++);
for (end = start; end < len && !is_boundary(version_info[end]); end++)
;
return strndup(version_info + start, end - start);
}

char* fastfetch() {
char *fastfetch() {
// NOTE Version in the format "fastfetch x.x.x (ARCH)"
char *out = app_version("fastfetch --version");
return extract_named_version(out, "fastfetch ");
}

char* neofetch() {
char *neofetch() {
// NOTE Version in the format "Neofetch x.x.x"
char *out = app_version("neofetch --version");
return extract_named_version(out, "Neofetch ");
}

char* onefetch() {
char *onefetch() {
// NOTE Version in the format "onefetch x.x.x"
char *out = app_version("onefetch --version");
return extract_named_version(out, "onefetch ");
}

char* pfetch() {
char *pfetch() {
// NOTE Version in the format "pfetch x.x.x"
char *out = app_version("pfetch --version");
return extract_named_version(out, "pfetch ");
}

char* uwufetch() {
char *uwufetch() {
// NOTE Version in the format "UwUfetch version x.x"
char *out = app_version("uwufetch --version");
return extract_named_version(out, "UwUfetch version ");
}

FetchStat* get_stats() {
FetchStat *get_stats() {
FetchStat *stats = malloc(STATS_SIZE * sizeof(FetchStat));
stats[0].label = "Fastfetch";
stats[0].version = fastfetch();
Expand Down
12 changes: 6 additions & 6 deletions stats.h → src/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,32 @@ typedef struct {
/**
* Gets Fastfetch version information.
*/
char* fastfetch();
char *fastfetch();

/**
* Gets Neofetch version information.
*/
char* neofetch();
char *neofetch();

/**
* Gets onefetch version information.
*/
char* onefetch();
char *onefetch();

/**
* Gets pfetch version information.
*/
char* pfetch();
char *pfetch();

/**
* Gets UwUfetch version information.
*/
char* uwufetch();
char *uwufetch();

#define STATS_SIZE 6
/**
* Gets all stats.
*/
FetchStat* get_stats();
FetchStat *get_stats();

#endif
2 changes: 1 addition & 1 deletion version.c → src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
*/
#include "version.h"

const char* version = "1.1.0";
const char *version = "1.1.0";
File renamed without changes.
Loading