File: diyfetch

package info (click to toggle)
gum 0.17.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 668 kB
  • sloc: sh: 232; ruby: 24; makefile: 17; javascript: 9; python: 4
file content (100 lines) | stat: -rwxr-xr-x 3,939 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/sh

#  ____ _____   ____      _       _
# |  _ \_ _\ \ / / _| ___| |_ ___| |__
# | | | | | \ V / |_ / _ \ __/ __| '_ \
# | |_| | |  | ||  _|  __/ || (__| | | |
# |____/___| |_||_|  \___|\__\___|_| |_|
#
# About:
#   DIYfetch it the shell script template for writing fetch tool
#   utilizing `gum join` command (https://github.com/charmbracelet/gum#join).
#
#   This script is written in POSIX-shell for portability
#   feel free to switch it to any scripting language that you prefer.
#
# Note:
#   When copy ANSI string from random script make sure to replace "\033" and "\e" to ""
#   or wrap it in `$(printf '%b' "<ansi_string>")`.
#
# URL: https://github.com/info-mono/diyfetch


# Prepare ------------------------------------------------------------------------------------------

# You can lookup the color codes on https://wikipedia.org/wiki/ANSI_escape_code#8-bit
main_color=4

# You can add some eye candy icons with Emoji of use Nerd Fonts (https://www.nerdfonts.com).
info=$(gum style "[1;38;5;${main_color}m${USER}@[1;38;5;${main_color}m$(hostname)
----------------
[1;38;5;${main_color}mOS:        <your_os>
[1;38;5;${main_color}mKERNEL:    $(uname -sr)
[1;38;5;${main_color}mUPTIME:    $(uptime -p | cut -c 4-)
[1;38;5;${main_color}mSHELL:     $(basename "${SHELL}")
[1;38;5;${main_color}mEDITOR:    $(basename "${EDITOR:-<your_editor>}")
[1;38;5;${main_color}mDE:        <your_de>
[1;38;5;${main_color}mWM:        <your_wm>
[1;38;5;${main_color}mTERMINAL:  <your_terminal>")

# You can get OS arts on https://github.com/info-mono/os-ansi
# copy the raw data of the .ansi file then paste it down below.
art=$(gum style '    ___
   (.. |
   (<> |
  / __  \
 ( /  \/ |
_/\ __)/_)
\/-____\/')

# You can generate colorstrip using https://github.com/info-mono/colorstrip
color=$(gum style '████████████████████████
████████████████████████')


# Display ------------------------------------------------------------------------------------------

# The code in this section is to display the fetch adaptively to the terminal's size.
# If you just want a static fetch display, you can just use something like this:
#
#   group_info_color=$(gum join --vertical "${info}" '' "${color}")
#   gum join --horizontal --align center '  ' "${art}" '  ' "${group_info_color}"

terminal_size=$(stty size)
terminal_height=${terminal_size% *}
terminal_width=${terminal_size#* }

# Acknowledge of how high the shell prompt is so the prompt don't push the fetch out.
prompt_height=${PROMPT_HEIGHT:-1}

print_test() {
	no_color=$(printf '%b' "${1}" | sed -e 's/\x1B\[[0-9;]*[JKmsu]//g')

	[ "$(printf '%s' "${no_color}" | wc --lines)" -gt $(( terminal_height - prompt_height )) ] && return 1
	[ "$(printf '%s' "${no_color}" | wc --max-line-length)" -gt "${terminal_width}" ] && return 1

	gum style --align center --width="${terminal_width}" "${1}" ''
	printf '%b' "\033[A"

	exit 0
}


# Paper layout
print_test "$(gum join --vertical --align center "${art}" '' "${info}" '' "${color}")"

# Classic layout
group_info_color=$(gum join --vertical "${info}" '' "${color}")
print_test "$(gum join --horizontal --align center "${art}" '  ' "${group_info_color}")"

# Hybrid layout
group_art_info=$(gum join --horizontal --align center "${art}" '  ' "${info}")
print_test "$(gum join --vertical --align center "${group_art_info}" '' "${color}")"

# Other layout
print_test "$(gum join --vertical --align center "${art}" '' "${info}")"
print_test "${group_art_info}"
print_test "${group_info_color}"
print_test "${info}"

exit 1