.bashrc 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. if [[ -f /etc/bash_completion.d/docker-machine-prompt.bash ]]; then
  54. source /etc/bash_completion.d/docker-machine-prompt.bash
  55. 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\] \$ '
  56. fi
  57. # Also do color ls
  58. export CLICOLOR=true
  59. else
  60. PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
  61. fi
  62. unset color_prompt force_color_prompt
  63. # If this is an xterm set the title to user@host:dir
  64. case "$TERM" in
  65. xterm*|rxvt*)
  66. PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
  67. ;;
  68. *)
  69. ;;
  70. esac
  71. # enable color support of ls and also add handy aliases
  72. if [ -x /usr/bin/dircolors ]; then
  73. test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
  74. alias ls='ls --color=auto'
  75. #alias dir='dir --color=auto'
  76. #alias vdir='vdir --color=auto'
  77. alias grep='grep --color=auto'
  78. alias fgrep='fgrep --color=auto'
  79. alias egrep='egrep --color=auto'
  80. fi
  81. # some more ls aliases
  82. alias ll='ls -alF'
  83. alias la='ls -A'
  84. alias l='ls -CF'
  85. # Add an "alert" alias for long running commands. Use like so:
  86. # sleep 10; alert
  87. 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$//'\'')"'
  88. # Alias definitions.
  89. # You may want to put all your additions into a separate file like
  90. # ~/.bash_aliases, instead of adding them here directly.
  91. # See /usr/share/doc/bash-doc/examples in the bash-doc package.
  92. if [ -f ~/.bash_aliases ]; then
  93. . ~/.bash_aliases
  94. fi
  95. # enable programmable completion features (you don't need to enable
  96. # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
  97. # sources /etc/bash.bashrc).
  98. if ! shopt -oq posix; then
  99. if [ -f /usr/share/bash-completion/bash_completion ]; then
  100. . /usr/share/bash-completion/bash_completion
  101. elif [ -f /etc/bash_completion ]; then
  102. . /etc/bash_completion
  103. fi
  104. fi
  105. export GOPATH=$HOME/go
  106. #export GOROOT=/usr/lib/go
  107. #export PATH=$PATH:$GOROOT/bin
  108. # Add scripts directories to the path
  109. if [ -d ~/scripts ]; then
  110. for D in ~/scripts/*; do
  111. export PATH=$PATH:$D
  112. done
  113. export PATH=$PATH:~/scripts
  114. fi
  115. # Add bin directories to the path
  116. if [ -d ~/bin ]; then
  117. export PATH=$PATH:~/bin
  118. fi
  119. # Add python bin directories to the path
  120. if [ -d ~/Library/Python/3.8/bin ]; then
  121. export PATH=$PATH:~/Library/Python/3.8/bin
  122. fi
  123. if [ -d ~/xdr-terraform-live/bin ]; then
  124. export PATH=$PATH:~/xdr-terraform-live/bin
  125. fi
  126. # Add autocompletion for git
  127. source ~/.bash/git-completion.bash
  128. # Gitrob token
  129. [ -f ~/.git_token ] && source ~/.git_token
  130. # Add autocompletion for aws
  131. #[ -x /usr/local/bin/aws_completer ] && complete -C '/usr/local/bin/aws_completer' aws
  132. ## iTerm integration
  133. #[ -f ~/.iterm2_shell_integration.bash ] && source ~/.iterm2_shell_integration.bash
  134. # Additional possible paths
  135. [ -d /usr/local/heroku/bin ] && export PATH="/usr/local/heroku/bin:$PATH"
  136. [ -d $GOPATH/bin ] && export PATH="$GOPATH/bin:$PATH"
  137. [ -d ~/terraform ] && export PATH="~/terraform:$PATH"
  138. [ -d ~/esp/crosstool-NG/builds/xtensa-esp32-elf ] && export PATH="~/esp/crosstool-NG/builds/xtensa-esp32-elf:$PATH"
  139. # We want SSH keys to have passwords, so load the ssh agent
  140. SSH_ENV="$HOME/.ssh/environment"
  141. function start_agent {
  142. echo "Initialising new SSH agent..."
  143. /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
  144. echo succeeded
  145. chmod 600 "${SSH_ENV}"
  146. . "${SSH_ENV}" > /dev/null
  147. /usr/bin/ssh-add;
  148. }
  149. # Source SSH settings, if applicable
  150. if [ -f "${SSH_ENV}" ]; then
  151. . "${SSH_ENV}" > /dev/null
  152. #ps ${SSH_AGENT_PID} doesn't work under cywgin
  153. ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
  154. start_agent;
  155. }
  156. else
  157. start_agent;
  158. fi
  159. # Make less allow colors
  160. export LESS="-R"
  161. eval $(thefuck --alias)
  162. # These are legacy
  163. #export ANSIBLE_INVENTORY=~/ansible/ansible_hosts
  164. #export ANSIBLE_HOST_KEY_CHECKING=False
  165. # Make sure vundle is installed
  166. [ -f ~/.vim/bundle/Vundle.vim/autoload/vundle.vim ] || git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
  167. [[ $(type -P fortune) ]] && [[ $(type -P cowsay) ]] && [[ $(type -P lolcat) ]] && fortune | cowsay | lolcat
  168. # tabtab source for serverless package
  169. # uninstall by removing these lines or running `tabtab uninstall serverless`
  170. [ -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
  171. # tabtab source for sls package
  172. # uninstall by removing these lines or running `tabtab uninstall sls`
  173. [ -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
  174. [ -f ~/MyEnvironment/iterm2_shell_integration.bash ] && . ~/MyEnvironment/iterm2_shell_integration.bash
  175. # Python venv?
  176. if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
  177. if [ -f ~/awsinfo/scripts/awsinfo.bash ]; then
  178. alias awsinfo=~/awsinfo/scripts/awsinfo.bash
  179. fi
  180. alias python='python3'
  181. # WHen were passwords changed
  182. #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
  183. if [[ "$(uname -s)" == "Darwin" ]]; then
  184. # Print password expirations:
  185. echo
  186. echo -n Password Expiration:
  187. u=$(dscl . list /Users | egrep -v '^_|daemon|nobody|root')
  188. for i in $u; do
  189. printf \\n$i\\t;
  190. currentUser=$i;
  191. t=$(dscl . read /Users/"$currentUser" | grep -A1 passwordLastSetTime | grep real | awk -F'real>|</real' '{print $2}');
  192. t=$(echo "$t" | cut -f1 -d".");
  193. t=$(expr $t + 5184000);
  194. echo -n $(date -j -f "%s" "$t" 2> /dev/null);
  195. done;
  196. echo
  197. fi
  198. #if [[ -x `which bw` ]]; then
  199. # export LANG=en_CA.UTF-8;export LOCALE=en_CA.UTF-8; `which bw` slab
  200. #fi
  201. if [[ -x `which microk8s` ]]; then
  202. alias kubectl='microk8s kubectl'
  203. fi
  204. # May be incompatible with tf14+
  205. export TF_PLUGIN_CACHE_DIR=~/.terraform.d/plugin-cache
  206. [[ -d "$TF_PLUGIN_CACHE_DIR" ]] || mkdir -p $TF_PLUGIN_CACHE_DIR
  207. # Better colors
  208. export LSCOLORS="gxfxcxdxbxegedabagacad"
  209. # Disable bell for tab completion
  210. #bind 'set bell-style none'
  211. export EDITOR=vim
  212. echo ""
  213. echo "Reminder: Use command-shift-s to save your window arrangement, command-shift-r to restore."
  214. echo ""