Skip to content
Myr

diyfetch

This file

Path

examples/diyfetch

100 lines · 3.8 KiB

Last changed by

Not known.

History of this file

Take it

1#!/bin/sh23#  ____ _____   ____      _       _4# |  _ \_ _\ \ / / _| ___| |_ ___| |__5# | | | | | \ V / |_ / _ \ __/ __| '_ \6# | |_| | |  | ||  _|  __/ || (__| | | |7# |____/___| |_||_|  \___|\__\___|_| |_|8#9# About:10#   DIYfetch it the shell script template for writing fetch tool11#   utilizing `gum join` command (https://github.com/charmbracelet/gum#join).12#13#   This script is written in POSIX-shell for portability14#   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/diyfetch212223# Prepare ------------------------------------------------------------------------------------------2425# You can lookup the color codes on https://wikipedia.org/wiki/ANSI_escape_code#8-bit26main_color=42728# You can add some eye candy icons with Emoji of use Nerd Fonts (https://www.nerdfonts.com).29info=$(gum style "[1;38;5;${main_color}m${USER}@[1;38;5;${main_color}m$(hostname)30----------------31[1;38;5;${main_color}mOS:        <your_os>32[1;38;5;${main_color}mKERNEL:    $(uname -sr)33[1;38;5;${main_color}mUPTIME:    $(uptime -p | cut -c 4-)34[1;38;5;${main_color}mSHELL:     $(basename "${SHELL}")35[1;38;5;${main_color}mEDITOR:    $(basename "${EDITOR:-<your_editor>}")36[1;38;5;${main_color}mDE:        <your_de>37[1;38;5;${main_color}mWM:        <your_wm>38[1;38;5;${main_color}mTERMINAL:  <your_terminal>")3940# You can get OS arts on https://github.com/info-mono/os-ansi41# copy the raw data of the .ansi file then paste it down below.42art=$(gum style '    ___43   (.. |44   (<> |45  / __  \46 ( /  \/ |47_/\ __)/_)48\/-____\/')4950# You can generate colorstrip using https://github.com/info-mono/colorstrip51color=$(gum style '████████████████████████52████████████████████████')535455# Display ------------------------------------------------------------------------------------------5657# 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}"6263terminal_size=$(stty size)64terminal_height=${terminal_size% *}65terminal_width=${terminal_size#* }6667# Acknowledge of how high the shell prompt is so the prompt don't push the fetch out.68prompt_height=${PROMPT_HEIGHT:-1}6970print_test() {71	no_color=$(printf '%b' "${1}" | sed -e 's/\x1B\[[0-9;]*[JKmsu]//g')7273	[ "$(printf '%s' "${no_color}" | wc --lines)" -gt $(( terminal_height - prompt_height )) ] && return 174	[ "$(printf '%s' "${no_color}" | wc --max-line-length)" -gt "${terminal_width}" ] && return 17576	gum style --align center --width="${terminal_width}" "${1}" ''77	printf '%b' "\033[A"7879	exit 080}818283# Paper layout84print_test "$(gum join --vertical --align center "${art}" '' "${info}" '' "${color}")"8586# Classic layout87group_info_color=$(gum join --vertical "${info}" '' "${color}")88print_test "$(gum join --horizontal --align center "${art}" '  ' "${group_info_color}")"8990# Hybrid layout91group_art_info=$(gum join --horizontal --align center "${art}" '  ' "${info}")92print_test "$(gum join --vertical --align center "${group_art_info}" '' "${color}")"9394# Other layout95print_test "$(gum join --vertical --align center "${art}" '' "${info}")"96print_test "${group_art_info}"97print_test "${group_info_color}"98print_test "${info}"99100exit 1