.bashrc 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. # ~/.bashrc: executed by bash(1) for non-login shells.
  2. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
  3. # for examples
  4. parse_git_branch() {
  5. git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
  6. }
  7. # If not running interactively, don't do anything
  8. case $- in
  9. *i*) ;;
  10. *) return;;
  11. esac
  12. # don't put duplicate lines or lines starting with space in the history.
  13. # See bash(1) for more options
  14. HISTCONTROL=ignoreboth
  15. # append to the history file, don't overwrite it
  16. shopt -s histappend
  17. # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
  18. HISTSIZE=1000
  19. HISTFILESIZE=2000
  20. # check the window size after each command and, if necessary,
  21. # update the values of LINES and COLUMNS.
  22. shopt -s checkwinsize
  23. # If set, the pattern "**" used in a pathname expansion context will
  24. # match all files and zero or more directories and subdirectories.
  25. #shopt -s globstar
  26. # make less more friendly for non-text input files, see lesspipe(1)
  27. [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
  28. # set variable identifying the chroot you work in (used in the prompt below)
  29. if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
  30. debian_chroot=$(cat /etc/debian_chroot)
  31. fi
  32. # set a fancy prompt (non-color, unless we know we "want" color)
  33. case "$TERM" in
  34. xterm-color) color_prompt=yes;;
  35. esac
  36. # uncomment for a colored prompt, if the terminal has the capability; turned
  37. # off by default to not distract the user: the focus in a terminal window
  38. # should be on the output of commands, not on the prompt
  39. force_color_prompt=yes
  40. if [ -n "$force_color_prompt" ]; then
  41. if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
  42. # We have color support; assume it's compliant with Ecma-48
  43. # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
  44. # a case would tend to support setf rather than setaf.)
  45. color_prompt=yes
  46. else
  47. color_prompt=
  48. fi
  49. fi
  50. if [ "$color_prompt" = yes ]; then
  51. #PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "
  52. #PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[33m\]$(parse_git_branch)\[\033[00m\] \$ '
  53. source /etc/bash_completion.d/docker-machine-prompt.bash
  54. PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[33m\]$(parse_git_branch)$(__docker_machine_ps1)\[\033[00m\] \$ '
  55. # Also do color ls
  56. export CLICOLOR=true
  57. else
  58. PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
  59. fi
  60. unset color_prompt force_color_prompt
  61. # If this is an xterm set the title to user@host:dir
  62. case "$TERM" in
  63. xterm*|rxvt*)
  64. PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
  65. ;;
  66. *)
  67. ;;
  68. esac
  69. # enable color support of ls and also add handy aliases
  70. if [ -x /usr/bin/dircolors ]; then
  71. test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
  72. alias ls='ls --color=auto'
  73. #alias dir='dir --color=auto'
  74. #alias vdir='vdir --color=auto'
  75. alias grep='grep --color=auto'
  76. alias fgrep='fgrep --color=auto'
  77. alias egrep='egrep --color=auto'
  78. fi
  79. # some more ls aliases
  80. alias ll='ls -alF'
  81. alias la='ls -A'
  82. alias l='ls -CF'
  83. # Add an "alert" alias for long running commands. Use like so:
  84. # sleep 10; alert
  85. alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
  86. # Alias definitions.
  87. # You may want to put all your additions into a separate file like
  88. # ~/.bash_aliases, instead of adding them here directly.
  89. # See /usr/share/doc/bash-doc/examples in the bash-doc package.
  90. if [ -f ~/.bash_aliases ]; then
  91. . ~/.bash_aliases
  92. fi
  93. # enable programmable completion features (you don't need to enable
  94. # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
  95. # sources /etc/bash.bashrc).
  96. if ! shopt -oq posix; then
  97. if [ -f /usr/share/bash-completion/bash_completion ]; then
  98. . /usr/share/bash-completion/bash_completion
  99. elif [ -f /etc/bash_completion ]; then
  100. . /etc/bash_completion
  101. fi
  102. fi
  103. export GOPATH=$HOME/go
  104. #export GOROOT=/usr/lib/go
  105. #export PATH=$PATH:$GOROOT/bin
  106. # Add scripts directories to the path
  107. if [ -d ~/scripts ]; then
  108. for D in ~/scripts/*; do
  109. export PATH=$PATH:$D
  110. done
  111. export PATH=$PATH:~/scripts
  112. fi
  113. # Add bin directories to the path
  114. if [ -d ~/bin ]; then
  115. export PATH=$PATH:~/bin
  116. fi
  117. if [ -d ~/xdr-terraform-live/bin ]; then
  118. export PATH=$PATH:~/xdr-terraform-live/bin
  119. fi
  120. # Add autocompletion for git
  121. source ~/.bash/git-completion.bash
  122. # Gitrob token
  123. [ -f ~/.git_token ] && source ~/.git_token
  124. # Add autocompletion for aws
  125. #[ -x /usr/local/bin/aws_completer ] && complete -C '/usr/local/bin/aws_completer' aws
  126. ## iTerm integration
  127. #[ -f ~/.iterm2_shell_integration.bash ] && source ~/.iterm2_shell_integration.bash
  128. # Additional possible paths
  129. [ -d /usr/local/heroku/bin ] && export PATH="/usr/local/heroku/bin:$PATH"
  130. [ -d $GOPATH/bin ] && export PATH="$GOPATH/bin:$PATH"
  131. [ -d ~/terraform ] && export PATH="~/terraform:$PATH"
  132. [ -d ~/esp/crosstool-NG/builds/xtensa-esp32-elf ] && export PATH="~/esp/crosstool-NG/builds/xtensa-esp32-elf:$PATH"
  133. # We want SSH keys to have passwords, so load the ssh agent
  134. SSH_ENV="$HOME/.ssh/environment"
  135. function start_agent {
  136. echo "Initialising new SSH agent..."
  137. /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
  138. echo succeeded
  139. chmod 600 "${SSH_ENV}"
  140. . "${SSH_ENV}" > /dev/null
  141. /usr/bin/ssh-add;
  142. }
  143. # Source SSH settings, if applicable
  144. if [ -f "${SSH_ENV}" ]; then
  145. . "${SSH_ENV}" > /dev/null
  146. #ps ${SSH_AGENT_PID} doesn't work under cywgin
  147. ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
  148. start_agent;
  149. }
  150. else
  151. start_agent;
  152. fi
  153. # Make less allow colors
  154. export LESS="-R"
  155. eval $(thefuck --alias)
  156. export ANSIBLE_INVENTORY=~/ansible/ansible_hosts
  157. export ANSIBLE_HOST_KEY_CHECKING=False
  158. # Make sure vundle is installed
  159. [ -f ~/.vim/bundle/Vundle.vim/autoload/vundle.vim ] || git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
  160. [[ $(type -P fortune) ]] && [[ $(type -P cowsay) ]] && [[ $(type -P lolcat) ]] && fortune | cowsay | lolcat
  161. # tabtab source for serverless package
  162. # uninstall by removing these lines or running `tabtab uninstall serverless`
  163. [ -f /usr/local/lib/node_modules/serverless/node_modules/tabtab/.completions/serverless.bash ] && . /usr/local/lib/node_modules/serverless/node_modules/tabtab/.completions/serverless.bash
  164. # tabtab source for sls package
  165. # uninstall by removing these lines or running `tabtab uninstall sls`
  166. [ -f /usr/local/lib/node_modules/serverless/node_modules/tabtab/.completions/sls.bash ] && . /usr/local/lib/node_modules/serverless/node_modules/tabtab/.completions/sls.bash
  167. [ -f ~/MyEnvironment/iterm2_shell_integration.bash ] && . ~/MyEnvironment/iterm2_shell_integration.bash
  168. # Python venv?
  169. if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
  170. if [ -f ~/awsinfo/scripts/awsinfo.bash ]; then
  171. alias awsinfo=~/awsinfo/scripts/awsinfo.bash
  172. fi
  173. alias python='python3'
  174. # WHen were passwords changed
  175. #echo; echo Password Last Changed:; u=$(dscl . list /Users | egrep -v '^_|daemon|nobody'); for i in $u; do printf \\n$i\\t; currentUser=$i;t=$(dscl . read /Users/"$currentUser" | grep -A1 passwordLastSetTime | grep real | awk -F'real>|</real' '{print $2}'); date -j -f %s "$t" 2> /dev/null; done
  176. if [[ "$(uname -s)" == "Darwin" ]]; then
  177. # Print password expirations:
  178. echo
  179. echo -n Password Expiration:
  180. u=$(dscl . list /Users | egrep -v '^_|daemon|nobody|root')
  181. for i in $u; do
  182. printf \\n$i\\t;
  183. currentUser=$i;
  184. t=$(dscl . read /Users/"$currentUser" | grep -A1 passwordLastSetTime | grep real | awk -F'real>|</real' '{print $2}');
  185. t=$(echo "$t" | cut -f1 -d".");
  186. t=$(expr $t + 5184000);
  187. echo -n $(date -j -f "%s" "$t" 2> /dev/null);
  188. done;
  189. echo
  190. fi
  191. #if [[ -x `which bw` ]]; then
  192. # export LANG=en_CA.UTF-8;export LOCALE=en_CA.UTF-8; `which bw` slab
  193. #fi
  194. export TF_PLUGIN_CACHE_DIR=~/.terraform.d/plugin-cache
  195. [[ -d "$TF_PLUGIN_CACHE_DIR" ]] || mkdir -p $TF_PLUGIN_CACHE_DIR
  196. # Better colors
  197. export LSCOLORS="gxfxcxdxbxegedabagacad"
  198. # Disable bell for tab completion
  199. #bind 'set bell-style none'
  200. echo ""
  201. echo "Reminder: Use command-shift-s to save your window arrangement, command-shift-r to restore."
  202. echo ""