-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add asciifetch, wait_for_pid, install figlet and gum
- Loading branch information
ron.record
committed
Jun 10, 2024
1 parent
a961b76
commit f799f56
Showing
12 changed files
with
1,304 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,312 @@ | ||
#!/bin/bash | ||
# | ||
# asciifetch - display, animate, zoom RoonCommandLine splash screen using Kitty | ||
# | ||
# Written by Ronald Joe Record <[email protected]> | ||
# | ||
# Based on https://github.com/info-mono/diyfetch/blob/main/examples/brandfetch | ||
# from the diyfetch project by Nguyen Nhadt Anh <[email protected]> | ||
|
||
have_gum=$(type -p gum) | ||
[ "${have_gum}" ] || exit 1 | ||
have_wmctrl=`type -p wmctrl` | ||
have_xprop=`type -p xprop` | ||
|
||
pathadd() { | ||
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then | ||
PATH="$1${PATH:+":$PATH"}" | ||
fi | ||
} | ||
|
||
pathadd "/usr/local/bin" | ||
pathadd "/usr/local/Roon/bin" | ||
pathadd "${HOME}/.local/bin" | ||
export PATH | ||
|
||
platform=`uname -s` | ||
if [ "${platform}" == "Darwin" ] | ||
then | ||
KITTY_QUIT_OPT="--override macos_quit_when_last_window_closed=yes" | ||
else | ||
KITTY_QUIT_OPT= | ||
fi | ||
|
||
usage() { | ||
printf "\nUsage: asciifetch [-a] [-f] [-k] [-q] [-z] [-u]" | ||
printf "\nWhere:" | ||
printf "\n\t-a indicates animate display" | ||
printf "\n\t-f indicates fullscreen mode" | ||
printf "\n\t-k indicates do not exit" | ||
printf "\n\t-q indicates quick display, do not sleep" | ||
printf "\n\t-z indicates zoom display" | ||
printf "\n\t-u displays this usage message and exits\n" | ||
exit 1 | ||
} | ||
|
||
add_fullscreen() { | ||
[ "${have_wmctrl}" ] && { | ||
[ "${have_xprop}" ] && { | ||
# The things a man must do | ||
win_id=`wmctrl -lp | grep $(xprop -root | grep _NET_ACTIVE_WINDOW | head -1 | awk '{print $5}' | sed 's/,//' | sed 's/^0x/0x0/') | awk ' { print $1 } '` | ||
[ "${win_id}" ] && xprop -id ${win_id} | grep _NET_WM_STATE | grep FULLSCREEN > /dev/null && isfull=1 | ||
} | ||
[ "${isfull}" ] || { | ||
wmctrl -r ':ACTIVE:' -b add,fullscreen | ||
sleep 1 | ||
set_term_sizes | ||
} | ||
} | ||
} | ||
|
||
remove_fullscreen() { | ||
[ "${have_wmctrl}" ] && { | ||
[ "${isfull}" ] || { | ||
wmctrl -r ':ACTIVE:' -b remove,fullscreen | ||
clear | ||
sleep 1 | ||
set_term_sizes | ||
display_ascii | ||
} | ||
} | ||
} | ||
|
||
cleanup() { | ||
[ "${fullscreen}" == "fullscreen" ] && [ "${animate}" ] && remove_fullscreen | ||
tput cnorm | ||
tput cup ${terminal_height} 0 | ||
parent_name=$(ps -p ${PPID} -o comm=) | ||
if [ "${parent_name}" == "asciifetch" ] | ||
then | ||
exit 2 | ||
else | ||
exit 0 | ||
fi | ||
} | ||
|
||
animate() { | ||
tput civis -- invisible 2> /dev/null | ||
interval="0.1" | ||
lastinterval="0.2" | ||
liftlines=$((terminal_height / 4)) | ||
while true | ||
do | ||
line=1 | ||
tput cup ${terminal_height} 0 | ||
while [ ${line} -lt ${liftlines} ] | ||
do | ||
sleep ${interval} | ||
printf "\n" | ||
line=$((line+1)) | ||
done | ||
|
||
line=1 | ||
tput cup 0 0 | ||
while [ ${line} -lt ${liftlines} ] | ||
do | ||
sleep ${interval} | ||
tput ri | ||
line=$((line+1)) | ||
done | ||
|
||
line=1 | ||
tput cup ${terminal_height} 0 | ||
while [ ${line} -lt ${liftlines} ] | ||
do | ||
sleep ${interval} | ||
printf "\n" | ||
line=$((line+1)) | ||
done | ||
|
||
line=1 | ||
tput cup 0 0 | ||
while [ ${line} -lt ${liftlines} ] | ||
do | ||
sleep ${lastinterval} | ||
tput ri | ||
line=$((line+1)) | ||
done | ||
|
||
[ "${quick}" ] || sleep 2 | ||
[ "${keepalive}" ] || break | ||
done | ||
[ "${fullscreen}" == "fullscreen" ] && remove_fullscreen | ||
tput cup ${terminal_height} 0 | ||
tput cnorm | ||
} | ||
|
||
zoom() { | ||
sock_name="/tmp/fetch_kitty$$" | ||
init_size=32 | ||
interval="0.1" | ||
kitty --title="Asciiville Zoom" \ | ||
--start-as ${fullscreen} \ | ||
--override initial_window_width=98c \ | ||
--override initial_window_height=26c \ | ||
--override allow_remote_control=yes \ | ||
--override dynamic_background_opacity=yes \ | ||
--override background=black \ | ||
--override cursor=#000000 \ | ||
--override font_size=${size} \ | ||
--override draw_minimal_borders=yes \ | ||
--override tab_bar_min_tabs=2 \ | ||
--override startup_session=none \ | ||
${KITTY_QUIT_OPT} \ | ||
--listen-on unix:${sock_name} \ | ||
asciifetch -k 2> /dev/null & | ||
kitty_pid=$! | ||
trap 'cleanup' USR1 | ||
wait_for_pid ${kitty_pid} > /dev/null 2>&1 & | ||
sleep 1 | ||
|
||
if [ "${fullscreen}" == "fullscreen" ] | ||
then | ||
scrollsize=4 | ||
else | ||
scrollsize=2 | ||
fi | ||
while true | ||
do | ||
size=${init_size} | ||
opacity="1.0" | ||
tput cup ${terminal_height} 0 | ||
|
||
[ -S ${sock_name} ] || break | ||
kitty @ --to unix:${sock_name} set-background-opacity ${opacity} 2> /dev/null | ||
kitty @ --to unix:${sock_name} scroll-window ${scrollsize} 2> /dev/null | ||
opacity=$(echo "${opacity}*0.95" | bc) | ||
while [ ${size} -gt 0 ] | ||
do | ||
kitty @ --to unix:${sock_name} set-font-size ${size} 2> /dev/null | ||
kitty @ --to unix:${sock_name} set-background-opacity ${opacity} 2> /dev/null | ||
size=$((size-2)) | ||
opacity=$(echo "${opacity}*0.95" | bc) | ||
done | ||
sleep 0.2 | ||
size=2 | ||
opacity=$(echo "${opacity}*1.05" | bc) | ||
while [ ${size} -lt ${init_size} ] | ||
do | ||
kitty @ --to unix:${sock_name} set-font-size ${size} 2> /dev/null | ||
size=$((size+2)) | ||
kitty @ --to unix:${sock_name} set-background-opacity ${opacity} 2> /dev/null | ||
opacity=$(echo "${opacity}*1.1" | bc) | ||
done | ||
sleep 2 | ||
[ "${keepalive}" ] || break | ||
done | ||
[ -S ${sock_name} ] && kitty @ --to unix:${sock_name} close-window 2> /dev/null | ||
} | ||
|
||
set_term_sizes() { | ||
terminal_size=$(stty size) | ||
terminal_height=${terminal_size% *} | ||
terminal_width=${terminal_size#* } | ||
tput cup ${terminal_height} 0 | ||
} | ||
|
||
print_info() { | ||
no_color=$(printf '%b' "${1}" | sed -e 's/\x1B\[[0-9;]*[JKmsu]//g') | ||
|
||
[ "$(printf '%s' "${no_color}" | wc --lines)" -gt ${terminal_height} ] && { | ||
return 1 | ||
} | ||
[ "$(printf '%s' "${no_color}" | wc --max-line-length)" -gt "${terminal_width}" ] && { | ||
return 1 | ||
} | ||
|
||
gum style --align center --width="${terminal_width}" "${1}" '' | ||
printf '%b' "\033[A" | ||
return 0 | ||
} | ||
|
||
display_ascii() { | ||
# Landscape layout | ||
group_info_color=$(gum join --vertical --align center "${info}" '' "${color}") | ||
print_info "$(gum join --horizontal --align center "${art}" ' ' "${group_info_color}")" | ||
|
||
# Portrait layout | ||
[ $? -eq 0 ] || { | ||
print_info "$(gum join --vertical --align center "${art}" '' "${group_info_color}")" | ||
} | ||
|
||
# Other layout | ||
[ $? -eq 0 ] || { | ||
print_info "${group_info_color}" | ||
print_info "${info}" | ||
} | ||
} | ||
|
||
animate= | ||
fullscreen=normal | ||
keepalive= | ||
quick= | ||
zoom= | ||
while getopts "afkqzu" flag; do | ||
case $flag in | ||
a) | ||
animate=1 | ||
;; | ||
f) | ||
fullscreen=fullscreen | ||
;; | ||
k) | ||
keepalive=1 | ||
;; | ||
q) | ||
quick=1 | ||
;; | ||
z) | ||
have_kitty=`type -p kitty` | ||
[ "${have_kitty}" ] && zoom=1 | ||
;; | ||
u) | ||
usage | ||
;; | ||
esac | ||
done | ||
shift $(( OPTIND - 1 )) | ||
|
||
clear | ||
[ "${fullscreen}" == "fullscreen" ] && [ "${animate}" ] && add_fullscreen | ||
|
||
trap 'cleanup' SIGINT SIGKILL SIGTERM | ||
|
||
title=$(gum style --bold --foreground 12 "$(figlet -d /usr/local/Roon/etc -f Graceful Roon)") | ||
subtitle=$(gum style --italic --foreground 12 'Automated Control of Roon') | ||
info=$(gum join --vertical --align center "${title}" "${subtitle}") | ||
|
||
art=$(gum style --foreground "${main_color}" ' ,~-. | ||
( ʻ )-. ,~ʻ`-. | ||
,~ʻ ` ʻ ) ) _( _) ) | ||
( ( [97m.--.===.--.[0m ( ` ʻ ) | ||
`[97m.%%.[91m###[97m|[0m888[97m.[31m:[97m`.[0m `-ʻ`~~=~ʻ | ||
[97m/%%/[91m####[97m|[0m8888[97m\[31m::[97m\[0m | ||
[97m|%%/[91m#####[97m|[0m88888[97m\[31m::[97m|[0m | ||
[97m|%%|[91m#####[97m|[0m88888[97m|[31m::[97m|[0m.,-. | ||
[97m\%%|[91m#####[97m|[0m88888[97m|[31m::[97m/[0m )_ | ||
[97m\%\[91m#####[97m|[0m88888[97m/[31m:[97m/[0m ( `ʻ ) | ||
[97m\%\[91m####[97m|[0m8888[97m/[31m:[97m/[0m( , -ʻ`-. | ||
,~-. [97m`%\[91m###[97m|[0m888[97m/[31m:[97mʻ[0m( ( ʻ) ) | ||
( ) )_ [97m`\[93m__[97m|[93m__[97m/ʻ[0m `~-~=--~~=ʻ | ||
( ` ʻ) ) [93m[VVVVV][0m | ||
(_(_.~~~ʻ [97m\|[93m_[97m|/[0m | ||
[93m[XXX][0m | ||
[93m`"""ʻ[0m') | ||
|
||
color=$(gum style '[0;30m [0;31m [0;32m [0;33m [0;34m [0;35m [0;36m [0;37m [0m | ||
[0;90m [0;91m [0;92m [0;93m [0;94m [0;95m [0;96m [0;97m [0m') | ||
|
||
[ "${quick}" ] || sleep 1 | ||
set_term_sizes | ||
|
||
display_ascii | ||
|
||
[ "${animate}" ] && animate | ||
[ "${zoom}" ] && zoom | ||
[ "${keepalive}" ] && { | ||
while true | ||
do | ||
sleep 1 | ||
done | ||
} | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
# | ||
# wait_for_pid - wait for pid provided by first argument to exit | ||
# then send signal to parent pid | ||
# | ||
# Useful when a process needs to wait on a child to exit but also | ||
# needs to continue to execute (e.g. the parent is acting as the | ||
# controller of the child, issuing commands over a socket). The | ||
# parent cannot suspend execution to wait for the child to exit. | ||
# Instead, the parent can spawn this process to wait on the pid. | ||
|
||
wait_pid=$1 | ||
|
||
# Can't use 'wait', that requires this process be the parent of the pid | ||
# Use tail instead of wait | ||
tail --pid=${wait_pid} -f /dev/null | ||
|
||
kill -USR1 ${PPID} |
Oops, something went wrong.