Restructure .bashrc.d for prefix-ordered mass sourcing.
authorW. Trevor King <wking@drexel.edu>
Wed, 30 Nov 2011 20:42:51 +0000 (15:42 -0500)
committerW. Trevor King <wking@drexel.edu>
Wed, 30 Nov 2011 20:57:42 +0000 (15:57 -0500)
Inspired by Gentoo's setup of /etc/env.d, /etc/profile.d, etc.

15 files changed:
src/.bashrc
src/.bashrc.d/00environment [moved from src/.bashrc.d/environment with 100% similarity]
src/.bashrc.d/01detect_system [new file with mode: 0644]
src/.bashrc.d/05local_paths [moved from src/.bashrc.d/local_paths with 100% similarity]
src/.bashrc.d/10aliases [moved from src/.bash_aliases with 100% similarity]
src/.bashrc.d/20completion [new file with mode: 0644]
src/.bashrc.d/20lesspipe [new file with mode: 0644]
src/.bashrc.d/20nobeep [moved from src/.bashrc.d/nobeep with 51% similarity]
src/.bashrc.d/20screen [new file with mode: 0644]
src/.bashrc.d/30gpg_agent [moved from src/.bashrc.d/gpg_agent with 100% similarity]
src/.bashrc.d/40ssh_agent [moved from src/.bashrc.d/ssh_agent with 100% similarity]
src/.bashrc.d/90dotfiles [moved from src/.bashrc.d/dotfiles with 100% similarity]
src/.bashrc.d/completion [deleted file]
src/.bashrc.d/lesspipe [deleted file]
src/.bashrc.d/screen [deleted file]

index 3bbae5610ce6b20727d4dd2aa21737e52b2362be..1dfa9c82d09874443a87009e7e88743fb59c4dba 100644 (file)
@@ -7,12 +7,10 @@
 # past this point for scp and rcp, and it's important to refrain from
 # outputting anything in those cases.
 if [[ $- != *i* ]] ; then
-    # Shell is non-interactive.  Be done now!
-    return
+       # Shell is non-interactive.  Be done now!
+       return
 fi
 
-#source .bashrc.d/local_paths
-
 # If not running interactively, don't do anything else
 [ -z "$PS1" ] && return
 
@@ -24,17 +22,11 @@ export HISTCONTROL=ignoreboth
 # update the values of LINES and COLUMNS.
 shopt -s checkwinsize
 
