Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # $HOME/.bashrc
- # This is the Bash shell $BASH_ENV file (aka .bashrc).
- # This file is sourced for interactive (bash -i) sessions.
- # source the system wide bashrc
- [ -f /etc/bashrc ] && . /etc/bashrc
- [ -f /etc/bash.bashrc ] && . /etc/bash.bashrc
- # shopt options
- shopt -s checkwinsize # Check window after each command.
- shopt -s dotglob # files beginning with . to show 'echo *'.
- shopt -s histappend # Append $HISTSIZE lines to $HISTFILE.
- # Bash history knobs.
- export HISTCONTROL=${HISTCONTROL:-"ignoreboth"} # Ignore repeated cmds, or begin with space.
- export HISTIGNORE=${HISTIGNORE:-"ls:ll:la:l."} # Explicitly ignore file listing.
- export HISTTIMEFORMAT="%F %H:%M " # The libc strftime(3) format (man -s3 strftime).
- export HISTFILE="$HOME/.bash_history" # Default is ~/.sh_history.
- export HISTSIZE=${HISTSIZE:-"1000"} # Lines of command history logged (in memory).
- export HISTFILESIZE=${HISTSIZE:-"2000"} # maximum number of history events to save (in file).
- ## Terminal settings (quirks)
- if [ "`uname -s`" = "HP-UX" ] && [ "$TERM" = "xterm" ]
- then # fix hp-ux backspace key in xterm.
- stty intr ^c
- stty erase ^?
- fi
- ## Terminal color capability switch.
- ## in order of desire: tput, ascii
- ## NOTE: The zsh right side escape (close-stash) is itself escaped, but not the left (open-stash).
- ## The aforementioned escaping may interfear with syntax highlighting of this file, no worries, it is fine.
- tput setaf 4
- case $? in
- 0) # tput works.
- tput sgr0
- #printf "TPUT STYLE CHOSEN\n"
- Rc="${BASH:+\\[}${ZSH_VERSION:+%{}`printf \"setaf 1\n\" | tput -S`${ZSH_VERSION:+%\}}${BASH:+\\]}"
- Yc="${BASH:+\\[}${ZSH_VERSION:+%{}`printf \"setaf 3\n\" | tput -S`${ZSH_VERSION:+%\}}${BASH:+\\]}"
- Bc="${BASH:+\\[}${ZSH_VERSION:+%{}`printf \"setaf 4\n\" | tput -S`${ZSH_VERSION:+%\}}${BASH:+\\]}"
- Wc="${BASH:+\\[}${ZSH_VERSION:+%{}`printf \"setaf 7\nbold\n\" | tput -S`${ZSH_VERSION:+%\}}${BASH:+\\]}"
- Nc="${BASH:+\\[}${ZSH_VERSION:+%{}`tput sgr0`${ZSH_VERSION:+%\}}${BASH:+\\]}"
- ;;
- *) # setup the ascii methods.
- #printf "ASCII STYLE CHOSEN\n"
- Rc="${BASH:+\\[}${ZSH_VERSION:+%{}\033[0;31m${ZSH_VERSION:+%\}}${BASH:+\\]}"
- Yc="${BASH:+\\[}${ZSH_VERSION:+%{}\033[0;33m${ZSH_VERSION:+%\}}${BASH:+\\]}"
- Bc="${BASH:+\\[}${ZSH_VERSION:+%{}\033[0;34m${ZSH_VERSION:+%\}}${BASH:+\\]}"
- Wc="${BASH:+\\[}${ZSH_VERSION:+%{}\033[1;37m${ZSH_VERSION:+%\}}${BASH:+\\]}"
- Nc="${BASH:+\\[}${ZSH_VERSION:+%{}\033[0m${ZSH_VERSION:+%\}}${BASH:+\\]}"
- ;;
- esac
- ## xterm and putty support dynamic in-session modification of the titlebar.
- ## putty titlebar - section 4.9.1 putty User Manual
- ## "PuTTY allows the server to send xterm control sequences which modify the title of the window in mid-session "
- ## Please note the begining and ending are literal escapes (Control Sequences), and will not survive copy/paste.
- ## in VI - INSERT MODE - type ctrl+v - then type esc for "^[" OR ctrl+g for "^G" - then esc to exit insert mode.
- titlebar () {
- ## NOTE: Might be better to negate DUMB terminals instead of inclusive list of supported terms.
- if [ "$TERM" = "xterm" ] || [ "$TERM" = "xterm-color" ] || [ "$TERM" = "sun-color" ] || [ "$TERM" = "rxvt-unicode-256xolor" ]
- #then printf ".]0;${@}." > `tty`
- # This new method uses interprited escapes, is equivilent, and works when the line is copy/pasted.
- then printf "\033]0;${@}\007" > `tty`
- fi
- }
- ## This function updates the interactive prompt.
- ## Note the id(1) usage to work-around Solaris (without having to choose xpg4 id that supports -u).
- setprompt() {
- _SYS=`hostname | sed 's|\..*||'`
- # The basename of the current working directory, with $HOME abbreviated with a tilde.
- # If the current working directory is a first-tier location, it is preceeded with a slash (example: /etc or /tmp).
- OIFS=$IFS
- IFS='/'
- set $PWD
- IFS=$OIFS
- unset OIFS
- # home
- if [ "$PWD" = "$HOME" ]
- then _PWD="${Yc}~${Nc}"
- # inside home
- elif [ "${PWD}" = "${HOME}${PWD#${HOME}}" ]
- then _PWD="${Yc}~${Nc}${PWD#${HOME}}"
- # non-home
- elif [ "$#" -le "2" ]
- then _PWD="${PWD}"
- else _PWD="${PWD##*/}"
- fi
- shift $#
- # make non-writable dirs red.
- [ -w "${PWD}" ] || _PWD="${Rc}${_PWD}${_Nc}"
- case `id | cut -d'(' -f1 | cut -c5-` in
- 0) # Privledge prompt
- _PS1="${Rc}[${Nc}${LOGNAME}${Rc}@${Nc}${_SYS}${Rc}:${Nc}${Wc}${_PWD}${Nc}${Rc}]${Nc}${Wc}# ${Nc}"
- _PS2="${Rc}> ${Nc}"
- ;;
- *) # User prompt
- _PS1="${Bc}[${Nc}${LOGNAME}${Bc}@${Nc}${_SYS}${Bc}:${Nc}${Wc}${_PWD}${Nc}${Bc}]${Nc}${Wc}$ ${Nc}"
- _PS2="${Bc}> ${Nc}"
- ;;
- esac
- COLUMNS=`expr ${#_PS1} + 10`
- PS1=`echo ${_PS1}`
- PS2=`echo ${_PS2}`
- # Set xterm or Putty title bar.
- titlebar "${LOGNAME}@${_SYS}:${PWD}"
- unset _SYS _PWD
- }
- # This function uses the korn shell built-in CD cmd, and the setprompt function together.
- # the effect is the user prompt displays updated path.
- # this function is designed to replaice (alias) the cd cmd.
- prompt_cd() {
- \cd "${@:-"$HOME"}" && setprompt
- }
- # the prompt features the working path, and colors.
- unset PROMPT_COMMAND
- setprompt
- alias cd="prompt_cd"
- alias ..='prompt_cd .. ; printf "$PWD\n"'
- # List enhancements
- # Solaris 5.11 may have GNU ls(1) installed.
- [ "`uname -s`" = "SunOS" ] && \
- [ "`uname -r`" = "5.11" ] && \
- [ -x "/usr/gnu/bin/ls" ] && export PATH="/usr/gnu/bin/:$PATH" alias ls='/usr/gnu/bin/ls'
- # check for GNU ls (colorful list)
- ls --version 2> /dev/null | grep GNU >/dev/null 2>&1 && export LS_COLOUR="--color=auto"
- # check for OSX ls (has color via -G
- [ "`uname -s`" = "Darwin" ] && export LS_COLOUR="-G"
- # check for human readable ( -h )
- ## I Don't like -h
- #ls -h /dev/null 2> /dev/null 1>&2 && H='-h'
- alias l.='ls -lAdF ${H} ${LS_COLOUR} .*' # list only hidden things
- alias la='ls -lAF ${H} ${LS_COLOUR}' # list all
- alias ll='ls -lF ${H} ${LS_COLOUR}' # list long
- alias ls='ls -F ${LS_COLOUR}' # list with flags
- ## GNU grep, if available, has colorized output.
- grep --version 2> /dev/null | grep GNU >/dev/null 2>&1 && alias grep='grep --color=auto'
- # When EDITOR == vim ; alias vi to vim
- [ "${EDITOR##*/}" = "vim" ] && alias vi='vim'
- #THE END
- export DOT_BASHRC="TRUE"
- ### END DEFAULT ###
- if [ -f ~/.bash_aliases ]; then
- . ~/.bash_aliases
- fi
- if [ -f /etc/bash_completion ]; then
- . /etc/bash_completion
- fi
- #if brew is installed (eg, we're on a mac), source the bash_completion file for it.
- type -P brew &>/dev/null && source `brew --prefix`/Library/Contributions/brew_bash_completion.sh
- export PATH=$PATH:~/bin
- set -o vi
- #override TERM so that byobu and vim display in color on Chrome's Crosh shell
- #also test for if we're using rxvt and convert to xterm-color
- if [ "x$TERM" = "xxterm" ] || [ "x$TERM" = "xrxvt-unicode-256color" ] ; then
- export TERM=xterm-color
- fi
- if [ -x /usr/bin/keychain ] ; then
- keychain --quiet ~/.ssh/id_rsa
- [ -f ~/.keychain/$HOSTNAME-sh ] && . ~/.keychain/$HOSTNAME-sh
- [ -f ~/.keychain/$HOSTNAME-sh-gpg ] && . ~/.keychain/$HOSTNAME-sh-gpg
- fi
- # update dotfiles
- if [[ "x$SSH_AGENT_PID" != "x" || "x$SSH_AUTH_SOCK" != "x" ]]; then
- dotfiles-pull -d
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement