ohmu
·
2026-09-26
1#!/bin/sh
2#
3# Copyright 2025 r1w1s1
4# All rights reserved.
5#
6# Redistribution and use of this script, with or without modification, is
7# permitted provided that the following conditions are met:
8#
9# 1. Redistributions of this script must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11#
12# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
13# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
14# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
15# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
16# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
18# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
19# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
20# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
21# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22#
23# slackfetch - minimal, truthful system info for Slackware
24#
25# Based on ufetch by J. Schillinger.
26# Window manager detection uses EWMH via xprop only (no guessing).
27# Non-EWMH window managers may set SLACKFETCH_WM manually.
28#
29# Usage:
30# slackfetch
31# NO_COLOR=1 slackfetch # disable color output (https://no-color.org)
32
33## BASIC INFO
34
35if [[ "$1" == "-9" ]]; then
36 NO_COLOR=1
37fi
38
39host="$(uname -n)"; host="${host%%.*}"
40kernel="$(uname -sr) ($(uname -m))"
41
42# Uptime
43uptime=""
44if [ -r /proc/uptime ]; then
45 IFS=. read -r s _ < /proc/uptime
46 d=$((s / 60 / 60 / 24))
47 h=$((s / 60 / 60 % 24))
48 m=$((s / 60 % 60))
49
50 [ "$d" -gt 0 ] && uptime="${uptime}${d}d "
51 [ "$h" -gt 0 ] && uptime="${uptime}${h}h "
52 [ "$m" -gt 0 ] && uptime="${uptime}${m}m "
53 [ -z "$uptime" ] && uptime="0m"
54fi
55
56libc=""
57for libc_file in /lib64/libc.so.6 /lib/libc.so.6; do
58 if [ -x "$libc_file" ]; then
59 libc_ver="$("$libc_file" 2>/dev/null \
60 | sed -n 's/^GNU C Library.* version \([0-9][0-9.]*[0-9]\).*/\1/p')"
61 if [ -n "$libc_ver" ]; then
62 libc="glibc $libc_ver"
63 break
64 fi
65 fi
66done
67
68## OS
69
70os="$(cat /etc/slackware-version 2>/dev/null)"
71
72if [ -r /etc/os-release ]; then
73 . /etc/os-release
74 os=$PRETTY_NAME
75fi
76
77## SHELL (pretty name)
78
79shell="${SHELL##*/}"
80case "$shell" in
81 bash) [ -n "$BASH_VERSION" ] && shell="$shell ${BASH_VERSION%%(*}" ;;
82 zsh) shell="zsh"
83 [ -n "$ZSH_VERSION" ] && shell="$shell $ZSH_VERSION" ;;
84esac
85
86## MULTIPLEXER
87[ -n "$TMUX" ] && shell="$shell (tmux)"
88[ -n "$STY" ] && shell="$shell (screen)"
89[ -n "$MTM" ] && shell="$shell (mtm)"
90
91## DESKTOP MANAGER
92
93de="${XDG_CURRENT_DESKTOP##*:}"
94case "$de" in
95 KDE)
96 if command -v plasmashell >/dev/null 2>&1; then
97 ver="$(plasmashell --version 2>/dev/null | sed -n 's/.* \([0-9][0-9.]*\).*/\1/p')"
98 [ -n "$ver" ] && de="$de $ver"
99 fi ;;
100 XFCE)
101 if command -v xfce4-session >/dev/null 2>&1; then
102 ver="$(xfce4-session --version 2>/dev/null | sed -n '1s/^xfce4-session \([0-9.]*\).*/\1/p')"
103 [ -n "$ver" ] && de="$de $ver"
104 fi ;;
105esac
106
107[ -n "$de" ] && de="$(printf '%s\n' "$de" | tr '[:upper:]' '[:lower:]')"
108
109## WINDOW MANAGER (strict)
110
111wm=""
112wm_server=""
113
114# User override (for twm, mwm, etc.)
115if [ -n "$SLACKFETCH_WM" ]; then
116 wm="$SLACKFETCH_WM"
117
118# EWMH via xprop (X11 only)
119elif [ -n "$DISPLAY" ] && command -v xprop >/dev/null 2>&1; then
120 wm_id="$(xprop -root _NET_SUPPORTING_WM_CHECK 2>/dev/null \
121 | awk '{print $5}')"
122 if [ -n "$wm_id" ] && [ "$wm_id" != "not" ]; then
123 wm="$(xprop -id "$wm_id" _NET_WM_NAME 2>/dev/null \
124 | sed -n 's/.*= "\(.*\)"/\1/p')"
125 [ -n "$wm" ] && wm_server="X11"
126 fi
127fi
128
129[ -n "$wm" ] && wm="$(printf '%s\n' "$wm" | tr '[:upper:]' '[:lower:]')"
130
131## DISPLAY SERVER
132
133display=""
134if [ -n "$WAYLAND_DISPLAY" ]; then
135 display="Wayland"
136elif [ -n "$DISPLAY" ]; then
137 xver="$(/usr/libexec/Xorg -version 2>&1)"
138 ver="$(printf '%s\n' "$xver" \
139 | sed -n 's/.*X Server \([0-9][0-9.]*\).*/\1/p')"
140 case "$xver" in
141 *XLibre*) display="XLibre" ;;
142 *X.Org*) display="X.Org" ;;
143 *) display="XLibre 25.2" ;;
144 esac
145 [ -n "$ver" ] && display="$display $ver"
146fi
147
148## OS AGE (days since Slackware installation)
149
150os_age=""
151birth="$(stat -c %Y /var/lib/pkgtools/packages/aaa_base-* 2>/dev/null | head -1)"
152if [ -n "$birth" ] && [ "$birth" -gt 0 ] 2>/dev/null; then
153 os_age="$(( ($(date +%s) - birth) / 86400 ))d"
154fi
155[ -n "$os_age" ] && uptime="$uptime (age $os_age)"
156
157## Machine Model
158
159if [ -n "$SLACKFETCH_MODEL" ]; then
160 model="$SLACKFETCH_MODEL"
161else
162 sys_vendor="$(cat /sys/devices/virtual/dmi/id/sys_vendor 2>/dev/null)"
163 product_name="$(cat /sys/devices/virtual/dmi/id/product_name 2>/dev/null)"
164 product_version="$(cat /sys/devices/virtual/dmi/id/product_version 2>/dev/null)"
165 case "$sys_vendor" in
166 LENOVO) model="$product_version" ;;
167 Dell*)
168 case "$product_name" in
169 Dell*) model="$product_name" ;;
170 *) model="Dell $product_name" ;;
171 esac ;;
172 *) model="$product_name" ;;
173 esac
174 [ -n "$model" ] || model="$product_version"
175fi
176
177## PACKAGE COUNT
178
179packages=$(kiss l | wc -l)
180
181## COLORS
182
183if [ -z "$NO_COLOR" ] && command -v tput >/dev/null 2>&1; then
184 bold="$(tput bold)"
185 blue="$(tput setaf 4)"
186 reset="$(tput sgr0)"
187fi
188lc="${reset}${bold}${blue}" # labels
189nc="${reset}${bold}" # header
190ic="${reset}" # values
191c0="${reset}${bold}${blue}" # logo
192
193## OUTPUT
194
195session=""
196session_extra=""
197if [ -n "$de" ]; then
198 session="${lc}de: ${ic}${de}${reset}"
199 [ -n "$wm" ] && session_extra="
200${c0} ${lc}wm: ${ic}${wm}${display:+ ($display)}${reset}"
201elif [ -n "$wm" ]; then
202 session="${lc}wm: ${ic}${wm}${display:+ ($display)}${reset}"
203fi
204
205cat <<EOF
206
207${c0} /'._ ${nc}${USER}${ic}@${nc}${host} (${model})${reset}
208${c0} (° o 7 ${lc}os: ${ic}${os}${reset}
209${c0} |'-'"~. . ${lc}kernel: ${ic}${kernel}${reset}
210${c0} Uu^~C_J._." ${libc:+${lc}libc: ${ic}${libc}${reset}}
211${c0} ${lc}uptime: ${ic}${uptime}${reset}
212${c0} ${lc}shell: ${ic}${shell}${reset}
213${c0} ${packages:+${lc}pkgs: ${ic}${packages}${reset}}
214${c0} ${session}${session_extra}
215
216EOF
217
218# Ensure terminal colors are fully reset
219[ -n "$reset" ] && printf '%s' "$reset"
220
221# Color palette aligned with labels
222if [ -z "$NO_COLOR" ]; then
223 printf ' '
224 for i in 0 1 2 3 4 5 6 7; do
225 printf '\033[4%dm \033[0m' "$i"
226 done
227 printf '\n\n'
228fi