Formatted every file with , as suggested in #73

This commit is contained in:
TheDarkBug 2021-04-15 09:33:51 +02:00
commit 45f26524c0
3 changed files with 27 additions and 18 deletions

View file

@ -55,4 +55,9 @@ If you are requesting a feature, please specify if you are already working on it
I know that adding this file now is a bit late, but I am writing this anyway, just to appear as a _professional_ programmer, even though I am not. I know that adding this file now is a bit late, but I am writing this anyway, just to appear as a _professional_ programmer, even though I am not.
<<<<<<< HEAD
I woult take some space to thank all the [contributors](https://github.com/TheDarkBug/uwufetch/graphs/contributors) that made this project better every day. I woult take some space to thank all the [contributors](https://github.com/TheDarkBug/uwufetch/graphs/contributors) that made this project better every day.
=======
I would take some space to thank all the [contributors](https://github.com/TheDarkBug/uwufetch/graphs/contributors) that made this project better every day.
> > > > > > > f87068f6f8746dbabd4f8936766b4389c07591ca

View file

@ -62,7 +62,7 @@ int ascii_image_flag = 0,
show_colors = 1; show_colors = 1;
char user[32], host[256], shell[64], kernel[256], version_name[64], cpu_model[256], char user[32], host[256], shell[64], kernel[256], version_name[64], cpu_model[256],
gpu_model[8][256] = {{'0'}, {'0'}, {'0'}, {'0'}, {'0'}, {'0'}, {'0'}, {'0'}}, gpu_model[8][256] = {{'0'}, {'0'}, {'0'}, {'0'}, {'0'}, {'0'}, {'0'}, {'0'}},
pkgman_name[64], image_name[32]; pkgman_name[64], image_name[128], *config_directory = NULL;
// functions definitions, to use them in main() // functions definitions, to use them in main()
int pkgman(); int pkgman();
@ -82,16 +82,14 @@ int main(int argc, char *argv[])
int opt = 0; int opt = 0;
static struct option long_options[] = { static struct option long_options[] = {
{"ascii", no_argument, NULL, 'a'}, {"ascii", no_argument, NULL, 'a'},
{"custom", required_argument, NULL, 'c'}, {"config", required_argument, NULL, 'c'},
{"config", required_argument, NULL, 0},
{"distro", required_argument, NULL, 'd'}, {"distro", required_argument, NULL, 'd'},
{"help", no_argument, NULL, 'h'}, {"help", no_argument, NULL, 'h'},
{"image", no_argument, NULL, 'i'}, {"image", optional_argument, NULL, 'i'},
{"list", no_argument, NULL, 'l'}, {"list", no_argument, NULL, 'l'},
{NULL, 0, NULL, 0}}; {NULL, 0, NULL, 0}};
get_info(); get_info();
parse_config(); while ((opt = getopt_long(argc, argv, "ac:d:hi::l", long_options, NULL)) != -1)
while ((opt = getopt_long(argc, argv, "ad:hilc:", long_options, NULL)) != -1)
{ {
switch (opt) switch (opt)
{ {
@ -99,8 +97,7 @@ int main(int argc, char *argv[])
ascii_image_flag = 0; ascii_image_flag = 0;
break; break;
case 'c': case 'c':
ascii_image_flag = 1; config_directory = optarg;
sprintf(image_name, "%s", optarg);
break; break;
case 'd': case 'd':
if (optarg) if (optarg)
@ -111,6 +108,10 @@ int main(int argc, char *argv[])
return 0; return 0;
case 'i': case 'i':
ascii_image_flag = 1; ascii_image_flag = 1;
if (!optarg && argv[optind] != NULL && argv[optind][0] != '-')
sprintf(image_name, "%s", argv[optind++]);
else if (optarg)
sprintf(image_name, "%s", optarg);
break; break;
case 'l': case 'l':
list(argv[0]); list(argv[0]);
@ -119,6 +120,7 @@ int main(int argc, char *argv[])
break; break;
} }
} }
parse_config();
if ((argc == 1 && ascii_image_flag == 0) || (argc > 1 && ascii_image_flag == 0)) if ((argc == 1 && ascii_image_flag == 0) || (argc > 1 && ascii_image_flag == 0))
print_ascii(); print_ascii();
else if (ascii_image_flag) else if (ascii_image_flag)
@ -132,15 +134,20 @@ void parse_config()
char line[256]; char line[256];
char *homedir = getenv("HOME"); char *homedir = getenv("HOME");
char *temp_buffer = ""; char *temp_buffer = "";
FILE *config;
FILE *config = fopen(strcat(homedir, "/.config/uwufetch/config"), "r"); if (config_directory == NULL)
config = fopen(strcat(homedir, "/.config/uwufetch/config"), "r");
else
config = fopen(config_directory, "r");
if (config == NULL) if (config == NULL)
return; return;
while (fgets(line, sizeof(line), config)) while (fgets(line, sizeof(line), config))
{ {
if (line[0] == '#') if (line[0] == '#')
continue; continue;
ascii_image_flag = sscanf(line, "image=%s", image_name); if (strlen(image_name) < 1 && ascii_image_flag == 0)
ascii_image_flag = sscanf(line, "image=%s", image_name);
sscanf(line, "distro=%s", version_name); sscanf(line, "distro=%s", version_name);
if (sscanf(line, "nouser%s", temp_buffer)) if (sscanf(line, "nouser%s", temp_buffer))
show_user_info = 0; show_user_info = 0;
@ -621,11 +628,10 @@ void usage(char *arg)
{ {
printf("Usage: %s <args>\n" printf("Usage: %s <args>\n"
" -a, --ascii prints logo as ascii text (default)\n" " -a, --ascii prints logo as ascii text (default)\n"
" -c, --custom choose a custom image\n" // this options should be different, maybe merged with `-i` " -c --config use custom config path\n"
" --config use custom config path\n"
" -d, --distro lets you choose the logo to print\n" " -d, --distro lets you choose the logo to print\n"
" -h, --help prints this help page\n" " -h, --help prints this help page\n"
" -i, --image prints logo as image\n" // someone should add an optional argument to change image without using `-c`, but I don't know how to do it. " -i, --image prints logo as image and use a custom image if provided\n"
" %sworks in most terminals\n" " %sworks in most terminals\n"
" read README.md for more info%s\n" " read README.md for more info%s\n"
" -l, --list lists all supported distributions\n", " -l, --list lists all supported distributions\n",

View file

@ -21,10 +21,7 @@ uwufetch - A meme system info tool for Linux, based on nyan/uwu trend on r/linux
-a --ascii\ -a --ascii\
prints the logo as ascii text (default) prints the logo as ascii text (default)
-c --custom\ -c --config\
you can choose a custom image path
--config\
you can change config path you can change config path
-d --distro\ -d --distro\
@ -34,7 +31,8 @@ you can choose the logo to print by the distro name
prints a help page prints a help page
-i --image\ -i --image\
prints image instead of ascii logo prints image instead of ascii logo\
uses a custom image if one is provided
-l --list\ -l --list\
prints a list of all supported distributions prints a list of all supported distributions