diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2012-06-04 23:46:47 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2012-06-04 23:46:47 +1200 |
commit | 4530d63af43a6781ce5965eb967c922b1e71a9b2 (patch) | |
tree | a76a9ecd60500b09036d4a2568fc5a18cb40d5d0 /bash/bashrc | |
parent | Quick and dirty fix for Markdown highlighting (diff) | |
download | dotfiles-4530d63af43a6781ce5965eb967c922b1e71a9b2.tar.gz dotfiles-4530d63af43a6781ce5965eb967c922b1e71a9b2.zip |
Refactor bashrc config for parity with new zshrc
I'm trying out Zshrc for a bit for a future Arabesque article. I've
started by just trying to get rough feature parity with my Bash
configuration. I've had some moderate success though it's taken quite
some time.
Diffstat (limited to 'bash/bashrc')
-rw-r--r-- | bash/bashrc | 118 |
1 files changed, 66 insertions, 52 deletions
diff --git a/bash/bashrc b/bash/bashrc index d3fedef0..ad9a5c20 100644 --- a/bash/bashrc +++ b/bash/bashrc @@ -1,6 +1,9 @@ # Don't do anything if not running interactively. [ -z "$PS1" ] && return +# Use vi as my text editor. +export EDITOR=vi + # Keep plenty of history. unset HISTFILESIZE HISTSIZE=1000000 @@ -38,76 +41,87 @@ shopt -s globstar &>/dev/null # Append rather than overwrite Bash history. shopt -s histappend &>/dev/null -# Simple prompt. -PS1='\u@\h:\w\$ ' +# Use completion, if available. +[[ -e /etc/bash_completion ]] && . /etc/bash_completion + +# SSH agent setup, if available. +[[ -e ~/.ssh/agent ]] && . ~/.ssh/agent + +# Turn off annoying and useless flow control keys. +stty -ixon + +# Never beep at me. +setterm -bfreq 0 + +# Sensible prompts, we'll work out colors shortly. +PS1='\u@\h:\w\$' PS2='...' -# Set up options for ls; use color. +# Start stacking up options for ls and grep. LS_OPTS= -if ls --help | grep -- --color &>/dev/null; then - hash dircolors &>/dev/null && eval "$(dircolors -b)" - LS_OPTS="$LS_OPTS --color=auto" -fi -alias ls="ls $LS_OPTS" - -# Set up options for grep; exclude version control files, use color. GREP_OPTS= + +# If we're using an xterm, force 256 colors. +case "$TERM" in + xterm*) + TERM=xterm-256color + ;; +esac + +# If we have a color terminal, do colory things. +case "$TERM" in + *color) + + # Change prompt color depending on whether I'm root or not. + if [[ $EUID -eq 0 ]]; then + PS1='\[\e[1;31m\]'${PS1}'\[\e[0m\]' + else + PS1='\[\e[1;32m\]'${PS1}'\[\e[0m\]' + fi + + # Get colouring for ls and grep if available. + hash dircolors &>/dev/null && eval "$(dircolors -b)" + if ls --help | grep -- --color &>/dev/null; then + LS_OPTS="${LS_OPTS} --color=auto" + fi + if grep --help | grep -- --color &>/dev/null; then + GREP_OPTS="${GREP_OPTS} --color=auto" + fi + ;; +esac + +# Set up more options for grep; exclude version control files. if grep --help | grep -- --exclude &>/dev/null; then for PATTERN in .git .gitignore .gitmodules; do - GREP_OPTS="$GREP_OPTS --exclude=$PATTERN" + GREP_OPTS="${GREP_OPTS} --exclude=${PATTERN}" done fi if grep --help | grep -- --exclude-dir &>/dev/null; then for PATTERN in .cvs .git .hg .svn; do - GREP_OPTS="$GREP_OPTS --exclude-dir=$PATTERN" + GREP_OPTS="${GREP_OPTS} --exclude-dir=${PATTERN}" done fi -if grep --help | grep -- --color &>/dev/null; then - GREP_OPTS="$GREP_OPTS --color=auto" -fi -alias grep="grep $GREP_OPTS" -# Protect innocent MySQL databases from my stupidity. -alias mysql="mysql --safe-updates" - -# I always do this and I hate slow train. -alias sl="ls" - -# Use completion, if available. -if [ -e /etc/bash_completion ]; then - . /etc/bash_completion - - # Use shots for hostname completion, if available. - hash shots &>/dev/null && complete -F _known_hosts -W "$(shots)" \ - dig fping ftp host mtr nc netcat ping ping6 telnet traceroute -fi - -# SSH agent setup, if available. -if [ -e ~/.ssh/agent ]; then - . ~/.ssh/agent -fi - -# Turn off annoying and useless flow control keys. -stty -ixon +# Alias ls and grep with the options we've collected. +alias ls="ls ${LS_OPTS}" +alias grep="grep ${GREP_OPTS}" -# Never beep at me. -setterm -bfreq 0 +# Protect innocent MySQL databases from my stupidity. +alias mysql='mysql --safe-updates' -# Use vi as my text editor, if available. -hash vi &>/dev/null && export EDITOR=vi +# I always do this, and I hate slow train. +alias sl='ls' -# Terminal-specific settings. +# Set window titles in various terminals. case "$TERM" in - - # Set xterm title, use 256 colors. - xterm*) - PS1="\[\e]0;\h\a\]"${PS1} - TERM=xterm-256color - ;; - - # Set screen window title. screen*) - PROMPT_COMMAND="printf '\033k$(hostname)\033\\';"${PROMPT_COMMAND} + PS1='\[\ek\h\e\\\]'${PS1} + ;; + xterm*) + PS1='\[\e]0;\h\a\]'${PS1} ;; esac +# Add space suffix to the prompt now that we're done hacking it up. +PS1="${PS1} " + |