This commit is contained in:
2026-01-24 05:25:45 +00:00
parent 73c54192f7
commit ee39628557
3 changed files with 81 additions and 132 deletions

58
dotfiles/banner/banner.sh Normal file
View File

@@ -0,0 +1,58 @@
#!/usr/bin/env bash
# Banner module (global/user). Runs once per login session.
case "$-" in
*i*) ;;
*) return 0 ;;
esac
# Disable switch (per-user/per-shell)
# 1) env: DISABLE_GLOBAL_BANNER=1
# 2) file: ~/.config/ps1/disable-banner
if [[ "${DISABLE_GLOBAL_BANNER:-0}" == "1" ]]; then
return 0
fi
if [[ -f "$HOME/.config/ps1/disable-banner" ]]; then
return 0
fi
# Run banner only once per session
if [[ -n "${__BANNER_ALREADY_SHOWN:-}" ]]; then
return 0
fi
__BANNER_ALREADY_SHOWN=1
# Find tools (be defensive)
FIGLET="$(command -v figlet 2>/dev/null || true)"
LANDSCAPE="$(command -v landscape-sysinfo 2>/dev/null || true)"
# lolcat is often /usr/games/lolcat on Ubuntu
if [[ -x /usr/games/lolcat ]]; then
LOLCAT="/usr/games/lolcat"
else
LOLCAT="$(command -v lolcat 2>/dev/null || true)"
fi
# If lolcat missing, fallback to cat (no color)
if [[ -z "${LOLCAT:-}" ]]; then
LOLCAT="cat"
fi
# Punchline source:
# - global file: /etc/ps1-punchline
# - fallback: "Hello"
PUNCHLINE="Hello"
if [[ -r /etc/ps1-punchline ]]; then
PUNCHLINE="$(cat /etc/ps1-punchline 2>/dev/null || echo "Hello")"
fi
# Print banner (only if figlet exists)
if [[ -n "${FIGLET:-}" ]]; then
"$FIGLET" "$(hostname)" -c | "$LOLCAT"
"$FIGLET" -f digital "$PUNCHLINE" -c | "$LOLCAT"
fi
# Print sysinfo if available (Linux)
if [[ -n "${LANDSCAPE:-}" ]]; then
"$LANDSCAPE" | "$LOLCAT"
fi

View File

@@ -10,21 +10,24 @@ SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
SRC_PS1="$REPO_ROOT/ps1/ps1.sh"
SRC_BANNER="$REPO_ROOT/banner/banner.sh"
DST_PS1="/etc/profile.d/ps1.sh"
DST_BANNER="/etc/profile.d/banner.sh"
BASH_BASHRC="/etc/bash.bashrc"
MARKER_START="# >>> global ps1 (managed) >>>"
MARKER_END="# <<< global ps1 (managed) <<<"
if [[ ! -r "$SRC_PS1" ]]; then
echo "Fant ikke $SRC_PS1"
exit 1
fi
MARKER_START="# >>> dotfiles (managed) >>>"
MARKER_END="# <<< dotfiles (managed) <<<"
# Copy modules
cp -f "$SRC_PS1" "$DST_PS1"
chmod 0644 "$DST_PS1"
# Ensure /etc/bash.bashrc sources it (idempotent)
cp -f "$SRC_BANNER" "$DST_BANNER"
chmod 0644 "$DST_BANNER"
# Ensure /etc/bash.bashrc sources both (idempotent)
tmp="$(mktemp)"
awk -v s="$MARKER_START" -v e="$MARKER_END" '
$0==s {inside=1; next}
@@ -37,17 +40,24 @@ rm -f "$tmp"
cat >> "$BASH_BASHRC" <<EOF
$MARKER_START
# Load global PS1 (managed)
# Load PS1 + Banner (managed)
if [ -r "$DST_PS1" ]; then
. "$DST_PS1"
fi
if [ -r "$DST_BANNER" ]; then
. "$DST_BANNER"
fi
$MARKER_END
EOF
echo "✅ Linux/WSL global PS1 installert:"
echo " $DST_PS1"
echo " og sourcet fra $BASH_BASHRC"
echo "✅ Installert globalt (Linux/WSL):"
echo " - $DST_PS1"
echo " - $DST_BANNER"
echo " - sourcet fra $BASH_BASHRC"
echo
echo "Disable per bruker:"
echo " export DISABLE_GLOBAL_PS1=1"
echo " eller touch ~/.config/ps1/disable"
echo " export DISABLE_GLOBAL_BANNER=1"
echo " eller:"
echo " mkdir -p ~/.config/ps1 && touch ~/.config/ps1/disable # disable PS1"
echo " mkdir -p ~/.config/ps1 && touch ~/.config/ps1/disable-banner # disable banner"