This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfetcher.sh
executable file
·215 lines (191 loc) · 4.88 KB
/
fetcher.sh
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/bin/sh
kernel="$(uname -s)"
print() {
cat <<EOF
Copy and paste the command below in the server.
You can also attach an image to the message, be it your screenshot or wallpaper.
Note that '!setfetch' without 'update' overwrites almost everything,
including the image, but not your git, dotfiles, or description.
Also note that !git, !dotfiles, and !desc are different commands.
!setfetch
Distro: $NAME $ver
Kernel: $(uname -sr)
Terminal: $term
Editor: ${EDITOR##*/}
Shell: ${SHELL##*/}
DE/WM: $wm
Bar: $bar
Resolution: $resolution
Display Protocol: $displayprot
GTK3 Theme: $theme
GTK Icon Theme: $icons
CPU: $cpu
GPU: $gpu
Memory: $ram
EOF
}
if [ "$kernel" = "Linux" ]; then
# get distro
if [ -f /bedrock/etc/os-release ]; then
. /bedrock/etc/os-release
elif [ -f /etc/os-release ]; then
. /etc/os-release
elif [ -f /etc/lsb-release ]; then
. /etc/lsb-release
NAME=$DISTRIB_ID
fi
# get display protocol
[ "$DISPLAY" ] && displayprot="x11"
[ "$WAYLAND_DISPLAY" ] && displayprot="wayland"
# fallback to tty if none is detected
[ ! "$displayprot" ] && displayprot="tty"
# get gtk theme
while read -r line; do
case $line in
gtk-theme*) theme=${line##*=} ;;
gtk-icon-theme*) icons=${line##*=} ;;
esac
done <"${XDG_CONFIG_HOME:-$HOME/.config}/gtk-3.0/settings.ini"
# WMs/DEs
# usually set by GUI display managers and DEs
wm="${XDG_CURRENT_DESKTOP#*:}" # ex: ubuntu:GNOME
[ "$wm" ] || wm="$DESKTOP_SESSION"
# for most WMs
[ ! "$wm" ] && [ "$DISPLAY" ] && command -v xprop >/dev/null && {
id=$(xprop -root -notype _NET_SUPPORTING_WM_CHECK)
id=${id##* }
wm=$(xprop -id "$id" -notype -len 100 -f _NET_WM_NAME 8t |
grep '^_NET_WM_NAME' | cut -d\" -f 2)
}
# for non-EWMH WMs
[ ! "$wm" ] || [ "$wm" = "LG3D" ] &&
wm=$(
ps -e | grep -m 1 -o \
-e "sway" \
-e "kiwmi" \
-e "wayfire" \
-e "sowm" \
-e "catwm" \
-e "fvwm" \
-e "dwm" \
-e "2bwm" \
-e "monsterwm" \
-e "tinywm" \
-e "xmonad"
)
# get gtk theme
case $wm in
*GNOME*)
theme=$(dconf read /org/gnome/desktop/interface/gtk-theme | tr -d "'")
icons=$(dconf read /org/gnome/desktop/interface/icon-theme | tr -d "'")
;;
*)
while read -r line; do
case $line in
gtk-theme*) theme=${line##*=} ;;
gtk-icon-theme*) icons=${line##*=} ;;
esac
done <"${XDG_CONFIG_HOME:-$HOME/.config}/gtk-3.0/settings.ini"
;;
esac
# hardware
while read -r a b _ model; do
case "$a $b" in
"model name")
cpu=$model
break
;;
esac
done </proc/cpuinfo
read -r _ ram </proc/meminfo
# GPU
# other option was 'lspci | grep | grep | tr | grep | sed' then
# if that failed 'lspci | grep | grep | sed' (for iGPUs)
command -v lspci >/dev/null && {
gpu=$(lspci -mm | grep -i 'vga\|display')
gpu=${gpu##*Corporation\"}
gpu=${gpu#*\[AMD/ATI\]}
gpu=${gpu%%\]*}
gpu=${gpu##*\[}
gpu=${gpu#*\"}
set -- "${gpu%%\"*}"
case $* in
*/*Mobile*) gpu="$1 $2 Mobile" ;;
*/*) gpu="$1 $2" ;;
*) gpu="$*" ;;
esac
}
# Terminal, list running processes and check for common terms
term=$(
ps -e | grep -m 1 -o \
-e " alacritty$" \
-e " gnome-terminal$" \
-e " kitty$" \
-e " xterm$" \
-e " u*rxvt[dc]*$" \
-e " [a-z0-9-]*terminal$" \
-e " cool-retro-term$" \
-e " konsole$" \
-e " termite$" \
-e " tilix$" \
-e " sakura$" \
-e " terminator$" \
-e " termonad$" \
-e " x*st$" \
-e " tilda$"
)
# remove leading space
term=${term# }
# Screen resolution
unset i resolution
command -v xrandr >/dev/null && {
for i in $(xrandr --current | grep ' connected' | grep -o '[0-9]\+x[0-9]\+'); do
resolution="$resolution$i, "
done
resolution=${resolution%, }
}
# bar
bar=$(
ps -e | grep -m 1 -o \
-e " i3bar$" \
-e " dzen2$" \
-e " tint2$" \
-e " xmobar$" \
-e " swaybar$" \
-e " polybar$" \
-e " lemonbar$" \
-e " taffybar$"
)
bar=${bar# }
print
elif [ "$kernel" = "Darwin" ]; then
NAME="macOS"
# get MacOS version
ver=$(
defaults read /System/Library/CoreServices/SystemVersion.plist \
ProductUserVisibleVersion
)
# get WM
wm="$(
ps -e | grep -o \
-e "[S]pectacle" \
-e "[A]methyst" \
-e "[k]wm" \
-e "[c]hun[k]wm" \
-e "[y]abai" \
-e "[R]ectangle" | head -n1
)"
# if the current WM isn't on this list, assume default DE
wm="${wm:-Aqua}"
# hardware
cpu="$(sysctl -n machdep.cpu.brand_string)"
ram="$(sysctl -n hw.memsize)"
case $TERM_PROGRAM in
"Terminal.app" | "Apple_Terminal") term="Apple Terminal" ;;
"iTerm.app") term="iTerm2" ;;
*) term="${TERM_PROGRAM%.app}" ;;
esac
print
else
echo "Unsupported OS; please add support on https://github.com/unixporn/trup"
fi