lots of snippets
[dotfiles.git] / Scripts / ufetch-arch
1 #!/bin/sh
2 #
3 # ufetch-arch - tiny system info for arch
4
5 ## INFO
6
7 # user is already defined
8 hostname="$(hostname)"
9 os='Arch Linux'
10 host="$(cat /sys/devices/virtual/dmi/id/product_name) $(cat /sys/devices/virtual/dmi/id/product_family)"
11 kernel="$(uname -sr)"
12 uptime="$(uptime -p | sed 's/up //')"
13 packages="$(pacman -Q | wc -l)"
14 shell="$(basename "${SHELL}")"
15 term="$TERM"
16
17 ## UI DETECTION
18
19 parse_rcs() {
20         for f in "${@}"; do
21                 wm="$(tail -n 1 "${f}" 2> /dev/null | cut -d ' ' -f 2)"
22                 [ -n "${wm}" ] && echo "${wm}" && return
23         done
24 }
25
26 rcwm="$(parse_rcs "${HOME}/.xinitrc" "${HOME}/.xsession")"
27
28 ui='unknown'
29 uitype='UI'
30 if [ -n "${DE}" ]; then
31         ui="${DE}"
32         uitype='DE'
33 elif [ -n "${WM}" ]; then
34         ui="${WM}"
35         uitype='WM'
36 elif [ -n "${XDG_CURRENT_DESKTOP}" ]; then
37         ui="${XDG_CURRENT_DESKTOP}"
38         uitype='DE'
39 elif [ -n "${DESKTOP_SESSION}" ]; then
40         ui="${DESKTOP_SESSION}"
41         uitype='DE'
42 elif [ -n "${rcwm}" ]; then
43         ui="${rcwm}"
44         uitype='WM'
45 elif [ -n "${XDG_SESSION_TYPE}" ]; then
46         ui="${XDG_SESSION_TYPE}"
47 fi
48
49 ui="$(basename "${ui}")"
50
51 ## DEFINE COLORS
52
53 # probably don't change these
54 if [ -x "$(command -v tput)" ]; then
55         bold="$(tput bold)"
56         black="$(tput setaf 0)"
57         red="$(tput setaf 1)"
58         green="$(tput setaf 2)"
59         yellow="$(tput setaf 3)"
60         blue="$(tput setaf 4)"
61         magenta="$(tput setaf 5)"
62         cyan="$(tput setaf 6)"
63         white="$(tput setaf 7)"
64         reset="$(tput sgr0)"
65 fi
66
67 # you can change these
68 lc="${reset}${bold}${blue}"         # labels
69 nc="${reset}${bold}${yellow}"         # user and hostname
70 ic="${reset}"                       # info
71 c0="${reset}${cyan}"                # first color
72
73 ## OUTPUT
74
75 # ${c0}        /\\         ${nc}${USER}${ic}@${nc}${hostname}${reset}
76 # ${c0}       /  \\        ${lc}OS:        ${ic}${os}${reset}
77 # ${c0}      /\\   \\       ${lc}KERNEL:    ${ic}${kernel}${reset}
78 # ${c0}     /  __  \\      ${lc}HOST:      ${ic}${host}${reset}      
79 # ${c0}    /  (  )  \\     ${lc}UPTIME:    ${ic}${uptime}${reset}
80 # ${c0}   / __|  |__\\\\    ${lc}PACKAGES:  ${ic}${packages}${reset}
81 # ${c0}  /.\`        \`.\\   ${lc}SHELL:     ${ic}${shell}${reset}
82 #                    ${lc}${uitype}:        ${ic}${ui}${reset}
83 #   ${bold}${red}██${green}██${yellow}██${blue}██${magenta}██${cyan}██${white}██${reset}   ${lc}TERM:      ${ic}${term}${reset}
84
85   # ${bold}${red}██${green}██${yellow}██${blue}██${magenta}██${cyan}██${white}██${reset}                 
86
87 cat <<EOF
88
89 ${c0}         .         ${nc}${USER}${ic}@${nc}${hostname}${reset}
90 ${c0}        / \\        ${lc}OS:        ${ic}${os}${reset}
91 ${c0}       /   \\       ${lc}KERNEL:    ${ic}${kernel}${reset}   
92 ${c0}      /^.   \\      ${lc}HOST:      ${ic}${host}${reset}  
93 ${c0}     /  .-.  \\     ${lc}UPTIME:    ${ic}${uptime}${reset}  
94 ${c0}    /  (   ) _\\    ${lc}PACKAGES:  ${ic}${packages}${reset}  
95 ${c0}   / _.~   ~._^\\   ${lc}${uitype}:        ${ic}${ui}${reset}
96 ${c0}  /.^         ^.\\  ${lc}TERM:      ${ic}${term}${reset}
97
98 EOF