-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbfetch
executable file
·65 lines (56 loc) · 2.42 KB
/
bfetch
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
#!/bin/bash
RESTORE='\033[0m'
RED='\033[31m'
GREEN='\033[32m'
YELLOW='\033[33m'
BLUE='\033[34m'
MAGENTA='\033[35m'
PURPLE='\033[35m'
CYAN='\033[36m'
LIGHTGRAY='\033[37m'
LRED='\033[1;31m'
LGREEN='\033[1;32m'
LYELLOW='\033[1;33m'
LBLUE='\033[1;34m'
LMAGENTA='\033[1;35m'
LPURPLE='\033[1;35m'
LCYAN='\033[1;36m'
WHITE='\033[1;37m'
ORANGE='\033[1;33m'
DARK='\033[1;30m'
# One sed(1) call, instead of two. Uses backreferencing (the parentheses) and
# separates multiple (two) commands into the same sed(1) call. Using `-E` flag
# for extended REGEX.
#OS=`sed -E '/^NAME=/!d; s/^NAME="(.*)"$/\1/' /etc/os-release`
# A significantly more efficient yet more advanced approach to the above:
while IFS='=' read KEY VALUE; do
if [ "$KEY" == 'NAME' ]; then
OS=${VALUE//\"}
break
fi
done < /etc/os-release
KERNEL=`uname -r`
while IFS=':' read KEY VALUE; do
if [ "$KEY" == 'MemTotal' ]; then
RAM=$((${VALUE//[![:digit:]]} / 1024))
elif [ "$KEY" == 'MemAvailable' ]; then
RAM_USED=$((${VALUE//[![:digit:]]} / 1024))
elif [ -n "$RAM" -a -n "$RAM_USED" ]; then
RAM_USED=$((RAM - RAM_USED))
# Insert commas to both values. Uncomment these two lines to disable.
printf -v RAM "%'d" $RAM
printf -v RAM_USED "%'d" $RAM_USED
break
fi
done < /proc/meminfo
UPTIME=`uptime | awk '{print $3}' | sed 's/,//g' | sed 's/\:/h /g'`
[ -z "$HOSTNAME" ] && HOSTNAME=`hostname`
#TODO: This needs a LOT of work to be effective, in that it needs to be handled
# dynamically, in order to maintain column widths; a time-consuming task.
echo -e "${BLUE}┏━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓"
echo -e "${BLUE}┃${RESTORE} .${ORANGE}~${RESTORE}. ${BLUE}┃ ${BLUE}$HOSTNAME${RESTORE}@${BLUE}$USER""\t\t"${BLUE}┃
echo -e "${BLUE}┃${RESTORE} ${DARK}/${ORANGE}V${RESTORE}${DARK}\ ${BLUE}┃ ${PURPLE}os${RESTORE}\t\t$OS""\t"${BLUE}┃
echo -e "${BLUE}┃${RESTORE} ${DARK}/${WHITE}/ \\\\${DARK}\ ${BLUE}┃ ${PURPLE}uptime${RESTORE}\t${UPTIME}m""\t\t"${BLUE}┃
echo -e "${BLUE}┃${RESTORE} ${DARK}/${WHITE}( )${DARK}\ ${BLUE}┃ ${PURPLE}kernel${RESTORE}\t$KERNEL""\t"${BLUE}┃
echo -e "${BLUE}┃${RESTORE} ${DARK}^${WHITE}\`${ORANGE}~${WHITE}'${DARK}^ ${BLUE}┃ ${PURPLE}ram${RESTORE}\t""$RAM_USED"M / "$RAM"M"\t"${BLUE}┃
echo -e "${BLUE}┗━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"