Permalink
Browse files

Long-overdue dotfiles rework. Bid farewell to 1997, .bashrc.

  • Loading branch information...
1 parent 9ea36bb commit 23028e6bd7a5c313b60b567c3a2688d5fad206a7 @wesolows committed May 6, 2012
View
@@ -0,0 +1,83 @@
+#! /bin/bash
+
+#
+# If $1 exists, set $2 to its full path and return 0; else return 1.
+#
+function __safe_hash
+{
+ local res=$(hash "$1" 2>/dev/null && hash -t "$1" 2>/dev/null)
+ local code=$?
+ [[ $code -eq 0 && -n "$2" ]] && eval $"$2"="$res"
+ return $code
+}
+
+#
+# Outputs uname with the provided arguments, or "unknown" if that fails.
+#
+function __safe_uname
+{
+ local res=$(uname "$@" 2>/dev/null)
+ [ -z "$res" ] && res="unknown"
+
+ echo "$res"
+ return 0
+}
+
+#
+# Succeeds silently if its input matches, fails otherwise.
+#
+function __qgrep
+{
+ grep "$@" >/dev/null 2>/dev/null
+}
+
+#
+# Helper for __link_subtrees
+#
+function __link_subtree
+{
+ for __f in $(cd "$1" && echo * 2>/dev/null); do
+ [ -e "$2/$__f" ] || ln -s "$1/$__f" "$2/$__f" 2>/dev/null
+ done
+}
+
+#
+# Replicate a symlink tree of everything under each of $2 .. $n under $1.
+# Useful for merging multiple sources; prefers earlier entries.
+#
+function __link_subtrees
+{
+ local dst=$1
+ shift
+
+ for __s in "$@"; do
+ [[ -n "$__s" && -d "$__s" ]] || continue
+ for __d in $(cd "$__s" && echo * 2>/dev/null); do
+ if [ -d "$__s/$__d" ]; then
+ mkdir -p "$dst/$__d"
+ __link_subtree "$__s/$__d" "$dst/$__d"
+ fi
+ done
+ done
+}
+
+#
+# Escape UTF-8 characters into their 3-byte format
+#
+function xencode
+{
+ printf "\\\x%s" $(printf "$@" | xxd -p -c1 -u)
+ echo
+}
+
+function oencode
+{
+ printf "\\\x%s" $(printf "$@" | od -c -b | head -2 | tail -1)
+ echo
+}
+
+# Get a character’s Unicode code point
+function codepoint() {
+ perl -e "use utf8; print sprintf('U+%04X', ord(\"$@\"))"
+ echo # newline
+}
View
@@ -0,0 +1,3 @@
+#! /bin/bash
+
+export TZ="UTC"
View
@@ -0,0 +1,27 @@
+#! /bin/bash
+
+# Canonicalize our architecture
+case "$HOSTTYPE" in
+sun4|sun4?|sparc*) _ARCH=sparc ;;
+i?86|i86pc|amd64|x86_64) _ARCH=i386 ;;
+*)
+ __is_inter && echo "WARNING: $_ARCH is an unsupported architecture."
+ ;;
+esac
+
+# Canonicalize our OS
+case "$OSTYPE" in
+darwin*) _OS=macos ;;
+solaris*)
+ if __safe_uname -v | __qgrep ^joyent_; then
+ _OS=smartos
+ elif __safe_uname -v | __qgrep ^oi_; then
+ _OS=openindiana
+ else
+ _OS=illumos
+ fi
+ ;;
+*)
+ _OS=$OSTYPE
+ __is_inter && echo "WARNING: $_OS is an unsupported OS."
+esac
View
@@ -0,0 +1,49 @@
+#! /bin/bash
+
+PATH="$HOME/$_ARCH-$_OS/bin:$HOME/bin"
+MANPATH="$HOME/share/man:$HOME/man"
+INFOPATH="$HOME/share/info:$HOME/info"
+
+case "$_OS" in
+illumos|openindiana)
+ PATH="$PATH:/usr/local/bin:/usr/local/sbin"
+ PATH="$PATH:/opt/local/bin:/opt/local/sbin"
+ PATH="$PATH:/usr/bin:/usr/sbin:/usr/gnu/bin"
+ PATH="$PATH:/usr/openwin/bin:/usr/X11R6/bin"
+ MANPATH="$MANPATH:/usr/local/man:/usr/local/share/man"
+ MANPATH="$MANPATH:/opt/local/man:/opt/local/share/man"
+ MANPATH="$MANPATH:/usr/share/man:/usr/man"
+ MANPATH="$MANPATH:/usr/gnu/man:/usr/gnu/share/man"
+ MANPATH="$MANPATH:/usr/openwin/man:/usr/X11R6/man"
+ INFOPATH="$INFOPATH:/usr/local/info:/usr/local/share/info"
+ INFOPATH="$INFOPATH:/opt/local/info:/opt/local/share/info"
+ INFOPATH="$INFOPATH:/usr/gnu/info:/usr/gnu/share/info"
+ INFOPATH="$INFOPATH:/usr/share/info:/usr/info"
+ ;;
+smartos)
+ PATH="$PATH:/usr/local/bin:/usr/local/sbin"
+ PATH="$PATH:/usr/bin:/usr/sbin"
+ PATH="$PATH:/opt/local/bin:/opt/local/sbin"
+ MANPATH="$MANPATH:/usr/local/man:/usr/local/share/man"
+ MANPATH="$MANPATH:/usr/share/man:/usr/man"
+ MANPATH="$MANPATH:/opt/local/man:/opt/local/share/man"
+ INFOPATH="$INFOPATH:/usr/local/info:/usr/local/share/info"
+ INFOPATH="$INFOPATH:/opt/local/info:/opt/local/share/info"
+ ;;
+macos)
+ PATH="$PATH:/usr/bin:/bin:/usr/X11R6/bin:/usr/sbin:/sbin"
+ PATH="$PATH:/usr/local/git/bin"
+ MANPATH="$MANPATH:/usr/share/man:/usr/X11R6/man"
+ MANPATH="$MANPATH:/usr/local/git/share/man"
+ INFOPATH="$INFOPATH:/usr/share/info"
+ ;;
+esac
+
+if [ "$USERNAME" != root ]; then
+ PATH="$PATH:."
+ MANPATH="$MANPATH:..:."
+ INFOPATH="$INFOPATH:..:."
+fi
+
+unset LD_LIBRARY_PATH LD_LIBRARY_PATH_32 LD_LIBRARY_PATH_64
+export PATH MANPATH INFOPATH
View
@@ -0,0 +1,18 @@
+#! /bin/bash
+
+[ -d "$HOME/.terminfo" ] || rm -f "$HOME/.terminfo" 2>/dev/null
+mkdir -p "$HOME/.terminfo" 2>/dev/null
+
+case $_OS in
+smartos) _TERMINFO=/opt/local/share/lib/terminfo ;;
+*) ;;
+esac
+
+_TERMINFO="$_TERMINFO:$HOME/.terminfo.d"
+IFS=":"
+set -- $_TERMINFO
+unset IFS
+
+__link_subtrees "$HOME/.terminfo" "$@"
+
+export TERMINFO="$HOME/.terminfo"
View
@@ -0,0 +1,67 @@
+#! /bin/bash
+
+if [ "$TERM" = "xterm" ]; then
+ if [ -z "$COLORTERM" ]; then
+ if [ -z "$XTERM_VERSION" ] ; then
+ echo "Warning: Terminal wrongly calling itself 'xterm'."
+ else
+ case "$XTERM_VERSION" in
+ "XTerm(256)") TERM="xterm-256color" ;;
+ "XTerm(88)") TERM="xterm-88color" ;;
+ "XTerm") ;;
+ *)
+ echo "Warning: Unknown xterm: $XTERM_VERSION"
+ ;;
+ esac
+ fi
+ else
+ case "$COLORTERM" in
+ gnome-terminal) TERM="gnome-256color" ;;
+ *)
+ echo "Warning: Unknown COLORTERM: $COLORTERM"
+ ;;
+ esac
+ fi
+fi
+
+_SCREEN_COLORS=$(tput colors 2>/dev/null)
+if [ -z "$_SCREEN_COLORS" ]; then
+ case "$TERM" in
+ screen-*color-bce)
+ echo "Unknown terminal $TERM. Falling back to 'screen-bce'."
+ TERM=screen-bce
+ ;;
+ *-88color)
+ echo "Unknown terminal $TERM. Falling back to 'xterm-88color'."
+ TERM=xterm-88color
+ ;;
+ *-256color)
+ echo "Unknown terminal $TERM. Falling back to 'xterm-256color'."
+ TERM=xterm-256color
+ ;;
+ esac
+ _SCREEN_COLORS=$(tput colors 2>/dev/null)
+fi
+if [ -z "$_SCREEN_COLORS" ]; then
+ case "$TERM" in
+ gnome*|xterm*|konsole*|aterm|[Ee]term)
+ echo "Unknown terminal $TERM. Falling back to 'xterm'."
+ TERM=xterm
+ ;;
+ rxvt*)
+ echo "Unknown terminal $TERM. Falling back to 'rxvt'."
+ TERM=rxvt
+ ;;
+ screen*)
+ echo "Unknown terminal $TERM. Falling back to 'screen'."
+ TERM=screen
+ ;;
+ esac
+ _SCREEN_COLORS=$(tput colors 2>/dev/null)
+fi
+if ! infocmp "$TERM" >/dev/null 2>&1; then
+ TERM=$(tset -q 2>/dev/null)
+ [ -z "$TERM" ] && TERM=vt100
+fi
+
+export TERM
View
@@ -0,0 +1,20 @@
+#! /bin/bash
+
+if __safe_hash less __less; then
+ PAGER="$__less -ns"
+elif ! __safe_hash more PAGER; then
+ PAGER=
+fi
+
+if __safe_hash vim __vim; then
+ EDITOR="$__vim -X"
+elif __safe_hash vi EDITOR; then :
+elif __safe_hash xemacs __emacs || __safe_hash emacs __emacs; then
+ EDITOR="$__emacs -nw"
+else
+ EDITOR=
+fi
+
+export PAGER EDITOR
+[ -z "$PAGER" ] && unset PAGER
+[ -z "$EDITOR" ] && unset EDITOR
View
@@ -0,0 +1,27 @@
+#! /bin/bash
+
+# Turn on ls colors if we have GNU ls and a reasonable TERM
+__colorls=no
+case "$TERM" in
+gnome*|screen*|xterm*|*rxvt|linux|color*xterm)
+ __safe_hash ls __ls
+ if [ "$__ls" != /usr/ucb/ls ] && \
+ $__ls --color=tty >/dev/null 2>/dev/null; then
+ alias ls='ls --color=tty'
+ [ -f "$HOME/.dir_colors" ] && \
+ eval $(dircolors "$HOME/.dir_colors" 2>/dev/null)
+ fi
+ ;;
+esac
+
+if __safe_hash ncftp; then
+ alias ftp=ncftp
+fi
+
+if __safe_hash vim; then
+ alias vi='vim -X'
+fi
+
+if [ -x /opt/openoffice.org3/program/soffice ]; then
+ alias soffice=/opt/openoffice.org3/program/soffice
+fi
View
@@ -0,0 +1,7 @@
+#! /bin/bash
+
+HISTSIZE=32768
+HISTFILESIZE=HISTSIZE
+HISTCONTROL=ignoredups
+
+shopt -s histappend
View
@@ -0,0 +1,61 @@
+#! /bin/bash
+
+if tput setaf 1 >/dev/null 2>/dev/null; then
+ tput sgr0
+ if [[ $(tput colors 2>/dev/null) -ge 256 ]]; then
+ _MAGENTA=$(tput setaf 9)
+ _ORANGE=$(tput setaf 172)
+ _GREEN=$(tput setaf 190)
+ _PURPLE=$(tput setaf 141)
+ _WHITE=$(tput setaf 256)
+ else
+ _MAGENTA=$(tput setaf 5)
+ _ORANGE=$(tput setaf 4)
+ _GREEN=$(tput setaf 2)
+ _PURPLE=$(tput setaf 1)
+ _WHITE=$(tput setaf 7)
+ fi
+ _BOLD=$(tput bold)
+ _RESET=$(tput sgr0)
+else
+ _MAGENTA="\033[1;31m"
+ _ORANGE="\033[1;33m"
+ _GREEN="\033[1;32m"
+ _PURPLE="\033[1;35m"
+ _WHITE="\033[1;37m"
+ _BOLD=""
+ _RESET="\033[m"
+fi
+
+function _parse_git_dirty() {
+ [[ $(git status 2> /dev/null | tail -n1) != \
+ "nothing to commit (working directory clean)" ]] && echo "*"
+}
+
+function _parse_git_branch() {
+ git branch --no-color 2> /dev/null | \
+ sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(_parse_git_dirty)/"
+}
+
+__user="\[$_BOLD$_MAGENTA\]\u"
+__host="\[$_ORANGE\]\h"
+__dir="\[$_GREEN\]\w"
+
+__safe_hash git && \
+ __on="\[$_WHITE\]\$([[ -n \$(git branch 2>/dev/null) ]] && echo \" on \")"
+__safe_hash git && \
+ __branch="\[$_PURPLE\]\$(_parse_git_branch)"
+__dollar="\[$_WHITE\]\n\\$ \[$_RESET\]"
+
+PS1="$__user \[$_WHITE\]at $__host \[$_WHITE\]in $__dir$__on$__branch$__dollar"
+
+# Set the title bars for rxvt/xterm/etc.
+case "$TERM" in
+gnome*|screen*|*xterm|*rxvt|xterm-*)
+ __prompt='echo -ne "\033]2;"${USER}@${HOSTNAME}:$(pwd)"\007"';
+ ;;
+esac
+
+__prompt="$__prompt; history -a"
+
+PROMPT_COMMAND="$__prompt"
View
@@ -0,0 +1,6 @@
+#! /bin/bash
+
+mkdir -p "$HOME/.vim/backups"
+mkdir -p "$HOME/.vim/swaps"
+
+__link_subtrees "$HOME/.vim" "$HOME/.vim.d"
Oops, something went wrong.

0 comments on commit 23028e6

Please sign in to comment.