From 1ce0e2ad424bf38768094488774eff23b3871ccc Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 20 Aug 2016 00:43:35 +1200 Subject: Port all bash_profile.d scripts to POSIX sh Also require flag files in ~/.welcome for displaying or not displaying login stuff --- sh/profile.d/fortune.sh | 24 ++++++++++++++++++++++++ sh/profile.d/remind.sh | 19 +++++++++++++++++++ sh/profile.d/verse.sh | 28 ++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 sh/profile.d/fortune.sh create mode 100644 sh/profile.d/remind.sh create mode 100644 sh/profile.d/verse.sh (limited to 'sh/profile.d') diff --git a/sh/profile.d/fortune.sh b/sh/profile.d/fortune.sh new file mode 100644 index 00000000..a5894108 --- /dev/null +++ b/sh/profile.d/fortune.sh @@ -0,0 +1,24 @@ +# Only if shell is interactive +case $- in + *i*) ;; + *) return ;; +esac + +# Only if not in a tmux window +[ -z "$TMUX" ] || return + +# Only if ~/.welcome/fortune exists and ~/.hushlogin doesn't +[ -e "$HOME"/.welcome/fortune ] || return +! [ -e "$HOME"/.hushlogin ] || return + +# Only if fortune(6) available +command -v fortune >/dev/null 2>&1 || return + +# Print from subshell to keep namespace clean +( + if [ -d "$HOME"/.local/share/games/fortunes ] ; then + : "${FORTUNE_PATH:="$HOME"/.local/share/games/fortunes}" + fi + fortune -s "$FORTUNE_PATH" + printf '\n' +) diff --git a/sh/profile.d/remind.sh b/sh/profile.d/remind.sh new file mode 100644 index 00000000..3ef0f353 --- /dev/null +++ b/sh/profile.d/remind.sh @@ -0,0 +1,19 @@ +# Only if shell is interactive +case $- in + *i*) ;; + *) return ;; +esac + +# Only if not in a tmux window +[ -z "$TMUX" ] || return + +# Only if ~/.welcome/remind exists and ~/.hushlogin doesn't +[ -e "$HOME"/.welcome/remind ] || return +! [ -e "$HOME"/.hushlogin ] || return + +# Only if rem(1) available +command -v rem >/dev/null 2>&1 || return + +# Print reminders with asterisks +rem -hq | sed 's/^/* /' +printf '\n' diff --git a/sh/profile.d/verse.sh b/sh/profile.d/verse.sh new file mode 100644 index 00000000..781d68bc --- /dev/null +++ b/sh/profile.d/verse.sh @@ -0,0 +1,28 @@ +# Only if shell is interactive +case $- in + *i*) ;; + *) return ;; +esac + +# Only if not in a tmux window on this machine +[ -z "$TMUX" ] || return + +# Only if ~/.welcome/verse exists and ~/.hushlogin doesn't +[ -e "$HOME"/.welcome/verse ] || return +! [ -e "$HOME"/.hushlogin ] || return + +# Only if verse(1) available +command -v verse >/dev/null 2>&1 || return + +# Run verse(1) if we haven't seen it already today (the verses are selected by +# date); run in a subshell to keep vars out of global namespace +( + now=$(date +%Y-%m-%d) + if [ -f "$HOME"/.verse ] ; then + last=$(cat -- "$HOME"/.verse) + fi + [ "$now" \> "$last" ] || exit + verse + printf '\n' + printf '%s\n' "$now" > "$HOME"/.verse +) -- cgit v1.2.3