Skip to content

Instantly share code, notes, and snippets.

@sinamics
Created December 30, 2022 15:46
Show Gist options
  • Save sinamics/d1f96f39b797ccb2eba6e8bd539510bc to your computer and use it in GitHub Desktop.
Save sinamics/d1f96f39b797ccb2eba6e8bd539510bc to your computer and use it in GitHub Desktop.
Motd welcome message
#!/bin/bash
# The [ -t 1 ] check only works when the function is not called from
# a subshell (like in `$(...)` or `(...)`, so this hack redefines the
# function at the top level to always return false when stdout is not
# a tty.
# THIS FIEL IS LOADED FROM /etc/zsh/zshrc
if [ -t 1 ]; then
is_tty() {
true
}
else
is_tty() {
false
}
fi
fmt_underline() {
is_tty && printf '\033[4m%s\033[24m\n' "$*" || printf '%s\n' "$*"
}
# shellcheck disable=SC2016 # backtick in single-quote
fmt_code() {
is_tty && printf '`\033[2m%s\033[22m`\n' "$*" || printf '`%s`\n' "$*"
}
supports_truecolor() {
case "$COLORTERM" in
truecolor|24bit) return 0 ;;
esac
case "$TERM" in
iterm |\
tmux-truecolor |\
linux-truecolor |\
xterm-truecolor |\
screen-truecolor) return 0 ;;
esac
return 1
}
setup_color() {
# Only use colors if connected to a terminal
if ! is_tty; then
FMT_RAINBOW=""
FMT_RED=""
FMT_GREEN=""
FMT_YELLOW=""
FMT_BLUE=""
FMT_BOLD=""
FMT_RESET=""
return
fi
if supports_truecolor; then
FMT_RAINBOW="
$(printf '\033[38;2;255;0;0m')
$(printf '\033[38;2;255;97;0m')
$(printf '\033[38;2;247;255;0m')
$(printf '\033[38;2;0;255;30m')
$(printf '\033[38;2;77;0;255m')
$(printf '\033[38;2;168;0;255m')
$(printf '\033[38;2;245;0;172m')
"
else
FMT_RAINBOW="
$(printf '\033[38;5;196m')
$(printf '\033[38;5;202m')
$(printf '\033[38;5;226m')
$(printf '\033[38;5;082m')
$(printf '\033[38;5;021m')
$(printf '\033[38;5;093m')
$(printf '\033[38;5;163m')
"
fi
FMT_RED=$(printf '\033[31m')
FMT_GREEN=$(printf '\033[32m')
FMT_YELLOW=$(printf '\033[33m')
FMT_BLUE=$(printf '\033[34m')
FMT_BOLD=$(printf '\033[1m')
FMT_RESET=$(printf '\033[0m')
}
# shellcheck disable=SC2183 # printf string has more %s than arguments ($FMT_RAINBOW expands to multiple arguments)
print_success() {
printf '%s %s______ %s_ %s_ %s______ %s %s %s\n' $FMT_RAINBOW $FMT_RESET
printf '%s %s/ _____|%s_) %s(_) %s/ _____) %s %s %s\n' $FMT_RAINBOW $FMT_RESET
printf '%s( %s(____ %s_ ____ _____ ____ %s _ ____ ___ %s( (____ _____ %s ____ _ %s _ _____ ____ %s\n' $FMT_RAINBOW $FMT_RESET
printf '%s \%s____ \| %s| _ \(____ | \|%s |/ ___)/___) %s \____ \| ___ |%s/ ___) |%s | | ___ |/ ___)%s\n' $FMT_RAINBOW $FMT_RESET
printf '%s __%s___) ) %s| | | / ___ | | | |%s ( (___|___ | %s _____) ) ____| %s| \ %sV /| ____| | %s\n' $FMT_RAINBOW $FMT_RESET
printf '%s(__%s____/|_%s|_| |_\_____|_|_|_|%s_|\____|___/ %s(______/|_____)_%s| \%s_/ |_____)_| %s\n' $FMT_RAINBOW $FMT_RESET
printf '\n\n'
}
setup_color
print_success
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment