Add *argument*

windows
Nakidai 2023-11-15 20:56:56 +03:00
parent c300ebeadf
commit 806f176ab0
4 changed files with 91 additions and 28 deletions

View File

@ -1,3 +1,15 @@
# mycfetch
Simle neofetch.
Simple neofetch.
Usage
--
Use argument to select art. If not argument provided, mycfetch uses first entry in arts list.
For your convenience, you can set alias for needed art.
List of arts
--
- `cat`
- `freebsd`
- `gentoo`
- `arch`

View File

@ -1,29 +1,44 @@
#include "defs.h"
const int max_username_length = 128;
const int max_hostname_length = 128;
const int max_uptime_length = 40;
char *art[] = {
// FreeBSD
"\033[31m_ _\033[0m",
"\033[31m\\‾‾‾‾/\033[0m",
"\033[31m|^ww^|\033[0m",
"\033[31m\\____/\033[0m"
// Gentoo
// "\x1B[38;5;135m /‾\\",
// "\x1B[38;5;135m( \x1B[38;5;183mo \x1B[38;5;135m\\",
// "\x1B[38;5;135m/ /",
// "\x1B[38;5;135m\\__/"
// Arch
// " /\\ ",
// " /\\ \\ ",
// " / \\ ",
// "/__/\\__\\"
// Just cute cat
// " |、 ",
// "(˚ˎ。7 ",
// " |、˜〵 ",
// "じしˍ,)"
struct art_entry arts[] = {
{
"cat",
{
" |、 ",
"(˚ˎ。7 ",
"| 、˜〵 ",
"じしˍ,)"
}
},
{
"freebsd",
{
"\033[31m_ _\033[0m",
"\033[31m\\‾‾‾‾/\033[0m",
"\033[31m|^vv^|\033[0m",
"\033[31m\\____/\033[0m"
}
},
{
"gentoo",
{
" /‾\\ ",
"( o \\",
"/ /",
"\\__/ "
}
},
{
"arch",
{
" /\\ ",
" /\\ \\ ",
" / \\ ",
"/__/\\__\\"
}
}
};

10
defs.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef __DEFS_H__
#define __DEFS_H__
struct art_entry
{
char *name;
char *art[4];
};
#endif /* __DEFS_H__ */

32
main.c
View File

@ -1,9 +1,22 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/utsname.h>
#include <unistd.h>
#include <time.h>
#include <stdarg.h>
#include <string.h>
#include "config.h"
#include "defs.h"
void die(int code, char *fmt, ...)
{
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
exit(code);
}
void getuptime(char *buffer, int max_length)
{
@ -26,21 +39,34 @@ void getuptime(char *buffer, int max_length)
int main(int argc, char **argv)
{
if (argc > 2) die(1, "usage: %s [artname]\n", argv[0]);
struct utsname uname_buf;
struct timespec uptime_buf;
char hostname[max_hostname_length];
char username[max_username_length];
char uptime[max_uptime_length];
int i;
char **art = NULL;
gethostname(hostname, max_hostname_length);
getlogin_r(username, max_username_length);
getuptime(uptime, max_uptime_length);
if (argc == 2)
{
for (i = 0; i < sizeof(arts)/sizeof(struct art_entry); ++i)
if (!strcmp(arts[i].name, argv[1])) { art = arts[i].art; break; }
if (!art) die(1, "Art %s not found\n", argv[1]);
} else
{
art = arts[0].art;
}
uname(&uname_buf);
printf("%s %s@%s\n", art[0], username, hostname);
printf("%s --\n", art[1]);
printf("%s %s %s\n", art[2], uname_buf.sysname, uname_buf.release);
printf("%s %s\n", art[3], uptime);
// #include "order.c"
return 0;
return 0;
}