C00=$'\\[\e[0m\\]' # neutral C01=$'\\[\e[0;30m\\]' # black C02=$'\\[\e[1;30m\\]' # dark gray C03=$'\\[\e[0;31m\\]' # red C04=$'\\[\e[1;31m\\]' # light red C05=$'\\[\e[0;32m\\]' # green C06=$'\\[\e[1;32m\\]' # light green C07=$'\\[\e[0;33m\\]' # brown C08=$'\\[\e[1;33m\\]' # yellow C09=$'\\[\e[0;34m\\]' # blue C10=$'\\[\e[1;34m\\]' # light blue C11=$'\\[\e[0;35m\\]' # purple C12=$'\\[\e[1;35m\\]' # light purple C13=$'\\[\e[0;36m\\]' # cyan C14=$'\\[\e[1;36m\\]' # light cyan C15=$'\\[\e[0;37m\\]' # light gray C16=$'\\[\e[1;37m\\]' # white if [ "$ITERM_PROFILE" = "SaurikIT" -o "$GNOME_DESKTOP_SESSION_ID" = "BlackOnWhite" ]; then CINV=$C01 CALM=$C15 CFAD=$C02 else #elif [ "$COLORTERM" = "gnome-terminal" -o "$TERM" = "xterm-color" ]; then CINV=$C16 CALM=$C15 CFAD=$C15 #else # CINV=$C16 # CALM=$C15 # CFAD=$C2 fi export PS1="$CFAD[$C07\s$CFAD(${CALM}L$CINV\$SHLVL$CFAD/${CALM}J$CINV\j$CFAD/$CALM#$CINV\#$CFAD)$CFAD/${C10}\l$C00 $C05\u$CFAD@${C10}\h$CFAD:$C07\w$CFAD]\\\$$C00 " #export PS1='\w\$ ' case "${TERM}" in Eterm*|alacritty*|aterm*|foot*|gnome*|konsole*|kterm*|putty*|rxvt*|tmux*|xterm*) PROMPT_COMMAND+=('printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"');; screen*) PROMPT_COMMAND+=('printf "\033_%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}"');; esac function title() { echo -ne $'\e]2;'"$@"$'\a\e]1;'"$@"'\a' } export HISTSIZE=10000 export HISTFILESIZE=1000000 export HISTCONTROL="ignoredups" export LANG=en_US.UTF-8 if [ -t 0 ]; then stty -ixon # OS X drops ctrl-O stty discard undef fi shopt -s checkwinsize shopt -s no_empty_cmd_completion shopt -s extglob shopt -s globstar 2>/dev/null shopt -s histappend shopt -s nullglob complete -r readonly BASH_COMPLETION=' ' if command -v gls &>/dev/null; then ls=gls else ls=ls fi if "${ls}" --version &>/dev/null; then alias ls="${ls} -Fb --color=auto -T 0" else alias ls="${ls} -Fb" fi if command -v dircolors &>/dev/null; then eval "$(dircolors -b)" fi if command -v colordiff &>/dev/null; then alias diff='colordiff' fi if cp --version &>/dev/null; then alias cp='cp -ia --sparse=always' else alias cp='cp -ipR' fi alias mv='mv -i' alias rm='rm -i' alias grep='grep --color=auto --exclude=.svn' alias less='less -R' alias ssh='ssh -e ^] -oHostKeyAlgorithms=+ssh-rsa' alias emacs='emacs -nw' alias epoch='date +%s' alias issh='ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null' alias iscp='scp -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null' function gri() { c=$(git rev-parse --verify "$@") git rebase -i "$@" && git rebase --committer-date-is-author-date "$c" } alias gd='git diff --ignore-submodules=dirty' alias gs='git status --ignore-submodules=dirty' #alias gr='git rebase --committer-date-is-author-date' alias ga='git commit --no-status --amend --reset-author' alias gc='git commit --no-status' #if [[ -e /sw/bin/init.sh ]]; then # . /sw/bin/init.sh #fi #export TERM=xterm-color export CLICOLOR= export LSCOLORS=ExGxFxdxCxDxDxhbaDacad if command -v gmake &>/dev/null; then alias make='gmake' fi export CVS_RSH=ssh export RSYNC_RSH=ssh export EDITOR=vim export SVN_EDITOR=vim export PAGER=less export GIT_PAGER=cat export TERMINAL=xterm # http://groups.google.com/group/programming-nu/msg/300c63ec4e98a921 #export DYLD_BIND_AT_LAUNCH=1 # http://synthesize.us/HOWTO_make_a_deb_archive_without_dpkg export COPY_EXTENDED_ATTRIBUTES_DISABLE=1 # WARNING: You're currently running as root; probably by accident. # Press control-C to abort or Enter to continue as root. # Set LEIN_ROOT to disable this warning. export LEIN_ROOT=1 export MOZ_USE_XINPUT2=1 export WINEDEBUG=-all export PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin #export MANPATH=/usr/share/man export CATALINA_OPTS="-XX:+UseConcMarkSweepGC -XX:+CMSPermGenSweepingEnabled -XX:+CMSClassUnloadingEnabled -XX:PermSize=256m -XX:MaxPermSize=512m" function cysh() { data=$1 name=$2 shift 2 user=${data%@*} host=${data#*@} if [[ $host =~ [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ ]]; then addr=$host else addr=$(host -t a "${host}" | sed -e '/^.* has address / { s///; p; }; d;' | head -n 1) fi title "${name}" name=${name//"'"/$'\'\\\'\''} while [[ 1 ]]; do ssh -t -e none \ -o ConnectTimeout=2 \ -o ServerAliveCountMax=4 \ -o ServerAliveInterval=2 \ -o TCPKeepAlive=no \ "$@" "${user}@${addr}" \ "dtach -A '${name}.sock' -Ez bash" case "$?" in (0) break;; (*) sleep 1;; esac done } function prepend_() { declare value=$(eval "echo \$$1") if [[ -z $value ]]; then export $1=$2 else export $1=$2:${value} fi } function postpend_() { declare value=$(eval "echo \$$1") if [[ -z $value ]]; then export $1=$2 else export $1=${value}:$2 fi } function path_() { if [[ -d $2/bin ]]; then "$1pend_" PATH "$2/bin" fi if [[ -d $2/sbin ]]; then "$1pend_" PATH "$2/sbin" fi if [[ -d $2/include ]]; then "$1pend_" C_INCLUDE_PATH "$2/include" "$1pend_" CPLUS_INCLUDE_PATH "$2/include" "$1pend_" OBJC_INCLUDE_PATH "$2/include" fi if [[ -d $2/lib ]]; then "$1pend_" DYLD_LIBRARY_PATH "$2/lib" "$1pend_" LD_LIBRARY_PATH "$2/lib" "$1pend_" LIBRARY_PATH "$2/lib" fi if [[ -d $2/man ]]; then "$1pend_" MANPATH "$2/man" fi } function prepath() { path_ pre "$@" } function postpath() { path_ post "$@" } if [[ -e ~/.pathrc ]]; then source ~/.pathrc fi # export EMAIL=user@example.com if [[ -e ~/.emailrc ]]; then source ~/.emailrc fi histsql=~/.bash_sqlite3 sqlite3 "${histsql}" ' create table if not exists "session" ( "id" integer not null primary key autoincrement, "address" text not null, "process" integer not null, "tty" text not null, "user" text not null, "start" timestamp not null default current_timestamp, "end" timestamp null ); create table if not exists "command" ( "session" integer not null, "line" integer not null, "time" timestamp not null default current_timestamp, "pwd" text not null, "text" text not null, primary key ("session", "line") ); ' if which ifconfig &>/dev/null; then histmac=$(ifconfig | sed -e '/.* HWaddr /{s///;q;};/.*ether /{s///;s/ .*//;q;};d') elif which ipconfig &>/dev/null; then histmac=$(ipconfig /all | sed -e '/Physical Address/{s/.* //;q;};d') else histmac="" fi histtty=$(tty) histssn=$(sqlite3 "${histsql}" " insert into \"session\" ( \"address\", \"process\", \"tty\", \"user\" ) values ( '${histmac//\'/$'\x27\x27'}', '${$//\'/$'\x27\x27'}', '${histtty//\'/$'\x27\x27'}', '${USER//\'/$'\x27\x27'}' ); select last_insert_rowid(); ") function histend { sqlite3 "${histsql}" " update \"session\" set \"end\" = current_timestamp where \"id\" = '${histssn//\'/$'\x27\x27'}'; " } trap histend EXIT function histadd { local data="$(HISTTIMEFORMAT= history 1)" if [[ -z $data ]]; then return; fi data="${data#"${data%%[![:space:]]*}"}" local line="${data%%' '*}" if [[ ${histnum} -eq ${line} ]]; then return; fi histnum=${line} data="${data#*' '}" data="${data#"${data%%[![:space:]]*}"}" sqlite3 "${histsql}" " insert or replace into \"command\" ( \"session\", \"line\", \"pwd\", \"text\" ) values ( '${histssn//\'/$'\x27\x27'}', '${line//\'/$'\x27\x27'}', '${PWD//\'/$'\x27\x27'}', '${data//\'/$'\x27\x27'}' ); " } trap histadd DEBUG