fetch

A MSYS2-compatible sys-info prompt
Log | Files | Refs | README | LICENSE

commit e665fcedd99d03370f6b26c147a12b2553da083a
parent a5b31cdb29fc7978bc348582105d8efba40e927c
Author: Byron Torres <b@torresjrjr>
Date:   Thu, 28 Jan 2021 22:13:44 +0000

Rewrite status() with string arguments

Diffstat:
Mfetch | 71++++++++++++++++++++++++++++++++---------------------------------------
1 file changed, 32 insertions(+), 39 deletions(-)

diff --git a/fetch b/fetch @@ -2,20 +2,21 @@ # A fetch for MSYS2 on Windows. # @torresjrjr -## Prepare colours and palette + +## Prepare colours c0=$(printf '\e[0m' ) c1=$(printf '\e[31m'); c2=$(printf '\e[32m') c3=$(printf '\e[33m'); c4=$(printf '\e[34m') c5=$(printf '\e[35m'); c6=$(printf '\e[36m') c7=$(printf '\e[37m'); c8=$(printf '\e[38m') -palette=$(printf "\e[7m$c1 $c1 $c2 $c2 $c3 $c3 $c4 $c4 $c5 $c5 $c6 $c6 \e[m") -## Create graphic + +## Prepare graphic graphic_y=7 graphic_x=15 -d='\t' # delimiter graphic() { + #d=':::::::::::::::::::::::::::::::::::::::::::::' # status background printf "\ ${c2} ~ ${d} ${c2} .-. ${d} @@ -27,8 +28,13 @@ ${c2} ${d}${c0} " } -## draw util -cursor_reset() { +palette() { + printf "\e[7m$c1 $c1 $c2 $c2 $c3 $c3 $c4 $c4 $c5 $c5 $c6 $c6 \e[m" +} + + +## Cursor util +reposition_cursor() { printf '\r' for i in $(seq ${graphic_y}); do printf '\e[A'; done } @@ -37,28 +43,21 @@ padding() { for i in $(seq ${graphic_x}); do printf '\e[C'; done } -## Create statuslines + +## Prepare statuslines _title() { + user="${USER}" host=$(hostname) date=$(date -R) - printf "${c5}${USER}@${host}${c3} ${date}\n" -} -_os() { - os=$(uname -o) - printf "${c6}os: ${c0}${os}\n" -} -_kernel() { - kernel=$(uname -sr) - printf "${c6}kernel: ${c0}${kernel}\n" -} -_shell() { - shell=${SHELL} - printf "${c6}shell: ${c0}${shell}\n" + printf "$1" "${user}" "${host}" "${date}" } +_os() { printf "$1" "$(uname -o)" ;} +_kernel() { printf "$1" "$(uname -sr)" ;} +_shell() { printf "$1" "${SHELL}" ;} _sshd() { sshd_pid=$(ps | grep sshd | awk '{print $1}' | paste -s) sshd_pid=${sshd_pid:---} - printf "${c6}sshd: ${c0}${sshd_pid}\n" + printf "$1" "${sshd_pid}" } _tmux() { if ps | grep tmux >/dev/null @@ -73,32 +72,26 @@ _tmux() { else tmux_sessions='--' fi - printf "${c6}tmux: ${c0}${tmux_sessions}\n" + printf "$1" "${tmux_sessions}" } -## Create status + +## Prepare status status() { - padding; _title - padding; _os - padding; _kernel - padding; _shell - padding; _sshd - padding; _tmux + padding; _title "${c5}%s@%s${c3} %s\n" + padding; _os "${c6}os: ${c0}%s\n" + padding; _kernel "${c6}kernel: ${c0}%s\n" + padding; _shell "${c6}shell: ${c0}%s\n" + padding; _sshd "${c6}sshd: ${c0}%s\n" + padding; _tmux "${c6}tmux: ${c0}%s\n" + #padding; palette } -#status="\ -#${c5}${user}@${host}${c3} ${date} -#${c6}os: ${c0}${os} -#${c6}kernel: ${c0}${kernel} -#${c6}shell: ${c0}${shell} -#${c6}sshd: ${c0}${sshd_pid} -#${c6}tmux: ${c0}${tmux_sessions} -#" +## Run main() { - printf '...\r' # initial wait graphic - cursor_reset + reposition_cursor status echo }