fetch

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

commit a5b31cdb29fc7978bc348582105d8efba40e927c
parent 5b6cf09700ac421e2049f6f9d017daf5d368a484
Author: Byron Torres <b@torresjrjr>
Date:   Thu, 28 Jan 2021 12:58:30 +0000

Print status lines sequentially, not as one block

Diffstat:
Mfetch | 120+++++++++++++++++++++++++++++++++++++++++++++++++------------------------------
1 file changed, 75 insertions(+), 45 deletions(-)

diff --git a/fetch b/fetch @@ -2,8 +2,6 @@ # A fetch for MSYS2 on Windows. # @torresjrjr -printf '...\r' # initial wait - ## Prepare colours and palette c0=$(printf '\e[0m' ) c1=$(printf '\e[31m'); c2=$(printf '\e[32m') @@ -13,9 +11,12 @@ 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 -graphic_height=6 +graphic_y=7 +graphic_x=15 + d='\t' # delimiter -graphic=$(printf "\ +graphic() { + printf "\ ${c2} ~ ${d} ${c2} .-. ${d} ${c2} /\`v\`\\ ${d} @@ -23,56 +24,85 @@ ${c2} (/ \\) ${d} ${c2}======\"=\"===< ${d} ${c2} |_| ${d} ${c2} ${d}${c0} -") +" +} +## draw util cursor_reset() { printf '\r' - for i in $(seq $1); do printf '\e[A'; done + for i in $(seq ${graphic_y}); do printf '\e[A'; done } -printf '%s' "${graphic}" # initial graphic +padding() { + for i in $(seq ${graphic_x}); do printf '\e[C'; done +} -## Get variables -date=$(date -R) -shell=${SHELL##*/} -user=${USER} -host=$(hostname) -os=$(uname -o) # see `man uname` -kernel_name=$(uname -s) -kernel_release=$(uname -r) +## Create statuslines +_title() { + 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" +} +_sshd() { + sshd_pid=$(ps | grep sshd | awk '{print $1}' | paste -s) + sshd_pid=${sshd_pid:---} + printf "${c6}sshd: ${c0}${sshd_pid}\n" +} +_tmux() { + if ps | grep tmux >/dev/null + then + tmux_sessions=$( + tmux ls \ + | sed \ + -e 's/(created[^)]*)//' -e 's/(attached)/@/' \ + -e 's/windows/w/' -e 's/ //g' \ + | paste -s + ) + else + tmux_sessions='--' + fi + printf "${c6}tmux: ${c0}${tmux_sessions}\n" +} -sshd_pid=$(ps | grep sshd | awk '{print $1}' | paste -s) -sshd_pid=${sshd_pid:---} +## Create status +status() { + padding; _title + padding; _os + padding; _kernel + padding; _shell + padding; _sshd + padding; _tmux +} -if ps | grep tmux >/dev/null -then - tmux_sessions=$( - tmux ls \ - | sed \ - -e 's/(created[^)]*)//' -e 's/(attached)/@/' \ - -e 's/windows/w/' -e 's/ //g' \ - | paste -s - ) -else - tmux_sessions='--' -fi +#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} +#" -## Create status -status="\ -${c5}${user}@${host}${c3} ${date} -${c6}os: ${c0}${os} -${c6}kernel: ${c0}${kernel_name} ${kernel_release} -${c6}shell: ${c0}${shell} -${c6}sshd: ${c0}${sshd_pid} -${c6}tmux: ${c0}${tmux_sessions} -" +main() { + printf '...\r' # initial wait + graphic + cursor_reset + status + echo +} -## Print fetch -tmpfile=/tmp/fetch_graphic.tmp -printf '%s' "${graphic}" > "${tmpfile}" -printf '%s\n' "$( - cursor_reset ${graphic_height}; - printf '%s' "${status}" | paste -d '' "${tmpfile}" - -)" +main # @torresjrjr