Skip to content

Instantly share code, notes, and snippets.

@robbieh
Created October 11, 2024 21:08
Show Gist options
  • Save robbieh/c12d355ea074a7aeef9d847d76ad69f8 to your computer and use it in GitHub Desktop.
Save robbieh/c12d355ea074a7aeef9d847d76ad69f8 to your computer and use it in GitHub Desktop.
bash banner
#!/bin/bash
#
# An easily-extensible "login banner". Put it in your $PATH and call it from your .bashrc.
# Mainly it shows tmux sessions.
# A "full" view with decorations is given on first run. After that a compact view is
# printed. After an hour has passed the next new terminal will give the full view agian.
columns=$( tput cols )
color1='\033[38;5;036m'
color2='\033[38;5;046m'
reset=`tput op`
figfont=future
function pos
{
local CURPOS
local X
local Y
read -sdR -p $'\E[6n' CURPOS
CURPOS=${CURPOS#*[} # Strip decoration characters <ESC>[
IFS=';' read -ra X Y <<< "$CURPOS" # split on the semicolon
X=$(( X - 1 )) # correct position for my uses
echo "$X $Y" # return in a format for use with tput rc
}
AGE=$( date -r "$0" +%s )
NOW=$( date +%s )
#if this file is not at least 600 seconds old, perform terse outpout
if [ $(( NOW - AGE )) -lt 600 ]
then
tput sc
echo -en $color1
tmux ls -F '#{session_name}' | tr -s '\n' ' ' |
fold -w 40 -s | sed 's/^/ /'
tput rc
echo -en $color1
figlet -f $figfont tmux
tput op
exit 0
fi
touch "$0"
stripe_left() {
echo -en $color1
for x in $(seq 1 $columns ); do echo -n "🭻"; done
echo
echo -en $color2
for x in $(seq 1 $(( columns / 3 ))); do echo -n "🭖🭐 "; done
echo
echo -en $color1
for x in $(seq 1 $columns ); do echo -n "🭶"; done
echo
}
stripe_right() {
echo -en $color1
for x in $(seq 1 $columns ); do echo -n "🭻"; done
echo
echo -en $color2
for x in $(seq 1 $(( columns / 3 ))); do echo -n "🭅🭡 "; done
echo
echo -en $color1
for x in $(seq 1 $columns ); do echo -n "🭶"; done
echo
}
tput op
stripe_left
if command -v tmux 2>&1 >/dev/null
then
#extract_current_cursor_position p1
p1=$(pos)
tput setaf 2
tmux ls -F '#{session_name}|#{t:session_created}|#{?session_attached,attached,-}' | column -t -s '|' | sed 's/^/ /'
#extract_current_cursor_position p2
p2=$(pos)
#tput cup ${p1[0]} ${p1[1]}
tput cup $p1
echo -en $color1
figlet -f $figfont tmux
#tput cup ${p2[0]} ${p2[1]}
tput cup $p2
echo
fi
stripe_right
tput op
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment