aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2013-06-20 22:51:35 +1200
committerTom Ryder <tom@sanctum.geek.nz>2013-06-20 22:51:35 +1200
commitbebbc9bb1c32f3f460ca6d6e81446fcc996dc9d6 (patch)
treeb10dfe3d6269550146c4d1184921f379cd79af83
parentNix DISPLAY, otherwise don't change environment (diff)
downloaddotfiles-bebbc9bb1c32f3f460ca6d6e81446fcc996dc9d6.tar.gz
dotfiles-bebbc9bb1c32f3f460ca6d6e81446fcc996dc9d6.zip
Massive overhaul of structure for Bash files
* No longer using .bash_logout * No longer using .bash_profile, using POSIX-compliant .profile * instead; in particular, moved most of environment settings into .profile * Moved some of the separable functionality of both .profile and .bashrc into subdirectories (some scripts shared, some not) * Tidied implementation of ls/grep aliases * Updated install script to reflect all of the above
-rw-r--r--.gitignore7
-rw-r--r--bash/bash_logout5
-rw-r--r--bash/bash_profile6
-rw-r--r--bash/bashrc214
-rw-r--r--bash/bashrc.d/cd.bash11
-rw-r--r--bash/bashrc.d/grep.bash15
-rw-r--r--bash/bashrc.d/ls.bash14
-rw-r--r--bash/bashrc.d/prompt.bash82
-rw-r--r--bash/bashrc.d/tmux.bash9
-rw-r--r--bash/profile33
-rwxr-xr-xinstall10
-rw-r--r--sh/profile23
12 files changed, 204 insertions, 225 deletions
diff --git a/.gitignore b/.gitignore
index dfb04663..dd5a5f4d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,15 @@
+bash/bashrc.d/*
+!bash/bashrc.d/cd.bash
+!bash/bashrc.d/grep.bash
+!bash/bashrc.d/ls.bash
+!bash/bashrc.d/prompt.bash
+!bash/bashrc.d/tmux.bash
gnupg/*
!gnupg/*.conf
mutt/muttrc.alternates
mutt/signature.*
newsbeuter/urls
+sh/profile.d/*
urxvt/urxvtd-*
vim/.netrwhist
vim/spell/*
diff --git a/bash/bash_logout b/bash/bash_logout
deleted file mode 100644
index de455a72..00000000
--- a/bash/bash_logout
+++ /dev/null
@@ -1,5 +0,0 @@
-# Clear screen when leaving console.
-if [ "$SHLVL" = 1 ]; then
- [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
-fi
-
diff --git a/bash/bash_profile b/bash/bash_profile
deleted file mode 100644
index 28f71bf9..00000000
--- a/bash/bash_profile
+++ /dev/null
@@ -1,6 +0,0 @@
-# Source the normal shell profile.
-[[ -e "${HOME}/.profile" ]] && source "${HOME}/.profile"
-
-# Then source .bashrc if it exists.
-[[ -e "${HOME}/.bashrc" ]] && source "${HOME}/.bashrc"
-
diff --git a/bash/bashrc b/bash/bashrc
index a9062e49..b83682d4 100644
--- a/bash/bashrc
+++ b/bash/bashrc
@@ -1,224 +1,82 @@
-# Don't do anything if not running interactively.
+# Don't do anything if not running interactively
[[ -z "$PS1" ]] && return
-# Keep plenty of history.
+# Keep plenty of history
HISTFILESIZE=1000000
HISTSIZE=1000000
-# Ignore duplicate commands and whitespace in history.
+# Ignore duplicate commands and whitespace in history
HISTCONTROL=ignoreboth
-# Keep the times of the commands in history.
+# Keep the times of the commands in history
HISTTIMEFORMAT='%F %T '
-# Autocorrect fudged paths in cd calls.
+# Autocorrect fudged paths in cd calls
shopt -s cdspell &>/dev/null
-# Update the hash table properly.
+# Update the hash table properly
shopt -s checkhash &>/dev/null
-# Warn me about stopped jobs when exiting.
+# Warn me about stopped jobs when exiting
shopt -s checkjobs &>/dev/null
-# Update columns and rows if window size changes.
+# Update columns and rows if window size changes
shopt -s checkwinsize &>/dev/null
-# Put multi-line commands onto one line of history.
+# Put multi-line commands onto one line of history
shopt -s cmdhist &>/dev/null
-# Expand globbing and variables for directory completion.
+# Expand globbing and variables for directory completion
shopt -s direxpand &>/dev/null
-# Autocorrect fudged paths during completion.
+# Autocorrect fudged paths during completion
shopt -s dirspell &>/dev/null
-# Include dotfiles in pattern matching.
+# Include dotfiles in pattern matching
shopt -s dotglob &>/dev/null
-# Enable advanced pattern matching.
+# Enable advanced pattern matching
shopt -s extglob &>/dev/null
-# Enable double-starring paths.
+# Enable double-starring paths
shopt -s globstar &>/dev/null
-# Append rather than overwrite Bash history.
+# Append rather than overwrite Bash history
shopt -s histappend &>/dev/null
-# Ignore me if I try to complete an empty line.
+# Ignore me if I try to complete an empty line
shopt -s no_empty_cmd_completion &>/dev/null
-# Never beep at me.
-hash setterm &>/dev/null && setterm -bfreq 0
+# Never beep at me
+setterm -bfreq 0 &>/dev/null
-# Turn off annoying and useless flow control keys.
-hash stty &>/dev/null && stty -ixon
+# Turn off annoying and useless flow control keys
+stty -ixon &>/dev/null
-# Use completion, if available.
+# Use completion, if available
[[ -e /etc/bash_completion ]] && source /etc/bash_completion
-# Figure out how many colors we have now.
-hash tput && colors=$(tput colors)
-
-# Save some color codes based on our colour space.
-if [[ $colors -ge 256 ]]; then
- color_root='\[\e[38;5;9m\]'
- color_sudo='\[\e[38;5;11m\]'
- color_user='\[\e[38;5;10m\]'
- color_norm='\[\e[0m\]'
-elif [[ $colors -ge 8 ]]; then
- color_root='\[\e[1;31m\]'
- color_sudo='\[\e[1;33m\]'
- color_user='\[\e[1;32m\]'
- color_norm='\[\e[0m\]'
-else
- color_root=
- color_sudo=
- color_user=
- color_norm=
-fi
-
-# Reset options for ls and grep.
-lsopts=
-grepopts='-I'
-
-# If we have a color terminal, we'll use color for ls and grep.
-if [[ $colors -ge 8 ]]; then
- hash dircolors &>/dev/null && eval "$(dircolors -b)"
- if ls --help | grep -- --color &>/dev/null; then
- lsopts="${lsopts} --color=auto"
- fi
- if grep --help | grep -- --color &>/dev/null; then
- grepopts="${grepopts} --color=auto"
- fi
-fi
+# I always want a unified diff
+alias diff='diff -u'
-# Set up more options for grep; exclude version control files.
-if grep --help | grep -- --exclude &>/dev/null; then
- grepopts="${grepopts} --exclude=.git{,ignore,modules}"
-fi
-if grep --help | grep -- --exclude-dir &>/dev/null; then
- grepopts="${grepopts} --exclude-dir=.{cvs,git,hg,svn}"
-fi
+# I actually use ed now and then, go figure
+alias ed='ed -p:'
-# Alias ls and grep with the options we've collected.
-alias ls="ls ${lsopts}"
-alias grep="grep ${grepopts}"
+# Make gdb shut up
+alias gdb='gdb -q'
-# Protect innocent MySQL databases from my stupidity.
+# Protect innocent MySQL databases from my stupidity
alias mysql='mysql --safe-updates'
-# I always do this, and I hate slow train.
+# I always do this, and I hate slow train
alias sl='ls'
-# I actually use ed now and then. Go figure.
-alias ed='ed -p:'
-
-# Make gdb shut up.
-alias gdb='gdb -q'
-
-# I always want a unified diff.
-alias diff='diff -u'
-
-# If given two arguments to cd, replace the first with the second in $PWD
-function cd {
- if [[ -n "$2" ]]; then
- builtin cd "${PWD/$1/$2}"
- elif [[ -n "$1" ]]; then
- builtin cd "$1"
- else
- builtin cd
- fi
-}
-
-# Attach to existing tmux session rather than create a new one if possible.
-function tmux {
- if [[ -n "$*" ]]; then
- command tmux $*
- else
- command tmux attach -d &>/dev/null || command tmux
- fi
-}
-
-# Decide on color for prompt.
-if [[ $EUID -eq 0 ]]; then
- color_prompt=${color_root}
-elif [[ -n $SUDO_USER ]]; then
- color_prompt=${color_sudo}
-else
- color_prompt=${color_user}
+# Load any supplementary scripts
+if [[ -d "$HOME/.bashrc.d" ]]
+then
+ for file in $HOME/.bashrc.d/*
+ do
+ source $file
+ done
fi
-# Frontend to controlling prompt.
-function prompt {
- case "$1" in
-
- # Turn complex coloured prompt on.
- on)
- PROMPT_COMMAND='history -a'
- PS1='\[\a\][\u@\h:\w]$(prompt return)$(prompt vcs)$(prompt jobs)\$'
- PS1="${color_prompt}${PS1}${color_norm} "
- ;;
-
- # Revert to simple inexpensive prompt.
- off)
- PROMPT_COMMAND=
- PS1='\[\a\]\$ '
- ;;
-
- # Git prompt function.
- git)
- git branch &>/dev/null || return 1
- HEAD="$(git symbolic-ref HEAD 2>/dev/null)"
- branch="${HEAD##*/}"
- [[ -n "$(git status 2>/dev/null | \
- grep -F 'nothing to commit')" ]] || state="!"
- printf '(git:%s)' "${branch:-unknown}${state}"
- ;;
-
- # Mercurial prompt function.
- hg)
- hg branch &>/dev/null || return 1
- branch="$(hg branch 2>/dev/null)"
- [[ -n "$(hg status 2>/dev/null)" ]] && state="!"
- printf '(hg:%s)' "${branch:-unknown}${state}"
- ;;
-
- # Subversion prompt function.
- svn)
- svn info &>/dev/null || return 1
- url="$(svn info 2>/dev/null | \
- awk -F': ' '$1 == "URL" {print $2}')"
- root="$(svn info 2>/dev/null | \
- awk -F': ' '$1 == "Repository Root" {print $2}')"
- branch=${url/$root}
- branch=${branch#/}
- branch=${branch#branches/}
- branch=${branch%%/*}
- [[ -n "$(svn status 2>/dev/null)" ]] && state="!"
- printf '(svn:%s)' "${branch:-unknown}${state}"
- ;;
-
- # VCS wrapper prompt function.
- vcs)
- prompt git || prompt svn || prompt hg
- ;;
-
- # Return status prompt function.
- return)
- ret=$?
- [[ $ret -ne 0 ]] && printf '<%d>' ${ret}
- ;;
-
- # Job count prompt function.
- jobs)
- [[ -n "$(jobs)" ]] && printf '{%d}' $(jobs | sed -n '$=')
- ;;
- esac
-}
-
-# Run local file if it exists.
-[[ -e "${HOME}/.bashrc.local" ]] && source "${HOME}/.bashrc.local"
-
-# Start with full-fledged prompt.
-prompt on
-
diff --git a/bash/bashrc.d/cd.bash b/bash/bashrc.d/cd.bash
new file mode 100644
index 00000000..9154291b
--- /dev/null
+++ b/bash/bashrc.d/cd.bash
@@ -0,0 +1,11 @@
+# If given two arguments to cd, replace the first with the second in $PWD
+function cd {
+ if [[ -n "$2" ]]; then
+ builtin cd "${PWD/$1/$2}"
+ elif [[ -n "$1" ]]; then
+ builtin cd "$1"
+ else
+ builtin cd
+ fi
+}
+
diff --git a/bash/bashrc.d/grep.bash b/bash/bashrc.d/grep.bash
new file mode 100644
index 00000000..7cb38c4d
--- /dev/null
+++ b/bash/bashrc.d/grep.bash
@@ -0,0 +1,15 @@
+# Function returns calculated options for grep
+function __grepopts {
+ local grepopts='-I'
+ grep --help | grep -- --color &>/dev/null \
+ && grepopts="${grepopts} --color=auto"
+ grep --help | grep -- --exclude &>/dev/null \
+ && grepopts="${grepopts} --exclude=.git{,ignore,modules}"
+ grep --help | grep -- --exclude-dir &>/dev/null \
+ && grepopts="${grepopts} --exclude-dir=.{cvs,git,hg,svn}"
+ echo $grepopts
+}
+
+# Alias grep with those options
+alias grep="grep $(__grepopts)"
+
diff --git a/bash/bashrc.d/ls.bash b/bash/bashrc.d/ls.bash
new file mode 100644
index 00000000..6c793a52
--- /dev/null
+++ b/bash/bashrc.d/ls.bash
@@ -0,0 +1,14 @@
+# Apply color and exclusions to ls and grep
+eval "$(dircolors -b &>/dev/null)"
+
+# Function returns calculated options for ls
+function __lsopts {
+ local lsopts=
+ ls --help | grep -- --color &>/dev/null \
+ && lsopts="${lsopts} --color=auto"
+ echo $lsopts
+}
+
+# Alias ls with these options
+alias ls="ls $(__lsopts)"
+
diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash
new file mode 100644
index 00000000..f82ef12f
--- /dev/null
+++ b/bash/bashrc.d/prompt.bash
@@ -0,0 +1,82 @@
+# Frontend to controlling prompt
+function prompt {
+ local colors=$(tput colors 2>/dev/null)
+ local color reset branch head state url root ret
+
+ if [[ $colors -ge 256 ]]; then
+ color='\[\e[38;5;10m\]'
+ reset='\[\e[0m\]'
+ elif [[ $colors -ge 8 ]]; then
+ color='\[\e[1;32m\]'
+ reset='\[\e[0m\]'
+ fi
+
+ case "$1" in
+
+ # Turn complex coloured prompt on
+ on)
+ PROMPT_COMMAND='history -a'
+ PS1='\[\a\][\u@\h:\w]$(prompt return)$(prompt vcs)$(prompt jobs)\$'
+ PS1="${color}${PS1}${reset} "
+ ;;
+
+ # Revert to simple inexpensive prompt
+ off)
+ PROMPT_COMMAND=
+ PS1='\[\a\]\$ '
+ ;;
+
+ # Git prompt function
+ git)
+ git branch &>/dev/null || return 1
+ head="$(git symbolic-ref HEAD 2>/dev/null)"
+ branch="${head##*/}"
+ [[ -n "$(git status 2>/dev/null | \
+ grep -F 'nothing to commit')" ]] || state="!"
+ printf '(git:%s)' "${branch:-unknown}${state}"
+ ;;
+
+ # Mercurial prompt function
+ hg)
+ hg branch &>/dev/null || return 1
+ branch="$(hg branch 2>/dev/null)"
+ [[ -n "$(hg status 2>/dev/null)" ]] && state="!"
+ printf '(hg:%s)' "${branch:-unknown}${state}"
+ ;;
+
+ # Subversion prompt function
+ svn)
+ svn info &>/dev/null || return 1
+ url="$(svn info 2>/dev/null | \
+ awk -F': ' '$1 == "URL" {print $2}')"
+ root="$(svn info 2>/dev/null | \
+ awk -F': ' '$1 == "Repository Root" {print $2}')"
+ branch=${url/$root}
+ branch=${branch#/}
+ branch=${branch#branches/}
+ branch=${branch%%/*}
+ [[ -n "$(svn status 2>/dev/null)" ]] && state="!"
+ printf '(svn:%s)' "${branch:-unknown}${state}"
+ ;;
+
+ # VCS wrapper prompt function
+ vcs)
+ prompt git || prompt svn || prompt hg
+ ;;
+
+ # Return status prompt function
+ return)
+ ret=$?
+ [[ $ret -ne 0 ]] && printf '<%d>' ${ret}
+ ;;
+
+ # Job count prompt function
+ jobs)
+ [[ -n "$(jobs)" ]] && printf '{%d}' $(jobs | sed -n '$=')
+ ;;
+ esac
+}
+
+# Start with full-fledged prompt
+prompt on
+
diff --git a/bash/bashrc.d/tmux.bash b/bash/bashrc.d/tmux.bash
new file mode 100644
index 00000000..fd623271
--- /dev/null
+++ b/bash/bashrc.d/tmux.bash
@@ -0,0 +1,9 @@
+# Attach to existing tmux session rather than create a new one if possible
+function tmux {
+ if [[ -n "$*" ]]; then
+ command tmux $*
+ else
+ command tmux attach -d &>/dev/null || command tmux
+ fi
+}
+
diff --git a/bash/profile b/bash/profile
deleted file mode 100644
index 6fc34a51..00000000
--- a/bash/profile
+++ /dev/null
@@ -1,33 +0,0 @@
-# Locale
-export LANG='en_NZ.UTF-8'
-export LANGUAGE='en_NZ:en'
-unset LC_ALL
-
-# Editor
-export EDITOR='vi'
-export VISUAL="$EDITOR"
-
-# Pager
-export PAGER='less'
-
-# Mail
-export MAIL="$HOME/Mail"
-
-# Browser
-if [ -n "$DISPLAY" ]; then
- export BROWSER='firefox'
-else
- export BROWSER='lynx'
-fi
-
-# Path
-for bindir in \
- "$HOME/.local/bin" \
- '/usr/local/apache/bin' \
- '/usr/local/mysql/bin' \
- '/usr/local/nagios/bin' \
- '/usr/local/pgsql/bin'
-do
- [ -d "$bindir" ] && export PATH="$bindir:$PATH"
-done
-
diff --git a/install b/install
index 12116681..42b27a77 100755
--- a/install
+++ b/install
@@ -7,9 +7,7 @@ cd "${OLDPWD}"
# Link in files, replacing whatever's already there.
ln -fs ".dotfiles/bash/bashrc" "${HOME}/.bashrc"
-ln -fs ".dotfiles/bash/bash_profile" "${HOME}/.bash_profile"
-ln -fs ".dotfiles/bash/bash_logout" "${HOME}/.bash_logout"
-ln -fs ".dotfiles/bash/profile" "${HOME}/.profile"
+ln -fs ".dotfiles/sh/profile" "${HOME}/.profile"
ln -fs ".dotfiles/git/gitconfig" "${HOME}/.gitconfig"
ln -fs ".dotfiles/mutt/muttrc" "${HOME}/.muttrc"
ln -fs ".dotfiles/readline/inputrc" "${HOME}/.inputrc"
@@ -17,6 +15,12 @@ ln -fs ".dotfiles/tmux/tmux.conf" "${HOME}/.tmux.conf"
ln -fs ".dotfiles/vim/vimrc" "${HOME}/.vimrc"
ln -fs ".dotfiles/vim/gvimrc" "${HOME}/.gvimrc"
+# Link in shell stuff.
+[[ -e "${HOME}/.bashrc.d" ]] && rm -r "$HOME/.bashrc.d"
+ln -fs ".dotfiles/bash/bashrc.d" "${HOME}/.bashrc.d"
+[[ -e "${HOME}/.profile.d" ]] && rm -r "$HOME/.profile.d"
+ln -fs ".dotfiles/sh/profile.d" "${HOME}/.profile.d"
+
# Link in Mutt stuff.
[[ -e "${HOME}/.mutt" ]] && rm -r "${HOME}/.mutt"
ln -fs ".dotfiles/mutt" "${HOME}/.mutt"
diff --git a/sh/profile b/sh/profile
new file mode 100644
index 00000000..eb2b7e8f
--- /dev/null
+++ b/sh/profile
@@ -0,0 +1,23 @@
+# Set editor
+export EDITOR='vi'
+export VISUAL="$EDITOR"
+
+# Set pager
+export PAGER='less'
+
+# Add ~/.local/bin to PATH
+[ -d "$HOME/.local/bin" ] && PATH="$HOME/.local/bin:$PATH"
+export PATH
+
+# Load any supplementary scripts
+if [[ -d "$HOME/.profile.d" ]]
+then
+ for file in $HOME/.profile.d/*
+ do
+ . $file
+ done
+fi
+
+# If running Bash, try to run .bashrc
+[ -n "$BASH" ] && [ -e "$HOME/.bashrc" ] && . $HOME/.bashrc
+