From: W. Trevor King Date: Wed, 30 Nov 2011 20:42:51 +0000 (-0500) Subject: Restructure .bashrc.d for prefix-ordered mass sourcing. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ebe05f993b872baaa01c74b62f6c16da2e258deb;p=dotfiles-public.git Restructure .bashrc.d for prefix-ordered mass sourcing. Inspired by Gentoo's setup of /etc/env.d, /etc/profile.d, etc. --- diff --git a/src/.bashrc b/src/.bashrc index 3bbae56..1dfa9c8 100644 --- a/src/.bashrc +++ b/src/.bashrc @@ -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/environment b/src/.bashrc.d/00environment similarity index 100% rename from src/.bashrc.d/environment rename to src/.bashrc.d/00environment diff --git a/src/.bashrc.d/01detect_system b/src/.bashrc.d/01detect_system new file mode 100644 index 0000000..bce8321 --- /dev/null +++ b/src/.bashrc.d/01detect_system @@ -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 diff --git a/src/.bashrc.d/local_paths b/src/.bashrc.d/05local_paths similarity index 100% rename from src/.bashrc.d/local_paths rename to src/.bashrc.d/05local_paths diff --git a/src/.bash_aliases b/src/.bashrc.d/10aliases 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 index 0000000..0c50784 --- /dev/null +++ b/src/.bashrc.d/20completion @@ -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 index 0000000..792f02c --- /dev/null +++ b/src/.bashrc.d/20lesspipe @@ -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 diff --git a/src/.bashrc.d/nobeep b/src/.bashrc.d/20nobeep similarity index 51% rename from src/.bashrc.d/nobeep rename to src/.bashrc.d/20nobeep index 9e784f9..8eddcbf 100644 --- a/src/.bashrc.d/nobeep +++ b/src/.bashrc.d/20nobeep @@ -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 index 0000000..164c04b --- /dev/null +++ b/src/.bashrc.d/20screen @@ -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/gpg_agent b/src/.bashrc.d/30gpg_agent similarity index 100% rename from src/.bashrc.d/gpg_agent rename to src/.bashrc.d/30gpg_agent diff --git a/src/.bashrc.d/ssh_agent b/src/.bashrc.d/40ssh_agent similarity index 100% rename from src/.bashrc.d/ssh_agent rename to src/.bashrc.d/40ssh_agent diff --git a/src/.bashrc.d/dotfiles b/src/.bashrc.d/90dotfiles similarity index 100% rename from src/.bashrc.d/dotfiles rename to src/.bashrc.d/90dotfiles diff --git a/src/.bashrc.d/completion b/src/.bashrc.d/completion deleted file mode 100644 index 96dcaa6..0000000 --- a/src/.bashrc.d/completion +++ /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 index 5b988d1..0000000 --- a/src/.bashrc.d/lesspipe +++ /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 index 3395c66..0000000 --- a/src/.bashrc.d/screen +++ /dev/null @@ -1,4 +0,0 @@ -# adjust for Ubuntu not recognizing screen.* terms -if [ "${TERM:0:7}" == "screen." ]; then - export TERM="${TERM:7}" -fi