aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--src/ascii.c17
2 files changed, 22 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index fe2e4a8..19fb8af 100644
--- a/Makefile
+++ b/Makefile
@@ -19,6 +19,8 @@ CC = gcc
CFLAGS = -Wall -Wextra -Wundef -Wshadow -Wformat=2
PREFIX ?= /usr/local
TARGET = cfetch
+ASCII = ascii
+ASCII_DIR = /opt/$(TARGET)
SRC = src/cfetch.c \
src/sysinfo.c \
@@ -35,8 +37,12 @@ $(TARGET):
@echo "Finished install of $(TARGET)!"
install: $(TARGET)
+ @echo "Creating directories"
mkdir -p $(PREFIX)/bin
+ mkdir -p $(ASCII_DIR)
+ @echo "Installing $(TARGET)"
cp $(TARGET) $(PREFIX)/bin/$(TARGET)
+ cp -r $(ASCII) $(ASCII_DIR)
uninstall:
rm -f $(TARGET)
diff --git a/src/ascii.c b/src/ascii.c
index 0a2dc67..b199dd4 100644
--- a/src/ascii.c
+++ b/src/ascii.c
@@ -18,6 +18,7 @@
#include "../include/cfetch.h"
#include <stddef.h>
#include <stdio.h>
+#include <unistd.h>
#define MAX_LOGOS 5
@@ -32,6 +33,20 @@ static const struct ascii_mapping_t ascii_mappings[] =
{NULL, NULL}
};
+char* get_ascii_path(void)
+{
+ char *path[] = {
+ "/opt/cfetch/ascii/",
+ "./ascii/"
+ };
+
+ for (size_t i = 0; i < (sizeof(path) / sizeof(path[0])) ; i++) {
+ if (access(path[i], F_OK) == 0) return path[i];
+ }
+
+ return NULL;
+}
+
const char* get_ascii_name(const struct ascii_mapping_t *d_map, int art)
{
if (art >= MAX_LOGOS) {
@@ -48,7 +63,7 @@ void print_ascii_art(struct system_info_t *info)
{
// get ascii name
const char* name = get_ascii_name(ascii_mappings, info->ascii_art);
- char* path = concat("ascii/", name);
+ char* path = concat(get_ascii_path(), name);
if (info->debug == 1) {
printf("path: %s\n", path);