-source ~/.bashrc.d/environment
-#source ~/.bashrc.d/screen
-#source ~/.bashrc.d/completion
-#source ~/.bashrc.d/nobeep
-#source ~/.bashrc.d/lesspipe
-source ~/.bashrc.d/ssh_agent
-source ~/.bashrc.d/gpg_agent
-
-# load aliases
-if [ -f ~/.bash_aliases ]; then
-    . ~/.bash_aliases
-fi
+for FILE in ~/.bashrc.d/*; do
+       if [ -f "${FILE}" ]; then
+               source "${FILE}"
+       fi
+done
 
-source ~/src/dotfiles/public/src/.bashrc.d/dotfiles
+# reduce environment pollution
+unset FILE
diff --git a/src/.bashrc.d/01detect_system b/src/.bashrc.d/01detect_system
new file mode 100644 (file)
index 0000000..bce8321
--- /dev/null
@@ -0,0 +1,19 @@
+# Detect the type of system we're running on
+#
+# This makes it easy to adjust script locations and so forth to match
+# your system's file placement and other quirks.
+
+if [ -z "${OS}" ]; then
+       export OS='UNKNOWN'
+       if [ -f '/etc/make.conf' ]; then
+               export OS='Gentoo'
+       elif [ "${SHELL#*gentoo}" != "${SHELL}" ]; then  # assumes 'gentoo' in prefix
+               export OS='Gentoo Prefix'
+       elif ! grep -i debian /etc/issue; then
+               export OS='Debian'
+       elif ! grep -i ubuntu /etc/issue; then
+               export OS='Ubuntu'
+       else
+               echo "unknown system.  Adjust .bashrc.d/01detect_system or set OS by hand" >&2
+       fi
+fi
similarity index 100%
rename from src/.bash_aliases
rename to src/.bashrc.d/10aliases
diff --git a/src/.bashrc.d/20completion b/src/.bashrc.d/20completion
new file mode 100644 (file)
index 0000000..0c50784
--- /dev/null
@@ -0,0 +1,31 @@
+# enable programmable completion
+#
+# You don't need to enable this if it's already enabled globally for
+# your system.
+
+if [ "${OS}" = 'Gentoo' ]; then
+       # Gentoo-based systems 
+       #
+       # Bash completion comes from the 'app-shells/bash_completion' package,
+       # which stores the initialization script in
+       #   /etc/profile.d/bash_completion.sh
+       if [ -f /etc/profile.d/bash_completion.sh ]; then
+               . /etc/profile.d/bash_completion.sh
+       fi
+elif [ "${OS}" = 'Debian' ] || [ "${OS}" = 'Ubuntu' ]; then
+       # Debian-based systems
+       #
+       # Bash completion comes from the 'bash' package, which stores the
+       # initialization script in
+       #   /etc/bash_completion
+       # You won't need to enable this if you uncommented the appropriate
+       # section in /etc/bash.bashrc.
+       if [ -f /etc/bash_completion ]; then
+               . /etc/bash_completion
+       fi
+fi
+
+# bugs-everywhere completion
+#if [ -f ~/.be-completion.sh ]; then
+#      source ~/.be-completion.sh
+#fi
diff --git a/src/.bashrc.d/20lesspipe b/src/.bashrc.d/20lesspipe
new file mode 100644 (file)
index 0000000..792f02c
--- /dev/null
@@ -0,0 +1,6 @@
+# make less more friendly for non-text input files, see lesspipe(1)
+# (Debian-based systems only)
+
+if [ "${OS}" = "Debian" ] || [ "${OS}" = "Ubuntu" ]; then
+       [ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
+fi
similarity index 51%
rename from src/.bashrc.d/nobeep
rename to src/.bashrc.d/20nobeep
index 9e784f90c7f959a8dffed725b738f4f8ce9bfb18..8eddcbfb18951f0ee4162bfc5747a6ffd26f8b3a 100644 (file)
@@ -1,12 +1,11 @@
 # turn off terminal beep in X
-if [ $TERM == "xterm" ] && [ -n "$DISPLAY" ]
-    then
-    xset b off
+if [ $TERM == "xterm" ] && [ -n "$DISPLAY" ]; then
+       xset b off
 fi
 
 # turn of terminal beeps in the console, unless connecting via SSH
 if [ -z "$SSH_CLIENT" ]; then
-    if [ ! -z "$TERM" ]; then
-       setterm -blength 0
-    fi
+       if [ ! -z "$TERM" ]; then
+               setterm -blength 0
+       fi
 fi
diff --git a/src/.bashrc.d/20screen b/src/.bashrc.d/20screen
new file mode 100644 (file)
index 0000000..164c04b
--- /dev/null
@@ -0,0 +1,6 @@
+if [ "${OS}" = 'Ubuntu' ]; then
+       # adjust for Ubuntu not recognizing screen.* terms
+       if [ "${TERM:0:7}" == "screen." ]; then
+           export TERM="${TERM:7}"
+       fi
+fi
diff --git a/src/.bashrc.d/completion b/src/.bashrc.d/completion
deleted file mode 100644 (file)
index 96dcaa6..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-# enable programmable completion features (you don't need to enable
-# this if it's already enabled in /etc/bash.bashrc and /etc/profile
-# sources /etc/bash.bashrc).
-if [ -f /etc/bash_completion ]; then
-    . /etc/bash_completion
-fi
-
-# bugs-everywhere completion
-if [ -f ~/.be-completion.sh ]; then
-    source ~/.be-completion.sh
-fi
diff --git a/src/.bashrc.d/lesspipe b/src/.bashrc.d/lesspipe
deleted file mode 100644 (file)
index 5b988d1..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-# make less more friendly for non-text input files, see lesspipe(1)
-[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
diff --git a/src/.bashrc.d/screen b/src/.bashrc.d/screen
deleted file mode 100644 (file)
index 3395c66..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-# adjust for Ubuntu not recognizing screen.* terms
-if [ "${TERM:0:7}" == "screen." ]; then
-    export TERM="${TERM:7}"
-fi