fakefetch

This is my version of neofetch
git clone git://shipwreckt.co.uk/fakefetch.git
Log | Files | Refs | README | LICENSE

fakefetch.c (5545B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 #include <string.h>
      4 
      5 //    __      _         __     _       _
      6 //   / _|    | |       / _|   | |     | |
      7 //  | |_ __ _| | _____| |_ ___| |_ ___| |__
      8 //  |  _/ _` | |/ / _ \  _/ _ \ __/ __| '_ \
      9 //  | || (_| |   <  __/ ||  __/ || (__| | | |
     10 //  |_| \__,_|_|\_\___|_| \___|\__\___|_| |_|
     11 
     12 // Note: I have tried to make this as user friendly as possable/
     13 
     14 //----------------------------------------------------------------------------------|
     15 //                               Welcome to fakefetch                               |
     16 //----------------------------------------------------------------------------------|
     17 //                             This is just neofetch but                            |
     18 //                             You do it yourself, now in C!                        |
     19 //----------------------------------------------------------------------------------|
     20 //             This is Libre code, you can do whatever you want with it since       |
     21 //                                  it is under the GPL                             |
     22 // ---------------------------------------------------------------------------------|
     23 // Function to execute shell commands and get the output                            |
     24 // ---------------------------------------------------------------------------------|
     25 char* execute_command(const char* command) {
     26     char* result = malloc(128 * sizeof(char));
     27     FILE* fp;
     28     if ((fp = popen(command, "r")) == NULL) {
     29         printf("Error opening pipe!\n");
     30         return NULL;
     31     }
     32     if (fgets(result, 128, fp) == NULL) {
     33         printf("Error reading pipe!\n");
     34         return NULL;
     35     }
     36     pclose(fp);
     37 
     38     // Remove newline character
     39     result[strcspn(result, "\n")] = '\0';
     40     return result;
     41 }
     42 
     43 int main() {
     44     // ---------------------------------------------------------------------------------------------------//
     45     // Colour codes
     46     // ---------------------------------------------------------------------------------------------------//
     47     
     48     // Define colours by changing the last two letters to Xterm number
     49     const char* PURPLE = "\033[38;5;92m";
     50     const char* MAGENTA = "\033[38;5;98m";
     51     const char* RESET = "\033[0m";
     52     
     53     // Set colours
     54     const char* Text = MAGENTA;
     55     const char* Background = PURPLE;
     56 
     57     // ---------------------------------------------------------------------------------------------------//
     58     
     59     // Get system information
     60     char* USERNAME = execute_command("whoami");
     61     char* HOSTNAME = execute_command("uname -n");
     62     char* DISTRO = execute_command("lsb_release -sd | sed 's/\"//g'");
     63     char* CPU_INFO = execute_command("lscpu | grep 'Model name' | awk '{$1=$2=\"\"; print $0}' | sed 's/^[ \\t]*//'");
     64     char* CORES = execute_command("lscpu | grep 'Core(s) per socket' | awk '{print $NF}'");
     65     char* GPU_INFO = execute_command("lspci | grep -i 'VGA\\|3D' | sed 's/.*: //; s/ (.*//'");
     66     char* UPTIME = execute_command("uptime -p | sed 's/up //'");
     67 
     68     // Terminal and package manager
     69     const char* TERMINAL = "Alacritty";                              //Still need to work on the terminal bit 
     70     char* PACKAGE_MANAGER = execute_command(
     71         "if command -v pacman &> /dev/null; then echo Pacman; "
     72         "elif command -v apt-get &> /dev/null; then echo APT; "
     73         "else echo Unknown; fi"
     74     );
     75     
     76     // ---------------------------------------------------------------------------------------------------//
     77     // Print output
     78     // ---------------------------------------------------------------------------------------------------//
     79     printf("%s                   ::                %s\n", Background, RESET);
     80     printf("%s                  .==.               %s\n", Background, RESET);
     81     printf("%s                  ====               %s\n", Background, RESET);
     82     printf("%s                 -=====              %s@%s%s\n", Background, USERNAME, HOSTNAME, RESET);
     83     printf("%s                -======              ========================================%s\n", Background, RESET);
     84     printf("%s               :========-            OS  → %s%s%s\n", Background, Text, DISTRO, RESET);
     85     printf("%s              :.:-=======-           GPU → %s%s%s\n", Background, Text, GPU_INFO, RESET);
     86     printf("%s             :==---=======-          PM  → %s%s%s\n", Background, Text, PACKAGE_MANAGER, RESET);
     87     printf("%s            :==============-         Term → %s%s%s\n", Background, Text, TERMINAL, RESET);
     88     printf("%s           :================-        Uptime → %s%s%s\n", Background, Text, UPTIME, RESET);
     89     printf("%s          :==================-       ========================================%s\n", Background, RESET);
     90     printf("%s         :========----========-      %s\n", Background, RESET);
     91     printf("%s        -========.    .========-     %s\n", Background, RESET);
     92     printf("%s       -========        =========    %s\n", Background, RESET);
     93     printf("%s      -========:        :======---.  %s\n", Background, RESET);
     94     printf("%s     -=========:        .=======-:.  %s\n", Background, RESET);
     95     printf("%s    =========--:        .--=======-: %s\n", Background, RESET);
     96     printf("%s   .=====-:..                ..:-=====%s\n", Background, RESET);
     97     printf("%s .==-:.                          .:-==:%s\n", Background, RESET);
     98 
     99     // Free up memory
    100     free(USERNAME);
    101     free(HOSTNAME);
    102     free(DISTRO);
    103     free(CPU_INFO);
    104     free(CORES);
    105     free(GPU_INFO);
    106     free(UPTIME);
    107     free(PACKAGE_MANAGER);
    108 
    109     return 0;
    110 }