-
Notifications
You must be signed in to change notification settings - Fork 1
/
ifetch.sh
executable file
·146 lines (121 loc) · 3.15 KB
/
ifetch.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
#!/bin/bash
. /etc/os-release
BLACK='\E[0;30m'
RED='\E[0;31m'
GREEN='\E[0;32m'
YELLOW='\E[0;33m'
BLUE='\E[0;34m'
PURPLE='\E[0;35m'
CYAN='\E[0;36m'
WHITE='\E[0;37m'
RESET='\E[0m'
line() {
echo "├─ ${BLUE}$1${RESET}: $2\n"
}
FETCH=""
add() {
if [[ "$1" == "user" ]]; then
FETCH="# ${PURPLE}$USER@$HOSTNAME${RESET}\n"
return
fi
if [[ "$1" == "color" ]]; then
FETCH="${FETCH}└─ $BLACK $RED $GREEN $YELLOW $BLUE $PURPLE $CYAN $WHITE $RESET\n"
return
fi
if [[ "$1" == "os" ]]; then
FETCH="${FETCH}$(line "OS" "$ID")"
return
fi
if [[ "$1" == "host" ]]; then
HOST_NAME=$(cat /sys/devices/virtual/dmi/id/product_name)
HOST_VERSION=$(cat /sys/devices/virtual/dmi/id/product_version)
FETCH="${FETCH}$(line "Host" "$HOST_NAME ($HOST_VERSION)")"
return
fi
if [[ "$1" == "kernel" ]]; then
FETCH="${FETCH}$(line "Kernel" "$(uname -r)")"
return
fi
if [[ "$1" == "uptime" ]]; then
FETCH="${FETCH}$(line "Uptime" "$(uptime -p)")"
return
fi
if [[ "$1" == "shell" ]]; then
FETCH="${FETCH}$(line "Shell" "$(basename $SHELL)")"
return
fi
if [[ "$1" == "terminal" ]]; then
FETCH="${FETCH}$(line "Terminal" "$TERM")"
return
fi
if [[ "$1" == "memory" ]]; then
TOTAL_MEMORY=$(free -m | awk 'NR==2 {print $2}')
USAGE_MEMORY=$(free -m | awk 'NR==2 {print $3}')
FETCH="${FETCH}$(line "Memory" "${USAGE_MEMORY} / ${TOTAL_MEMORY} Mib")"
return
fi
if [[ "$1" == "swap" ]]; then
TOTAL_MEMORY=$(free -m | awk 'NR==3 {print $2}')
USAGE_MEMORY=$(free -m | awk 'NR==3 {print $3}')
FETCH="${FETCH}$(line "Swap" "${USAGE_MEMORY} / ${TOTAL_MEMORY} Mib")"
return
fi
if [[ "$1" == "cpu" ]]; then
FETCH="${FETCH}$(line "CPU" "$(lscpu | grep 'Model name' | cut -f 2 -d ":" | awk '{$1=$1}1')")"
return
fi
if [[ "$1" == "local ip" ]]; then
FETCH="${FETCH}$(line "Local IP" "$(ip route get 1.2.3.4 | awk '{print $7}')")"
return
fi
if [[ "$1" == "locale" ]]; then
FETCH="${FETCH}$(line "Locale" "$LANG")"
return
fi
}
###############################################################
add "user" # start
add "os"
add "host"
add "kernel"
add "uptime"
add "shell"
add "terminal"
add "memory"
add "swap"
add "cpu"
add "local ip"
add "locale"
add "color" # end
###############################################################
PID=$(shuf -i 1-809 -n 1)
readarray -t sprite <<< $(cat "$(dirname $0)/colorscripts/${PID}" | sed -e 's/$/\\E[0m/g' | sed '$d')
readarray -t info <<< $(printf "$FETCH")
width="${sprite[0]}"
width="${width//[^▀▄ ]}"
width="${#width}"
slen=${#sprite[@]}
ilen=${#info[@]}
printf '\n'
if [ $slen -ge $ilen ]; then
center=$((($slen - $ilen) / 2))
for ((i=0; i <= $slen; i++)); do
printf " ${sprite[i]}"
if [ $i -ge $center ]; then
echo " ${info[$(($i-$center))]}"
else
echo ""
fi
done
else
center=$((($ilen - $slen) / 2))
for ((i=0; i <= $ilen; i++)); do
if [ $i -ge $center -a $i -lt $(($center + $slen)) ]; then
printf " ${sprite[$(($i-$center))]}"
else
printf " "
printf ' %.0s' $(seq $width)
fi
echo " ${info[i]}"
done
fi