Relicense as MIT
[ufetch.git] / ufetch-alpine
blob2ab0c4dac5420fc3a80f19ffe4c6ca2704c4efea
1 #!/bin/sh
3 # ufetch-alpine - tiny system info for alpine
5 ## INFO
7 # user is already defined
8 host="$(hostname)"
9 os='Alpine Linux'
10 kernel="$(uname -sr)"
11 uptime="$(uptime | awk -F, '{sub(".*up ",x,$1);print $1}' | sed -e 's/^[ \t]*//')"
12 packages="$(apk info | wc -l)"
13 shell="$(basename "${SHELL}")"
15 ## UI DETECTION
17 parse_rcs() {
18 for f in "${@}"; do
19 wm="$(tail -n 1 "${f}" 2> /dev/null | cut -d ' ' -f 2)"
20 [ -n "${wm}" ] && echo "${wm}" && return
21 done
24 rcwm="$(parse_rcs "${HOME}/.xinitrc" "${HOME}/.xsession")"
26 ui='unknown'
27 uitype='UI'
28 if [ -n "${DE}" ]; then
29 ui="${DE}"
30 uitype='DE'
31 elif [ -n "${WM}" ]; then
32 ui="${WM}"
33 uitype='WM'
34 elif [ -n "${XDG_CURRENT_DESKTOP}" ]; then
35 ui="${XDG_CURRENT_DESKTOP}"
36 uitype='DE'
37 elif [ -n "${DESKTOP_SESSION}" ]; then
38 ui="${DESKTOP_SESSION}"
39 uitype='DE'
40 elif [ -n "${rcwm}" ]; then
41 ui="${rcwm}"
42 uitype='WM'
43 elif [ -n "${XDG_SESSION_TYPE}" ]; then
44 ui="${XDG_SESSION_TYPE}"
47 ui="$(basename "${ui}")"
49 ## DEFINE COLORS
51 bold='\033[1m'
52 black='\033[0;30m'
53 red='\033[0;31m'
54 green='\033[0;32m'
55 yellow='\033[0;33m'
56 blue='\033[0;34m'
57 magenta='\033[0;35m'
58 cyan='\033[0;36m'
59 white='\033[0;37m'
60 reset='\033[0m'
62 # you can change these
63 lc="${reset}${bold}${blue}" # labels
64 nc="${reset}${bold}${blue}" # user and hostname
65 ic="${reset}" # info
66 c0="${reset}${blue}" # first color
68 ## OUTPUT
70 printf "
71 ${c0} /\\ ${nc}${USER}${ic}@${nc}${host}${reset}
72 ${c0} / \\ ${lc}OS: ${ic}${os}${reset}
73 ${c0} / /\\ \\ /\\ ${lc}KERNEL: ${ic}${kernel}${reset}
74 ${c0} / / \\ \\/ \\ ${lc}UPTIME: ${ic}${uptime}${reset}
75 ${c0} / / \\ \\/\\ \\ ${lc}PACKAGES: ${ic}${packages}${reset}
76 ${c0} / / /| \\ \\ \\ \\ ${lc}SHELL: ${ic}${shell}${reset}
77 ${c0} /_/ /_| \\_\\ \\_\\ ${lc}${uitype}: ${ic}${ui}${reset}