-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimfetch
More file actions
executable file
·171 lines (149 loc) · 6.67 KB
/
Copy pathsimfetch
File metadata and controls
executable file
·171 lines (149 loc) · 6.67 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash
# --- Color Scheme: Catppuccin Mocha https://github.com/catppuccin/catppuccin ---
PINK='\033[38;2;245;194;231m'
MAUVE='\033[38;2;203;166;247m'
RED='\033[38;2;243;139;168m'
PEACH='\033[38;2;250;179;135m'
YELLOW='\033[38;2;249;226;175m'
GREEN='\033[38;2;166;227;161m'
TEAL='\033[38;2;148;226;213m'
SKY='\033[38;2;137;220;235m'
BLUE='\033[38;2;137;180;250m'
LAVENDER='\033[38;2;180;190;254m'
TEXT='\033[38;2;205;214;244m'
SUBTEXT1='\033[38;2;186;194;222m'
NC='\033[0m'
# ----------------------------------------
# --- USER CONFIGURATION ---
DISPLAY_MODE="ascii" # options: "ascii" or "image"
IMAGE_PATH="" # your image path here, e.g.
SPACING=5
# ----------------------------
# --- ICON + LABEL (NERD FONTS) https://www.nerdfonts.com/cheat-sheet ---
LBL_DISTRO="${SKY} Distro${NC}"
LBL_KERNEL="${PEACH} Kernel${NC}"
LBL_UPTIME="${YELLOW} Uptime${NC}"
LBL_DE="${PINK} DE${NC}"
LBL_WM="${MAUVE} WM${NC}"
LBL_CPU="${RED} CPU${NC}"
LBL_GPU="${RED} GPU${NC}"
LBL_SHELL="${TEAL} Shell${NC}"
LBL_PACKAGES="${GREEN} Packages${NC}"
LBL_MEMORY="${GREEN} Memory${NC}"
# -----------------------------------
# --- FUNCTION: Get System Information ---
get_info() {
user_info="$USER@$(hostname)"
if [ -f /etc/os-release ]; then . /etc/os-release; distro_info="$PRETTY_NAME"; else distro_info=$(uname -s); fi
kernel_info=$(uname -r)
uptime_info=$(uptime -p | sed 's/up //')
de_info="${XDG_CURRENT_DESKTOP:-}"
if [ -z "$de_info" ]; then
if pgrep -x "gnome-shell" >/dev/null; then de_info="GNOME";
elif pgrep -x "plasmashell" >/dev/null; then de_info="KDE Plasma";
elif pgrep -x "xfce4-session" >/dev/null; then de_info="XFCE";
else de_info="Unknown"; fi
fi
de_info="${de_info##*:}"
de_info="${de_info^}"
declare -A wm_processes=(
[kwin_x11]="KWin" [kwin_wayland]="KWin" [mutter]="Mutter"
[xfwm4]="Xfwm4" [i3]="i3" [bspwm]="bspwm" [sway]="Sway"
[Hyprland]="Hyprland" [openbox]="Openbox" [fluxbox]="Fluxbox"
[qtile]="Qtile" [marco]="Marco" [dwm]="dwm"
)
wm_info="Unknown"
for process in "${!wm_processes[@]}"; do
if pgrep -x "$process" &>/dev/null; then
wm_info="${wm_processes[$process]}"
break
fi
done
if [[ "$wm_info" == "Unknown" ]]; then
case "$de_info" in
"GNOME") wm_info="Mutter" ;;
"KDE Plasma") wm_info="KWin" ;;
"XFCE") wm_info="Xfwm4" ;;
esac
fi
cpu_info=$(grep "model name" /proc/cpuinfo | head -n1 | cut -d: -f2 | sed 's/^[ \t]*//')
if command -v lspci >/dev/null; then
gpu_info=$(lspci | grep -Ei 'VGA|3D' | head -n1 | sed -e 's/^.*: //' -e 's/ (rev ..)//')
else
gpu_info="lspci not found"
fi
shell_info=$(basename "$SHELL")
if command -v apt >/dev/null; then
packages_info="$(dpkg-query -f '.\n' -W | wc -l) (apt)"
elif command -v pacman >/dev/null; then
packages_info="$(pacman -Q | wc -l) (pacman)"
else
packages_info="Unknown"
fi
memory_display=$(free -m | awk '/^Mem:/ {printf "%.1f / %.1f GB (%d%%)\n", $3/1024, $2/1024, $3*100/$2}')
}
# --- FUNCTION: Display ASCII Tux ---
display_tux_ascii() {
local c1="$TEXT" c2="$SUBTEXT1" c3="$YELLOW"
printf "%b" \
"\n\
${c2} #####\n\
#######\n\
##${c1}O${c2}#${c1}O${c2}##\n\
#${c3}#####${c2}#\n\
##${c1}##${c3}###${c1}##${c2}##\n\
#${c1}##########${c2}##\n\
#${c1}############${c2}##\n\
#${c1}############${c2}###\n\
${c3} ##${c2}#${c1}###########${c2}##${c3}#\n\
######${c2}#${c1}#######${c2}#${c3}######\n\
#######${c2}#${c1}#####${c2}#${c3}#######\n\
#####${c2}#######${c3}#####\n"
}
# --- FUNCTION: Display Main Information ---
display_info() {
clear
get_info
local temp_art=$(mktemp)
local temp_info=$(mktemp)
trap 'rm -f "$temp_art" "$temp_info"' EXIT
if [[ "$DISPLAY_MODE" == "image" ]] && [ -f "$IMAGE_PATH" ] && command -v chafa >/dev/null; then
chafa "$IMAGE_PATH" --size "x13" --format=ansi > "$temp_art"
else
display_tux_ascii > "$temp_art"
fi
{
local labels=("$LBL_DISTRO" "$LBL_KERNEL" "$LBL_UPTIME" "$LBL_DE" "$LBL_WM" "$LBL_CPU" "$LBL_GPU" "$LBL_SHELL" "$LBL_PACKAGES" "$LBL_MEMORY")
local values=("$distro_info" "$kernel_info" "$uptime_info" "$de_info" "$wm_info" "$cpu_info" "$gpu_info" "$shell_info" "$packages_info" "$memory_display")
local max_label_len=0; for label in "${labels[@]}"; do local len; len=$(echo -ne "$label" | sed 's/\x1b\[[0-9;?]*[mK]//g' | wc -m); if (( len > max_label_len )); then max_label_len=$len; fi; done
local info_lines=(); for i in "${!labels[@]}"; do info_lines+=("$(printf "%-*b : ${TEXT}%s${NC}" "$max_label_len" "${labels[i]}" "${values[i]}")"); done
local max_total_len=0; for line in "${info_lines[@]}"; do local len; len=$(echo -ne "$line" | sed 's/\x1b\[[0-9;?]*[mK]//g' | wc -m); if (( len > max_total_len )); then max_total_len=$len; fi; done
local title=" ${BLUE} ${user_info}${NC} "; local title_visible; title_visible=$(echo -e "$title" | sed 's/\x1b\[[0-9;?]*[mK]//g'); local title_len=${#title_visible}
local bar_width=$((max_total_len + 2)); local total_bar_len=$((bar_width - title_len)); local left_bar_len=$((total_bar_len / 2)); local right_bar_len=$((total_bar_len - left_bar_len))
local top_border="╭$(printf '─%.0s' $(seq 1 $left_bar_len))${title}$(printf '─%.0s' $(seq 1 $right_bar_len))╮"
local bottom_border="╰$(printf '─%.0s' $(seq 1 $bar_width))╯"
echo -e "\n ${LAVENDER}${top_border}${NC}"; for line in "${info_lines[@]}"; do local visible_line; visible_line=$(echo -e "$line" | sed 's/\x1b\[[0-9;?]*[mK]//g'); local current_len=${#visible_line}; local padding=$((max_total_len - current_len)); printf " ${LAVENDER}│${NC} %s%*s ${LAVENDER}│${NC}\n" "$line" "$padding" ""; done; echo -e " ${LAVENDER}${bottom_border}${NC}"
} > "$temp_info"
tput civis
trap 'tput cnorm; rm -f "$temp_art" "$temp_info"' EXIT INT TERM
mapfile -t art_lines < "$temp_art"
mapfile -t info_lines < "$temp_info"
local art_width=0
for line in "${art_lines[@]}"; do
local len
len=$(echo -ne "$line" | sed 's/\x1b\[[0-9;?]*[mK]//g' | wc -m)
if (( len > art_width )); then art_width=$len; fi
done
local info_col=$((art_width + SPACING))
local max_lines=$(( ${#art_lines[@]} > ${#info_lines[@]} ? ${#art_lines[@]} : ${#info_lines[@]} ))
for ((i=0; i<$max_lines; i++)); do
tput cup "$i" 0
echo -ne "${art_lines[i]}"
tput cup "$i" "$info_col"
echo -e "${info_lines[i]}"
done
tput cup $max_lines 0
tput cnorm
}
# Run the script
display_info