#!/bin/sh
# A fetch for MSYS2 on Windows.
# @torresjrjr <b@torresjrjr.com>
## Main
main() {
config
formatters
graphic
reposition
status
echo
}
## Graphic
graphic() {
env printf "$c6%s\n" \
' ~ ' \
' .-. ' \
' /`v`\ ' \
' (/ \) ' \
'====="="===< ' \
' |_| '
}
## Status
status() {
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
}
## Statuslines
_title() {
printf "$1" "$(whoami)" "$(uname -n)" "$(date -R)"
}
_os() {
printf "$1" "$(uname -o)"
}
_kernel() {
printf "$1" "$(uname -sr)"
}
_shell() {
printf "$1" "$(readlink /proc/$PPID/exe)"
}
_sshd() {
pids=$(ps axc -o 'pid,comm' | awk '/sshd/{printf $1 " "}')
printf "$1" "${pids:---}"
}
_tmux() {
ps axc -o 'comm' | grep -q 'tmux: server' && tmux_sessions=$(
tmux ls -F "#{session_created} #{?session_attached,$ul,}#S:#{session_windows}$c0" \
| sort \
| awk '{printf $2 " "}' \
| xargs -0 printf
)
printf "$1" "${tmux_sessions:---}"
}
_palette() {
printf "$rv$c1 $c2 $c3 $c4 $c5 $c6 $c0\n"
}
## Config
config() {
config="${XDG_CONFIG_HOME:-$HOME/.config}/fetch/config.sh"
[ -f "$config" ] && . "$config"
graphic_y=$(graphic | wc -l) # height
graphic_x=$(graphic | wc -L) # width
}
## Formatters
formatters() {
c0='\x1b[0m' # normal
c1='\x1b[1;31m' # bold red
c2='\x1b[1;32m' # bold green
c3='\x1b[1;33m' # bold yellow
c4='\x1b[1;34m' # bold blue
c5='\x1b[1;35m' # bold magenta
c6='\x1b[1;36m' # bold cyan
c7='\x1b[1;37m' # bold white
ul='\x1b[4m' # underline
rv='\x1b[7m' # reverse video
}
## Cursor util
reposition() { printf '\e[%sA\r' "$graphic_y" ;}
padding() { printf '\e[%sC' "$graphic_x" ;}
## Run
main