CYAN="\e[96m" GREEN="\e[92m" RED="\e[91m" BBLUE="\e[34;1m" RESET="\e[0m" IS_PASS() { [[ $1 -eq 0 ]] || [[ $1 -gt 128 ]] } SUCCESS() { if IS_PASS $1; then echo -en $GREEN else echo -en $RED fi } CODE() { IS_PASS $1 || echo "(rc=$1) "; } GITBRANCH() { local branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) [[ -z ${branch} ]] || echo -n ":${branch}" } export PS1='$(rc=$?; echo -e "\[$CYAN\]\D{%F %T} \[$BBLUE\]\u\[$RESET\]@\[$(SUCCESS $rc)\]\h:[\w$(GITBRANCH)] $(CODE $rc)\[$RESET\]$ ")' PATH="$HOME/usr/local/bin:$HOME/bin:$HOME/usr/bin:$PATH" export PATH export LC_ALL=en_US.UTF-8 if [[ -z "$BASEPATH" ]]; then export BASEPATH="$PATH" fi alias reset-path="export PATH=\"$BASEPATH\"" # Turn a number of symlink files into copies of their original # Usage: # detach file... detach() { for i; do [ -L "$i" ] && cp --remove-destination $(readlink "$i") "$i"; done } link-tools() { PATH=$HOME/tools/bin:$HOME/tools/usr/bin:$PATH LD_LIBRARY_PATH=$HOME/tools/lib:$HOME/tools/usr/lib:$LD_LIBRARY_PATH export PATH export LD_LIBRARY_PATH } unlink-tools() { PATH=$(echo $PATH | perl -pne "s/(?<=:)$HOME/tools.*?://g") LD_LIBRARY_PATH=$(echo $LD_LIBRARY_PATH | perl -pne "s/(?<=:)$HOME/tools.*?://g") export PATH export LD_LIBRARY_PATH } alias listall="list -A" alias disk-usage="ls -A | xargs du -shc | sort -h" alias reload="source ~/.bashrc" alias crontab="VIM_CRONTAB=true crontab" refreshterm() { clear uname -a cat /etc/motd echo "" pwd list } _mkcd_fun() { if [ ! -d "$2" ]; then if [ -e "$2" ]; then echo "mkcd: file exists and is not a directory" exit else $1 "$2" fi fi cd "$2" } alias mkcd="_mkcd_fun mkdir" mkdirs() { mkdir -p "$1" } alias mkcds="_mkcd_fun mkdirs" alias diffr="diff --ignore-blank-lines --minimal --side-by-side --report-identical-files --suppress-common-lines" alias diffl="diff --changed-group-format='%<' --unchanged-group-format=''" _recall_fun() { if [ -z "$1" ]; then echo "recall: usage: recall string"; return 1; fi history | cut -c 8- | grep --extended-regexp "$1" | \ grep --invert-match --extended-regexp "^(history|recall|redo)" | sort | uniq } redo() { IFS=$'\n' hist=($(_recall_fun $1)) for ((i=0; i<${#hist[@]}; i++)); do echo "[$i] ${hist[$i]}" done printf "Index: " read idx if [[ $idx =~ ^[0-9]+$ ]]; then eval "${hist[$idx]}" fi unset IFS } recall(){ _recall_fun $1 | sed 's/^/ /' } clear() { /usr/bin/clear if [[ ! -z "${TMUX}" ]]; then tmux clear-history; fi } swap() { if [[ $# -ne 2 ]]; then echo "swap file1 file2" >&2 return 1 fi local tmpfile=$(mktemp) mv "${1}" "${tmpfile}" mv "${2}" "${1}" mv "${tmpfile}" "${2}" } has() { [[ "$(type -t "${1}")" =~ function|alias|file ]] } maybe_do() { has "${1}" && "$@" } alias coms="${HOME}/tools/comstore/commands.sh" clrun() { clear echo "$@" "$@" } if [[ $(uname) == "Darwin" ]]; then # OSX / FreeBSD . ${HOME}/.profile-bsd else . ${HOME}/.profile-linux fi has git && . ${HOME}/.profile-git || true has p4 && . ${HOME}/.profile-p4 || true