Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 7.21 KB | None | 0 0
  1. # $HOME/.bashrc
  2. # This is the Bash shell $BASH_ENV file (aka .bashrc).
  3. # This file is sourced for interactive (bash -i) sessions.
  4.  
  5.  
  6. # source the system wide bashrc
  7. [ -f /etc/bashrc ] && . /etc/bashrc
  8. [ -f /etc/bash.bashrc ] && . /etc/bash.bashrc
  9.  
  10.  
  11. # shopt options
  12. shopt -s checkwinsize   # Check window after each command.
  13. shopt -s dotglob                # files beginning with . to show 'echo *'.
  14. shopt -s histappend     # Append $HISTSIZE lines to $HISTFILE.
  15.  
  16.  
  17. # Bash history knobs.
  18. export HISTCONTROL=${HISTCONTROL:-"ignoreboth"} # Ignore repeated cmds, or begin with space.
  19. export HISTIGNORE=${HISTIGNORE:-"ls:ll:la:l."}  # Explicitly ignore file listing.
  20. export HISTTIMEFORMAT="%F %H:%M  "              # The libc strftime(3) format (man -s3 strftime).
  21. export HISTFILE="$HOME/.bash_history"    # Default is ~/.sh_history.
  22. export HISTSIZE=${HISTSIZE:-"1000"}      # Lines of command history logged (in memory).
  23. export HISTFILESIZE=${HISTSIZE:-"2000"}  # maximum number of history events to save (in file).
  24.  
  25.  
  26.  
  27. ## Terminal settings (quirks)
  28. if [ "`uname -s`" = "HP-UX" ] && [ "$TERM" = "xterm" ]
  29. then # fix hp-ux backspace key in xterm.
  30.     stty intr ^c
  31.     stty erase ^?
  32. fi
  33.  
  34.  
  35.  
  36. ## Terminal color capability switch.
  37. ## in order of desire: tput, ascii
  38. ## NOTE: The zsh right side escape (close-stash) is itself escaped, but not the left (open-stash).
  39. ## The aforementioned escaping may interfear with syntax highlighting of this file, no worries, it is fine.
  40. tput setaf 4
  41. case $? in
  42.   0) # tput works.
  43.      tput sgr0
  44.      #printf "TPUT STYLE CHOSEN\n"
  45.      Rc="${BASH:+\\[}${ZSH_VERSION:+%{}`printf \"setaf 1\n\" | tput -S`${ZSH_VERSION:+%\}}${BASH:+\\]}"
  46.      Yc="${BASH:+\\[}${ZSH_VERSION:+%{}`printf \"setaf 3\n\" | tput -S`${ZSH_VERSION:+%\}}${BASH:+\\]}"
  47.      Bc="${BASH:+\\[}${ZSH_VERSION:+%{}`printf \"setaf 4\n\" | tput -S`${ZSH_VERSION:+%\}}${BASH:+\\]}"
  48.      Wc="${BASH:+\\[}${ZSH_VERSION:+%{}`printf \"setaf 7\nbold\n\" | tput -S`${ZSH_VERSION:+%\}}${BASH:+\\]}"
  49.      Nc="${BASH:+\\[}${ZSH_VERSION:+%{}`tput sgr0`${ZSH_VERSION:+%\}}${BASH:+\\]}"
  50.   ;;
  51.   *) # setup the ascii methods.
  52.      #printf "ASCII STYLE CHOSEN\n"
  53.      Rc="${BASH:+\\[}${ZSH_VERSION:+%{}\033[0;31m${ZSH_VERSION:+%\}}${BASH:+\\]}"
  54.      Yc="${BASH:+\\[}${ZSH_VERSION:+%{}\033[0;33m${ZSH_VERSION:+%\}}${BASH:+\\]}"
  55.      Bc="${BASH:+\\[}${ZSH_VERSION:+%{}\033[0;34m${ZSH_VERSION:+%\}}${BASH:+\\]}"
  56.      Wc="${BASH:+\\[}${ZSH_VERSION:+%{}\033[1;37m${ZSH_VERSION:+%\}}${BASH:+\\]}"
  57.      Nc="${BASH:+\\[}${ZSH_VERSION:+%{}\033[0m${ZSH_VERSION:+%\}}${BASH:+\\]}"
  58.   ;;
  59. esac
  60.  
  61.  
  62. ## xterm and putty support dynamic in-session modification of the titlebar.
  63. ## putty titlebar - section 4.9.1 putty User Manual
  64. ## "PuTTY allows the server to send xterm control sequences which modify the title of the window in mid-session "
  65. ## Please note the begining and ending are literal escapes (Control Sequences), and will not survive copy/paste.
  66. ## in VI - INSERT MODE - type ctrl+v - then type esc for "^[" OR ctrl+g for "^G" - then esc to exit insert mode.
  67. titlebar () {
  68.   ## NOTE: Might be better to negate DUMB terminals instead of inclusive list of supported terms.
  69.   if [ "$TERM" = "xterm" ] || [ "$TERM" = "xterm-color" ] || [ "$TERM" = "sun-color" ] || [ "$TERM" = "rxvt-unicode-256xolor" ]
  70.   #then printf ".]0;${@}." > `tty`
  71.  
  72.   # This new method uses interprited escapes, is equivilent, and works when the line is copy/pasted.
  73.   then printf "\033]0;${@}\007" > `tty`
  74.   fi
  75. }
  76.  
  77.  
  78.  
  79. ## This function updates the interactive prompt.
  80. ## Note the id(1) usage to work-around Solaris (without having to choose xpg4 id that supports -u).
  81. setprompt() {
  82.  
  83.   _SYS=`hostname | sed 's|\..*||'`
  84.  
  85.   # The basename of the current working directory, with $HOME abbreviated with a tilde.
  86.   # If the current working directory is a first-tier location, it is preceeded with a slash (example: /etc or /tmp).
  87.  
  88.   OIFS=$IFS
  89.   IFS='/'
  90.   set $PWD
  91.   IFS=$OIFS
  92.   unset OIFS
  93.  
  94.   # home
  95.   if   [ "$PWD" = "$HOME" ]
  96.     then _PWD="${Yc}~${Nc}"
  97.  
  98.   # inside home
  99.   elif [ "${PWD}" = "${HOME}${PWD#${HOME}}" ]
  100.     then _PWD="${Yc}~${Nc}${PWD#${HOME}}"
  101.  
  102.   # non-home
  103.   elif [ "$#" -le "2"  ]
  104.     then _PWD="${PWD}"
  105.     else _PWD="${PWD##*/}"
  106.   fi
  107.   shift $#
  108.  
  109.   # make non-writable dirs red.
  110.   [ -w "${PWD}" ] || _PWD="${Rc}${_PWD}${_Nc}"
  111.  
  112.   case `id | cut -d'(' -f1 | cut -c5-` in
  113.   0)   # Privledge prompt
  114.     _PS1="${Rc}[${Nc}${LOGNAME}${Rc}@${Nc}${_SYS}${Rc}:${Nc}${Wc}${_PWD}${Nc}${Rc}]${Nc}${Wc}# ${Nc}"
  115.     _PS2="${Rc}>  ${Nc}"
  116.   ;;
  117.   *)   # User prompt
  118.     _PS1="${Bc}[${Nc}${LOGNAME}${Bc}@${Nc}${_SYS}${Bc}:${Nc}${Wc}${_PWD}${Nc}${Bc}]${Nc}${Wc}$ ${Nc}"
  119.     _PS2="${Bc}>  ${Nc}"
  120.   ;;
  121.   esac
  122.   COLUMNS=`expr ${#_PS1} + 10`
  123.   PS1=`echo ${_PS1}`
  124.   PS2=`echo ${_PS2}`
  125.  
  126.   # Set xterm or Putty title bar.
  127.   titlebar "${LOGNAME}@${_SYS}:${PWD}"
  128.  
  129.   unset _SYS _PWD
  130. }
  131.  
  132.  
  133. # This function uses the korn shell built-in CD cmd, and the setprompt function together.
  134. # the effect is the user prompt displays updated path.
  135. # this function is designed to replaice (alias) the cd cmd.
  136. prompt_cd() {
  137.   \cd "${@:-"$HOME"}" && setprompt
  138. }
  139.  
  140.  
  141.  
  142.  
  143.  
  144. # the prompt features the working path, and colors.
  145. unset PROMPT_COMMAND
  146. setprompt
  147. alias cd="prompt_cd"
  148. alias ..='prompt_cd .. ; printf "$PWD\n"'
  149.  
  150.  
  151. # List enhancements
  152. # Solaris 5.11 may have GNU ls(1) installed.
  153. [ "`uname -s`" = "SunOS" ] && \
  154. [ "`uname -r`" = "5.11" ] && \
  155. [ -x "/usr/gnu/bin/ls" ] && export PATH="/usr/gnu/bin/:$PATH" alias ls='/usr/gnu/bin/ls'
  156.  
  157. # check for GNU ls (colorful list)
  158. ls --version 2> /dev/null | grep GNU >/dev/null 2>&1 && export LS_COLOUR="--color=auto"
  159. # check for OSX ls (has color via -G
  160. [ "`uname -s`" = "Darwin" ] && export LS_COLOUR="-G"
  161.  
  162.  
  163. # check for human readable ( -h )
  164. ## I Don't like -h
  165. #ls -h /dev/null 2> /dev/null 1>&2 && H='-h'
  166.  
  167. alias l.='ls -lAdF ${H} ${LS_COLOUR} .*'    # list only hidden things
  168. alias la='ls -lAF ${H} ${LS_COLOUR}'        # list all
  169. alias ll='ls -lF ${H} ${LS_COLOUR}'         # list long
  170. alias ls='ls -F ${LS_COLOUR}'               # list with flags
  171.  
  172. ## GNU grep, if available, has colorized output.
  173. grep --version 2> /dev/null | grep GNU >/dev/null 2>&1 && alias grep='grep --color=auto'
  174.  
  175.  
  176. # When EDITOR == vim ; alias vi to vim
  177. [ "${EDITOR##*/}" = "vim" ] && alias vi='vim'
  178.  
  179.  
  180.  
  181.  
  182. #THE END
  183. export DOT_BASHRC="TRUE"
  184.  
  185. ### END DEFAULT ###
  186.  
  187. if [ -f ~/.bash_aliases ]; then
  188.     . ~/.bash_aliases
  189. fi
  190.  
  191. if [ -f /etc/bash_completion ]; then
  192.     . /etc/bash_completion
  193. fi
  194.  
  195. #if brew is installed (eg, we're on a mac), source the bash_completion file for it.
  196. type -P brew &>/dev/null && source `brew --prefix`/Library/Contributions/brew_bash_completion.sh
  197.  
  198. export PATH=$PATH:~/bin
  199. set -o vi
  200.  
  201. #override TERM so that byobu and vim display in color on Chrome's Crosh shell
  202. #also test for if we're using rxvt and convert to xterm-color
  203. if [ "x$TERM" = "xxterm" ] || [ "x$TERM" = "xrxvt-unicode-256color" ] ; then
  204.   export TERM=xterm-color
  205. fi
  206.  
  207. if [ -x /usr/bin/keychain ] ; then
  208.  keychain --quiet ~/.ssh/id_rsa
  209.  [ -f ~/.keychain/$HOSTNAME-sh ] && . ~/.keychain/$HOSTNAME-sh
  210.  [ -f ~/.keychain/$HOSTNAME-sh-gpg ] && . ~/.keychain/$HOSTNAME-sh-gpg
  211. fi
  212.  
  213. # update dotfiles
  214. if [[ "x$SSH_AGENT_PID" != "x" || "x$SSH_AUTH_SOCK" != "x" ]]; then
  215.   dotfiles-pull -d
  216. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement