| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | |
| 3 | # ____ _____ ____ _ _ |
| 4 | # | _ \_ _\ \ / / _| ___| |_ ___| |__ |
| 5 | # | | | | | \ V / |_ / _ \ __/ __| '_ \ |
| 6 | # | |_| | | | || _| __/ || (__| | | | |
| 7 | # |____/___| |_||_| \___|\__\___|_| |_| |
| 8 | # |
| 9 | # About: |
| 10 | # DIYfetch it the shell script template for writing fetch tool |
| 11 | # utilizing `gum join` command (https://github.com/charmbracelet/gum#join). |
| 12 | # |
| 13 | # This script is written in POSIX-shell for portability |
| 14 | # feel free to switch it to any scripting language that you prefer. |
| 15 | # |
| 16 | # Note: |
| 17 | # When copy ANSI string from random script make sure to replace "\033" and "\e" to "" |
| 18 | # or wrap it in `$(printf '%b' "<ansi_string>")`. |
| 19 | # |
| 20 | # URL: https://github.com/info-mono/diyfetch |
| 21 | |
| 22 | |
| 23 | # Prepare ------------------------------------------------------------------------------------------ |
| 24 | |
| 25 | # You can lookup the color codes on https://wikipedia.org/wiki/ANSI_escape_code#8-bit |
| 26 | main_color=4 |
| 27 | |
| 28 | # You can add some eye candy icons with Emoji of use Nerd Fonts (https://www.nerdfonts.com). |
| 29 | info=$(gum style "[1;38;5;${main_color}m${USER}[0m@[1;38;5;${main_color}m$(hostnamescip-shell system . . hostname.)[0m |
| 30 | ---------------- |
| 31 | [1;38;5;${main_color}mOS: [0m<your_os> |
| 32 | [1;38;5;${main_color}mKERNEL: [0m$(unamescip-shell system . . uname. -sr) |
| 33 | [1;38;5;${main_color}mUPTIME: [0m$(uptimescip-shell system . . uptime. -p | cutscip-shell system . . cut. -c 4-) |
| 34 | [1;38;5;${main_color}mSHELL: [0m$(basenamescip-shell system . . basename. "${SHELL}") |
| 35 | [1;38;5;${main_color}mEDITOR: [0m$(basenamescip-shell system . . basename. "${EDITOR:-<your_editor>}") |
| 36 | [1;38;5;${main_color}mDE: [0m<your_de> |
| 37 | [1;38;5;${main_color}mWM: [0m<your_wm> |
| 38 | [1;38;5;${main_color}mTERMINAL: [0m<your_terminal>") |
| 39 | |
| 40 | # You can get OS arts on https://github.com/info-mono/os-ansi |
| 41 | # copy the raw data of the .ansi file then paste it down below. |
| 42 | art=$(gum style ' [34m___[0m |
| 43 | [34m([0m.. [34m|[0m |
| 44 | [34m([33m<> [34m|[0m |
| 45 | [34m/ [0m__ [34m\[0m |
| 46 | [34m( [0m/ \[34m/ |[0m |
| 47 | [33m_[34m/\ [0m__)[34m/[33m_[34m)[0m |
| 48 | [33m\/[34m-____[33m\/[0m') |
| 49 | |
| 50 | # You can generate colorstrip using https://github.com/info-mono/colorstrip |
| 51 | color=$(gum style '[0;30m███[0;31m███[0;32m███[0;33m███[0;34m███[0;35m███[0;36m███[0;37m███[0m |
| 52 | [0;1;90m███[0;1;91m███[0;1;92m███[0;1;93m███[0;1;94m███[0;1;95m███[0;1;96m███[0;1;97m███[0m') |
| 53 | |
| 54 | |
| 55 | # Display ------------------------------------------------------------------------------------------ |
| 56 | |
| 57 | # The code in this section is to display the fetch adaptively to the terminal's size. |
| 58 | # If you just want a static fetch display, you can just use something like this: |
| 59 | # |
| 60 | # group_info_color=$(gum join --vertical "${info}" '' "${color}") |
| 61 | # gum join --horizontal --align center ' ' "${art}" ' ' "${group_info_color}" |
| 62 | |
| 63 | terminal_size=$(sttyscip-shell system . . stty. size) |
| 64 | terminal_height=${terminal_size% *} |
| 65 | terminal_width=${terminal_size#* } |
| 66 | |
| 67 | # Acknowledge of how high the shell prompt is so the prompt don't push the fetch out. |
| 68 | prompt_height=${PROMPT_HEIGHT:-1} |
| 69 | |
| 70 | print_testscip-shell shell shell-project 0.0.0 print_test().() { |
| 71 | no_color=$(printfscip-shell system . . printf. '%b' "${1}" | sedscip-shell system . . sed. -e 's/\x1B\[[0-9;]*[JKmsu]//g') |
| 72 | |
| 73 | [scip-shell system . . `[`. "$(printfscip-shell system . . printf. '%s' "${no_color}" | wcscip-shell system . . wc. --lines)" -gt $(( terminal_height - prompt_height )) ] && return 1 |
| 74 | [scip-shell system . . `[`. "$(printfscip-shell system . . printf. '%s' "${no_color}" | wcscip-shell system . . wc. --max-line-length)" -gt "${terminal_width}" ] && return 1 |
| 75 | |
| 76 | gum style --align center --width="${terminal_width}" "${1}" '' |
| 77 | printfscip-shell system . . printf. '%b' "\033[A" |
| 78 | |
| 79 | exit 0 |
| 80 | } |
| 81 | |
| 82 | |
| 83 | # Paper layout |
| 84 | print_testscip-shell shell shell-project 0.0.0 print_test(). "$(gum join --vertical --align center "${art}" '' "${info}" '' "${color}")" |
| 85 | |
| 86 | # Classic layout |
| 87 | group_info_color=$(gum join --vertical "${info}" '' "${color}") |
| 88 | print_testscip-shell shell shell-project 0.0.0 print_test(). "$(gum join --horizontal --align center "${art}" ' ' "${group_info_color}")" |
| 89 | |
| 90 | # Hybrid layout |
| 91 | group_art_info=$(gum join --horizontal --align center "${art}" ' ' "${info}") |
| 92 | print_testscip-shell shell shell-project 0.0.0 print_test(). "$(gum join --vertical --align center "${group_art_info}" '' "${color}")" |
| 93 | |
| 94 | # Other layout |
| 95 | print_testscip-shell shell shell-project 0.0.0 print_test(). "$(gum join --vertical --align center "${art}" '' "${info}")" |
| 96 | print_testscip-shell shell shell-project 0.0.0 print_test(). "${group_art_info}" |
| 97 | print_testscip-shell shell shell-project 0.0.0 print_test(). "${group_info_color}" |
| 98 | print_testscip-shell shell shell-project 0.0.0 print_test(). "${info}" |
| 99 | |
| 100 | exit 1 |