完成afetch
parent
e3893a8511
commit
75ff0b9af3
185
src/fetch
185
src/fetch
|
@ -15,16 +15,16 @@ _cbd=$(tput bold) # 加粗
|
|||
_cnc=$(tput sgr0) # 重置(结束)
|
||||
|
||||
# 一些变量
|
||||
FULL=─
|
||||
EMPTY=─
|
||||
FULL="─"
|
||||
EMPTY="─"
|
||||
|
||||
IN_DOCKER='N'
|
||||
|
||||
ARCH_NAME='amd64'
|
||||
|
||||
name=$USER
|
||||
host=$(uname -n)
|
||||
distro=$(uname -o | awk -F '"' '/PRETTY_NAME/ { print $2 }' /etc/os-release)
|
||||
distro_version=$(lsb_release -sr)
|
||||
packages=$(apt list --installed | wc -l)
|
||||
wm=$(xprop -id $(xprop -root -notype | awk '$1=="_NET_SUPPORTING_WM_CHECK:"{print $5}') -notype -f _NET_WM_NAME 8t | grep "WM_NAME" | cut -f2 -d \")
|
||||
storage=$(df -h --output=used,size / | awk 'NR == 2 { print $1,"/",$2 }')
|
||||
|
@ -32,7 +32,7 @@ term=$(ps -o sid= -p "$$" | xargs ps -o ppid= -p | xargs ps -o comm= -p)
|
|||
uptm=$(uptime -p | sed -e 's/up //')
|
||||
|
||||
|
||||
check_is_docker(){
|
||||
function check_is_docker(){
|
||||
if [ -f /.dockerenv ]; then
|
||||
IN_DOCKER="Y"
|
||||
elif [ -f /proc/cmdline ]; then
|
||||
|
@ -42,8 +42,58 @@ check_is_docker(){
|
|||
fi
|
||||
}
|
||||
|
||||
function pad_start() {
|
||||
input_string=$1
|
||||
max_len=$2
|
||||
|
||||
while [ ${#input_string} -lt $max_len ]
|
||||
do
|
||||
input_string=" ${input_string}"
|
||||
done
|
||||
|
||||
echo -n "$input_string"
|
||||
}
|
||||
|
||||
function pad_end() {
|
||||
input_string=$1
|
||||
max_len=$2
|
||||
|
||||
while [ ${#input_string} -lt $max_len ]
|
||||
do
|
||||
input_string+=" "
|
||||
done
|
||||
|
||||
echo -n "$input_string"
|
||||
}
|
||||
|
||||
# progress bar
|
||||
function draw() {
|
||||
perc=$1
|
||||
size=20
|
||||
inc=$((perc * size / 100))
|
||||
out=
|
||||
for v in $(seq 0 $((size - 1))); do
|
||||
test "$v" -le "$inc" &&
|
||||
out="${out}${_ccy}${_cbd}${FULL}" ||
|
||||
out="${out}${_cwh}${EMPTY}"
|
||||
done
|
||||
out+="${_cnc}"
|
||||
echo -n $out
|
||||
}
|
||||
|
||||
function trim() {
|
||||
str=$1
|
||||
str="${str#"${str%%[![:space:]]*}"}" # 前空格
|
||||
str="${str%"${str##*[![:space:]]}"}" # 后空格
|
||||
echo -n "$str"
|
||||
}
|
||||
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
# 获取设备信息
|
||||
get_model() {
|
||||
function get_model() {
|
||||
model=""
|
||||
if [[ -d /system/app/ && -d /system/priv-app ]]; then
|
||||
model="$(getprop ro.product.brand) $(getprop ro.product.model)"
|
||||
|
@ -65,13 +115,11 @@ get_model() {
|
|||
else
|
||||
model="@${host}"
|
||||
fi
|
||||
else
|
||||
model="@${model}"
|
||||
fi
|
||||
}
|
||||
|
||||
# 获取debian的内核版本
|
||||
get_kernel() {
|
||||
function get_kernel() {
|
||||
if [ $IN_DOCKER == "Y" ]; then
|
||||
kernel_version="$(uname -r)-${ARCH_NAME}"
|
||||
else
|
||||
|
@ -80,7 +128,7 @@ get_kernel() {
|
|||
fi
|
||||
}
|
||||
|
||||
get_shell(){
|
||||
function get_shell(){
|
||||
shell_name=${SHELL##*/}
|
||||
shell_version=" "
|
||||
|
||||
|
@ -97,36 +145,60 @@ get_shell(){
|
|||
;;
|
||||
esac
|
||||
|
||||
shell_version=${shell_version/\(*\)}
|
||||
}
|
||||
|
||||
# progress bar
|
||||
draw() {
|
||||
perc=$1
|
||||
size=$2
|
||||
inc=$((perc * size / 100))
|
||||
out=
|
||||
color="$3"
|
||||
for v in $(seq 0 $((size - 1))); do
|
||||
test "$v" -le "$inc" &&
|
||||
out="${out}\e[1;${color}m${FULL}" ||
|
||||
out="${out}\e[0;37m${CWH}${EMPTY}"
|
||||
done
|
||||
printf "$out"
|
||||
function get_cpu() {
|
||||
cpu=$(lscpu | awk -F '\\s*: | @' '/Model name/ {print $2}')
|
||||
cpu_cores=$(lscpu | awk -F '\\s*: | @' '/^CPU\(s\):/ {print $2}')
|
||||
cpu_speed=$(lscpu | awk -F '\\s*: | @' '/CPU max MHz/ {print $2}')
|
||||
|
||||
cpu_cores=$(trim "$cpu_cores")
|
||||
cpu_speed=$(trim "$cpu_speed")
|
||||
cpu_speed=${cpu_speed%.*}
|
||||
cpu_speed="$((cpu_speed / 1000)).${cpu_speed:1}"
|
||||
|
||||
cpu=$(trim "$cpu" | sed -e 's/ Gen//')
|
||||
cpu+=" (${cpu_cores}) ${cpu_speed}GHz"
|
||||
}
|
||||
|
||||
free() {
|
||||
printf "0"
|
||||
function get_gpu() {
|
||||
gpu=$(lspci -mm | awk -F '\"|\" \"|\\(' '/"Display|"3D|"VGA/ { print $(NF-1) }')
|
||||
}
|
||||
|
||||
function get_ram() {
|
||||
ram_total=$(free -m | awk '/Mem:/ {printf "%.2fGB", $2/1024}')
|
||||
ram_used=$(free -m | awk '/Mem:/ {printf "%.2fGB", $3/1024}')
|
||||
ram_perc=$(free -m | awk '/Mem:/ {print int($3/$2 * 100.0)}')
|
||||
}
|
||||
|
||||
function get_screen() {
|
||||
if type -p xrandr >/dev/null; then
|
||||
resolution="$(xrandr --nograb --current | awk 'match($0,/[0-9]*\.[0-9]*\*/) {
|
||||
printf $1 "@" int($2) ", "}')"
|
||||
resolution="${resolution:0: -2}"
|
||||
|
||||
elif type -p xwininfo >/dev/null; then
|
||||
read -r w h <<< "$(xwininfo -root | awk -F':' '/Width|Height/ {printf $2}')"
|
||||
resolution="${w}x${h}"
|
||||
|
||||
elif type -p xdpyinfo >/dev/null; then
|
||||
resolution="$(xdpyinfo | awk '/dimensions:/ {printf $2}')"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
check_is_docker
|
||||
get_model
|
||||
get_kernel
|
||||
get_shell
|
||||
|
||||
|
||||
ram=$(free | awk '/Mem:/ {print int($3/$2 * 100.0)}')
|
||||
get_cpu
|
||||
get_gpu
|
||||
get_ram
|
||||
get_screen
|
||||
|
||||
|
||||
block_1=" ▓▓ "
|
||||
|
@ -134,18 +206,23 @@ block_2=" ▒▒ "
|
|||
block_3=" ░░ "
|
||||
|
||||
|
||||
logo_1="${_cre}${block_1}${block_1}${block_1}${block_1}${block_1}${block_1}${_cnc}"
|
||||
logo_2="${_cbl}${block_1}${_cma}${block_1}${block_1}${block_1}${block_1}${_cgr}${block_1}${_cnc}"
|
||||
logo_3="${_cbl}${block_1}${_cre}${block_1}${_cbk}${block_3}${block_3}${_ccy}${block_1}${_cgr}${block_1}${_cnc}"
|
||||
logo_4="${_cbl}${block_1}${_cre}${block_1}${_cbk}${block_3}${block_3}${_ccy}${block_1}${_cgr}${block_1}${_cnc}"
|
||||
logo_5="${_cbl}${block_1}${_cwh}${block_1}${block_1}${block_1}${_ccy}${block_1}${_cgr}${block_1}${_cnc}"
|
||||
logo_6="${_cye}${block_1}${block_1}${block_1}${block_1}${block_1}${_cgr}${block_1}${_cnc}"
|
||||
logo_1="${_cbd}${_cre}${block_1}${block_1}${block_1}${block_1}${block_1}${block_1}${_cnc}"
|
||||
|
||||
deb_1=" _ _ _ "
|
||||
deb_2=" __| | ___| |__ (_) __ _ _ ___"
|
||||
deb_3=" / _\` |/ _ \ '_ \| |/ _\` | '_ \ "
|
||||
deb_4=" | (_| | __/ |_) | | (_| | | | |"
|
||||
deb_5=" \__,_|\___|_.__/|_|\__,_|_| |_|"
|
||||
logo_2="${_cbd}${_cbl}${block_1}${_cma}${block_1}${block_1}${block_1}${block_1}${_cgr}${block_1}${_cnc}"
|
||||
|
||||
logo_3=${_cbd}"${_cbl}${block_1}${_cwh}${block_1}${_cbk}${block_3}${block_3}${_ccy}${block_1}${_cgr}${block_1}${_cnc}"
|
||||
|
||||
logo_4=${_cbd}"${_cbl}${block_1}${_cwh}${block_1}${_cbk}${block_3}${block_3}${_ccy}${block_1}${_cgr}${block_1}${_cnc}"
|
||||
|
||||
logo_5=${_cbd}"${_cbl}${block_1}${_cwh}${block_1}${block_1}${block_1}${_ccy}${block_1}${_cgr}${block_1}${_cnc}"
|
||||
|
||||
logo_6=${_cbd}"${_cye}${block_1}${block_1}${block_1}${block_1}${block_1}${_cgr}${block_1}${_cnc}"
|
||||
|
||||
deb_1="${_cre}${_cbd} _ _ _ ${_cnc}"
|
||||
deb_2="${_cre}${_cbd} __| | ___| |__ (_) __ _ _ ___${_cnc}"
|
||||
deb_3="${_cre}${_cbd} / _\` |/ _ \ '_ \| |/ _\` | '_ \ ${_cnc}"
|
||||
deb_4="${_cre}${_cbd} | (_| | __/ |_) | | (_| | | | |${_cnc}"
|
||||
deb_5="${_cre}${_cbd} \__,_|\___|_.__/|_|\__,_|_| |_|${_cnc}"
|
||||
|
||||
|
||||
# 输出前清屏
|
||||
|
@ -160,26 +237,26 @@ cat <<EOF
|
|||
│ │ ${deb_5} │
|
||||
│ ${logo_3} │ │
|
||||
│ │ │
|
||||
│ ${logo_4} ├──────────────┬───────────────────────────────────┤
|
||||
│ ${logo_4} ├──────────┬───────────────────────────────────────┤
|
||||
│ │ │ │
|
||||
│ ${logo_5} │ Host │ ${model} │
|
||||
│ │ OS │ │
|
||||
│ ${logo_6} │ Uptime │ ${uptm} │
|
||||
│ ${logo_5} │ ${_cre}${_cbd}Host${_cnc} │ $(pad_end "$model" 35) │
|
||||
│ │ ${_cre}${_cbd}OS${_cnc} │ $(pad_end "$distro" 35) │
|
||||
│ ${logo_6} │ ${_cre}${_cbd}Uptime${_cnc} │ $(pad_end "$uptm" 35) │
|
||||
│ │ │ │
|
||||
├──────────────────────────┼──────────────┴───────────────────────────────────┤
|
||||
├─────────────────┬────────┴──────────┴───────────────────────────────────────┤
|
||||
│ │ │
|
||||
│ ${_cbl}Kernel${_cnc} │ ${kernel_version} │
|
||||
│ ${_cma}Packages${_cnc} │ ${packages} (apt) │
|
||||
│ ${_cgr}Shell${_cnc} │ ${shell_name} ${shell_version} │
|
||||
│ ${_ccy}Resolution${_cnc} │ 2048x1280, 2048x1280 │
|
||||
│ ${_cye}WM${_cnc} │ ${wm} │
|
||||
│ ${_cbl}Terminal${_cnc} │ ${term} │
|
||||
│ ${_cbl}CPU${_cnc} │ ${term} │
|
||||
│ ${_cbl}GPU${_cnc} │ ${term} │
|
||||
│ ${_cbl}Disk${_cnc} │ $(draw "$ram" 15 35) ${ram}% │
|
||||
│ ${_cbl}Memory${_cnc} │ $(draw "$ram" 15 35) ${ram}% │
|
||||
│ ${_cre}${_cbd}$(pad_start "Kernel" 13)${_cnc} │ $(pad_end "$kernel_version" 54) │
|
||||
│ ${_cre}${_cbd}$(pad_start "Packages" 13)${_cnc} │ $(pad_end "${packages} (apt)" 54) │
|
||||
│ ${_cre}${_cbd}$(pad_start "Shell" 13)${_cnc} │ $(pad_end "${shell_name} ${shell_version}" 54) │
|
||||
│ ${_cre}${_cbd}$(pad_start "Resolution" 13)${_cnc} │ $(pad_end "$resolution" 54) │
|
||||
│ ${_cre}${_cbd}$(pad_start "WM" 13)${_cnc} │ $(pad_end "${wm}" 54) │
|
||||
│ ${_cre}${_cbd}$(pad_start "Terminal" 13)${_cnc} │ $(pad_end "${term}" 54) │
|
||||
│ ${_cre}${_cbd}$(pad_start "CPU" 13)${_cnc} │ $(pad_end "${cpu}" 54) │
|
||||
│ ${_cre}${_cbd}$(pad_start "GPU" 13)${_cnc} │ $(pad_end "${gpu}" 54) │
|
||||
│ ${_cre}${_cbd}$(pad_start "Disk" 13)${_cnc} │ $(pad_end "${storage}" 54) │
|
||||
│ ${_cre}${_cbd}$(pad_start "Memory" 13)${_cnc} │ $(draw $ram_perc)$(pad_end " ${ram_perc}% (${ram_used} / ${ram_total})" 34) │
|
||||
│ │ │
|
||||
└──────────────────────────┴──────────────────────────────────────────────────┘
|
||||
└─────────────────┴───────────────────────────────────────────────────────────┘
|
||||
EOF
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue