Relicense as MIT
[ufetch.git] / ufetch-freebsd
blobacdf7f29a4e1de81441d82c7c603be2f1241b84f
1 #!/bin/sh
3 # ufetch-freebsd - tiny system info for freebsd
5 ## INFO
7 # user is already defined
8 host="$(hostname)"
9 os="$(uname -sr)"
10 kernel="$(uname -iK)"
11 uptime="$(uptime | awk -F, '{sub(".*up ",x,$1);print $1}' | sed -e 's/^[ \t]*//')"
12 packages="$(pkg info | wc -l | sed -e 's/^[ \t]*//')"
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 # probably don't change these
52 if [ -x "$(command -v tput)" ]; then
53 bold="$(tput md 2> /dev/null)"
54 black="$(tput AF 0 2> /dev/null)"
55 red="$(tput AF 1 2> /dev/null)"
56 green="$(tput AF 2 2> /dev/null)"
57 yellow="$(tput AF 3 2> /dev/null)"
58 blue="$(tput AF 4 2> /dev/null)"
59 magenta="$(tput AF 5 2> /dev/null)"
60 cyan="$(tput AF 6 2> /dev/null)"
61 white="$(tput AF 7 2> /dev/null)"
62 reset="$(tput me 2> /dev/null)"
65 # you can change these
66 lc="${reset}${bold}${red}" # labels
67 nc="${reset}${bold}${red}" # user and hostname
68 ic="${reset}" # info
69 c0="${reset}${bold}${red}" # first color
70 c1="${reset}${red}" # second color
72 ## OUTPUT
74 cat <<EOF
76 ${c0} _ ${c1}_____ ${c0}_ ${nc}${USER}${ic}@${nc}${host}${reset}
77 ${c0} / \\\` \`/ \\ ${lc}OS: ${ic}${os}${reset}
78 ${c0} \/ (__/ ${lc}KERNEL: ${ic}${kernel}${reset}
79 ${c1} | | ${lc}UPTIME: ${ic}${uptime}${reset}
80 ${c1} | | ${lc}PACKAGES: ${ic}${packages}${reset}
81 ${c1} \ / ${lc}SHELL: ${ic}${shell}${reset}
82 ${c1} \`-_____-\` ${lc}${uitype}: ${ic}${ui}${reset}
84 EOF