From 69dabe5a87f556505b6dd05ea2250df293b4889b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 10 Jun 2015 10:44:18 +1200 Subject: Instate .bash_profile.d Stuff that prints messages really only needs to be done for my primary login shell --- Makefile | 6 ++++-- README.markdown | 10 +++++----- bash/bash_profile | 10 ++++++++++ bash/bash_profile.d/fortune.bash | 8 ++++++++ bash/bash_profile.d/remind.bash | 8 ++++++++ bash/bash_profile.d/verse.bash | 15 +++++++++++++++ sh/profile.d/remind.sh | 6 ------ sh/profile.d/verse.sh | 15 --------------- 8 files changed, 50 insertions(+), 28 deletions(-) create mode 100644 bash/bash_profile.d/fortune.bash create mode 100644 bash/bash_profile.d/remind.bash create mode 100644 bash/bash_profile.d/verse.bash delete mode 100644 sh/profile.d/remind.sh delete mode 100644 sh/profile.d/verse.sh diff --git a/Makefile b/Makefile index 24006419..26457567 100644 --- a/Makefile +++ b/Makefile @@ -64,10 +64,12 @@ install : install-bash \ install-bash : test-bash install -m 0755 -d -- \ "$(HOME)"/.config \ - "$(HOME)"/.bashrc.d + "$(HOME)"/.bashrc.d \ + "$(HOME)"/.bash_profile.d install -m 0644 -- bash/bashrc "$(HOME)"/.bashrc install -m 0644 -- bash/bashrc.d/* "$(HOME)"/.bashrc.d install -m 0644 -- bash/bash_profile "$(HOME)"/.bash_profile + install -m 0644 -- bash/bash_profile.d/* "$(HOME)"/.bash_profile.d install -m 0644 -- bash/bash_logout "$(HOME)"/.bash_logout install -m 0644 -- bash/bash_completion "$(HOME)"/.config/bash_completion @@ -216,7 +218,7 @@ test-sh : @echo "All sh(1) scripts parsed successfully." test-bash : - @for bash in bash/* bash/bashrc.d/* ; do \ + @for bash in bash/* bash/bashrc.d/* bash/bash_profile.d/* ; do \ if [ -f "$$bash" ] && ! bash -n "$$bash" ; then \ exit 1 ; \ fi \ diff --git a/README.markdown b/README.markdown index 4f50e384..d39e2ef6 100644 --- a/README.markdown +++ b/README.markdown @@ -97,11 +97,11 @@ by `.profile` are saved in `.profile.d` and iterated on login for ease of management. All of these boil down to exporting variables appropriate to the system and the software it has available. -My `.bash_profile` calls `.profile` for variable exports, and then runs -`.bashrc` for interactive shells. Subscripts are kept in `.bashrc.d`, and all -are loaded for the creation of any new interactive shell. The contents of this -directory changes all the time depending on the host, and only specific scripts -in it are versioned. +My `.bash_profile` calls `.profile` for variable exports, runs subscripts in +`.bash_profile.d`. It then runs `.bashrc`, which only applies for interactive +shells; subscripts are loaded from `.bashrc.d`. interactive shell. The contents +of this directory changes all the time depending on the host, and only specific +scripts in it are versioned. My interactive and scripting shell of choice is Bash; as a GNU/Linux admin who ends up installing Bash on \*BSD machines anyway, I very rarely have to write diff --git a/bash/bash_profile b/bash/bash_profile index 7366840e..05b15693 100644 --- a/bash/bash_profile +++ b/bash/bash_profile @@ -11,6 +11,16 @@ elif ((10#${BASH_VERSINFO[0]%%[![:digit:]]*} == 2)) && \ return fi +# Load any supplementary scripts +if [[ -d $HOME/.bash_profile.d ]] ; then + for bash_profile in "$HOME"/.bash_profile.d/*.bash ; do + if [[ -e $bash_profile ]] ; then + source "$bash_profile" + fi + done + unset -v bash_profile +fi + # Source interactive Bash config if it exists if [[ -e $HOME/.bashrc ]] ; then source "$HOME"/.bashrc diff --git a/bash/bash_profile.d/fortune.bash b/bash/bash_profile.d/fortune.bash new file mode 100644 index 00000000..9caa3d3c --- /dev/null +++ b/bash/bash_profile.d/fortune.bash @@ -0,0 +1,8 @@ +# If interactive shell and fortune(6) installed, print a short fortune +if [[ $- == *i* ]] && hash fortune 2>/dev/null ; then ( + if [[ -d "$HOME"/.local/share/games/fortunes ]] ; then + FORTUNE_PATH=${FORTUNE_PATH:-$HOME/.local/share/games/fortunes} + fi + fortune -sn "${FORTUNE_MAXSIZE:-1024}" "$FORTUNE_PATH" +) ; fi + diff --git a/bash/bash_profile.d/remind.bash b/bash/bash_profile.d/remind.bash new file mode 100644 index 00000000..50a3d8c8 --- /dev/null +++ b/bash/bash_profile.d/remind.bash @@ -0,0 +1,8 @@ +# If interactive and rem(1) installed, run it +if [[ $- == *i* ]] && hash rem 2>/dev/null ; then ( + printf '\n' + while read -r reminder ; do + printf '* %s\n' "$reminder" + done < <(rem -hq) +) ; fi + diff --git a/bash/bash_profile.d/verse.bash b/bash/bash_profile.d/verse.bash new file mode 100644 index 00000000..5d2538dc --- /dev/null +++ b/bash/bash_profile.d/verse.bash @@ -0,0 +1,15 @@ +# Run verse(1) if it's installed and we haven't seen it already today (the +# verses are selected by date); run in a subshell to keep vars out of global +# namespace +if [[ $- == *i* ]] && hash verse 2>/dev/null ; then ( + date=$(date +%Y-%m-%d) + versefile=${VERSEFILE:-$HOME/.verse} + if [[ -e "$HOME"/.verse ]] ; then + read -r lastversedate < "$versefile" + fi + if [[ "$date" > "$lastversedate" ]] ; then + printf '\n%s\n\n' "$(verse)" + printf '%s\n' "$date" > "$versefile" + fi +) ; fi + diff --git a/sh/profile.d/remind.sh b/sh/profile.d/remind.sh deleted file mode 100644 index eec279af..00000000 --- a/sh/profile.d/remind.sh +++ /dev/null @@ -1,6 +0,0 @@ -# Show reminders on login -if command -v remind >/dev/null 2>&1 && [ -r "$HOME"/.reminders ] ; then - printf '\n' - remind -q "$HOME"/.reminders | sed 's/^/* /' -fi - diff --git a/sh/profile.d/verse.sh b/sh/profile.d/verse.sh deleted file mode 100644 index c4fec152..00000000 --- a/sh/profile.d/verse.sh +++ /dev/null @@ -1,15 +0,0 @@ -# Run verse(1) if it's installed and we haven't seen it already today (the -# verses are selected by date); run in a subshell to keep vars out of global -# namespace -if command -v verse >/dev/null 2>&1 ; then ( - date=$(date +%Y-%m-%d) - versefile=${VERSEFILE:-$HOME/.verse} - if [ -e "$HOME"/.verse ] ; then - read -r lastversedate < "$versefile" - fi - if [ "$date" \> "$lastversedate" ] ; then - printf '\n%s\n\n' "$(verse)" - printf '%s\n' "$date" > "$versefile" - fi -) ; fi - -- cgit v1.2.3