.bashrc 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. export 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. export HISTSIZE=
  19. export HISTFILESIZE=
  20. export HISTTIMEFORMAT="[%F %T ] "
  21. # If you want to be extra certain, you can force bash to write the
  22. # history file every prompt
  23. # https://superuser.com/questions/20900/bash-history-loss-when-using-histappend
  24. PROMPT_COMMAND="history -a"
  25. # check the window size after each command and, if necessary,
  26. # update the values of LINES and COLUMNS.
  27. shopt -s checkwinsize
  28. # If set, the pattern "**" used in a pathname expansion context will
  29. # match all files and zero or more directories and subdirectories.
  30. shopt -s globstar
  31. # If set, will fail if you use a '*' and there are no matches, rather than
  32. # passing through the wildcard.
  33. shopt -s failglob
  34. # make less more friendly for non-text input files, see lesspipe(1)
  35. [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
  36. # set variable identifying the chroot you work in (used in the prompt below)
  37. if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
  38. debian_chroot=$(cat /etc/debian_chroot)
  39. fi
  40. # set a fancy prompt (non-color, unless we know we "want" color)
  41. case "$TERM" in
  42. xterm-color) color_prompt=yes;;
  43. esac
  44. # uncomment for a colored prompt, if the terminal has the capability; turned
  45. # off by default to not distract the user: the focus in a terminal window
  46. # should be on the output of commands, not on the prompt
  47. force_color_prompt=yes
  48. if [ -n "$force_color_prompt" ]; then
  49. if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
  50. # We have color support; assume it's compliant with Ecma-48
  51. # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
  52. # a case would tend to support setf rather than setaf.)
  53. color_prompt=yes
  54. else
  55. color_prompt=
  56. fi
  57. fi
  58. if [ "$color_prompt" = yes ]; then
  59. #PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "
  60. 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\] \$ '
  61. if [[ -f /etc/bash_completion.d/docker-machine-prompt.bash ]]; then
  62. source /etc/bash_completion.d/docker-machine-prompt.bash
  63. 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\] \$ '
  64. fi
  65. # Also do color ls
  66. export CLICOLOR=true
  67. else
  68. PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
  69. fi
  70. unset color_prompt force_color_prompt
  71. # If this is an xterm set the title to user@host:dir
  72. case "$TERM" in
  73. xterm*|rxvt*)
  74. PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
  75. ;;
  76. *)
  77. ;;
  78. esac
  79. # enable color support of ls and also add handy aliases
  80. if [ -x /usr/bin/dircolors ]; then
  81. test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
  82. alias ls='ls --color=auto'
  83. #alias dir='dir --color=auto'
  84. #alias vdir='vdir --color=auto'
  85. alias grep='grep --color=auto'
  86. alias fgrep='fgrep --color=auto'
  87. alias egrep='egrep --color=auto'
  88. fi
  89. # some more ls aliases
  90. alias ll='ls -alF'
  91. alias la='ls -A'
  92. alias l='ls -CF'
  93. # Add an "alert" alias for long running commands. Use like so:
  94. # sleep 10; alert
  95. 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$//'\'')"'
  96. # Alias definitions.
  97. # You may want to put all your additions into a separate file like
  98. # ~/.bash_aliases, instead of adding them here directly.
  99. # See /usr/share/doc/bash-doc/examples in the bash-doc package.
  100. if [ -f ~/.bash_aliases ]; then
  101. . ~/.bash_aliases
  102. fi
  103. # enable programmable completion features (you don't need to enable
  104. # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
  105. # sources /etc/bash.bashrc).
  106. if ! shopt -oq posix; then
  107. if [ -f /usr/share/bash-completion/bash_completion ]; then
  108. . /usr/share/bash-completion/bash_completion
  109. elif [ -f /etc/bash_completion ]; then
  110. . /etc/bash_completion
  111. fi
  112. fi
  113. export GOPATH=$HOME/go
  114. #export GOROOT=/usr/lib/go
  115. #export PATH=$PATH:$GOROOT/bin
  116. # Add homebrew directories to the path
  117. if [ -d /opt/homebrew/bin ]; then
  118. export PATH=$PATH:/opt/homebrew/bin
  119. fi
  120. # Add scripts directories to the path
  121. if [ -d ~/scripts ]; then
  122. for D in ~/scripts/*; do
  123. export PATH=$PATH:$D
  124. done
  125. export PATH=$PATH:~/scripts
  126. fi
  127. # Add bin directories to the path
  128. if [ -d ~/bin ]; then
  129. export PATH=$PATH:~/bin
  130. fi
  131. # Add python bin directories to the path
  132. if [ -d ~/Library/Python/3.8/bin ]; then
  133. export PATH=$PATH:~/Library/Python/3.8/bin
  134. fi
  135. if [ -d ~/.chefdk/gem/ruby/2.6.0/bin ]; then
  136. export PATH=$PATH:~/.chefdk/gem/ruby/2.6.0/bin
  137. fi
  138. if [ -d ~/.local/bin ]; then
  139. export PATH=$PATH:~/.local/bin
  140. fi
  141. if [ -d ~/.gem/ruby/2.6.0/bin ]; then
  142. export PATH=$PATH:~/.gem/ruby/2.6.0/bin
  143. fi
  144. if [ -d ~/xdr-terraform-live/bin ]; then
  145. export PATH=$PATH:~/xdr-terraform-live/bin
  146. fi
  147. if [ -d ${KREW_ROOT:-$HOME/.krew}/bin ]; then
  148. export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
  149. fi
  150. if [ -d $HOME/.cargo ]; then
  151. . "$HOME/.cargo/env"
  152. fi
  153. # Add autocompletion for git
  154. source ~/.bash/git-completion.bash
  155. # Gitrob token
  156. [ -f ~/.git_token ] && source ~/.git_token
  157. # Add autocompletion for aws
  158. #[ -x /usr/local/bin/aws_completer ] && complete -C '/usr/local/bin/aws_completer' aws
  159. ## iTerm integration
  160. #[ -f ~/.iterm2_shell_integration.bash ] && source ~/.iterm2_shell_integration.bash
  161. # Additional possible paths
  162. [ -d /usr/local/heroku/bin ] && export PATH="/usr/local/heroku/bin:$PATH"
  163. [ -d $GOPATH/bin ] && export PATH="$GOPATH/bin:$PATH"
  164. [ -d ~/terraform ] && export PATH="~/terraform:$PATH"
  165. [ -d ~/esp/crosstool-NG/builds/xtensa-esp32-elf ] && export PATH="~/esp/crosstool-NG/builds/xtensa-esp32-elf:$PATH"
  166. # We want SSH keys to have passwords, so load the ssh agent
  167. SSH_ENV="$HOME/.ssh/environment"
  168. function start_agent {
  169. echo "Initialising new SSH agent..."
  170. /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
  171. echo succeeded
  172. chmod 600 "${SSH_ENV}"
  173. . "${SSH_ENV}" > /dev/null
  174. if [[ "$OSTYPE" == "darwin21" ]]; then
  175. /usr/bin/ssh-add --apple-load-keychain
  176. else
  177. /usr/bin/ssh-add
  178. fi
  179. }
  180. # Source SSH settings, if applicable
  181. if [ -f "${SSH_ENV}" ]; then
  182. . "${SSH_ENV}" > /dev/null
  183. #ps ${SSH_AGENT_PID} doesn't work under cywgin
  184. ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
  185. start_agent;
  186. }
  187. else
  188. start_agent;
  189. fi
  190. # Make less allow colors
  191. export LESS="-R"
  192. [ -f /opt/homebrew/bin/thefuck ] && eval $(/opt/homebrew/bin/thefuck --alias)
  193. # These are legacy
  194. #export ANSIBLE_INVENTORY=~/ansible/ansible_hosts
  195. #export ANSIBLE_HOST_KEY_CHECKING=False
  196. # Make sure vundle is installed
  197. [ -f ~/.vim/bundle/Vundle.vim/autoload/vundle.vim ] || git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
  198. [[ $(type -P fortune) ]] && [[ $(type -P cowsay) ]] && [[ $(type -P lolcat) ]] && fortune | cowsay | lolcat
  199. # tabtab source for serverless package
  200. # uninstall by removing these lines or running `tabtab uninstall serverless`
  201. [ -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
  202. # tabtab source for sls package
  203. # uninstall by removing these lines or running `tabtab uninstall sls`
  204. [ -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
  205. [ -f ~/MyEnvironment/iterm2_shell_integration.bash ] && . ~/MyEnvironment/iterm2_shell_integration.bash
  206. [ -f "`which chef`" ] && eval "$(chef shell-init bash)"
  207. # Python venv?
  208. if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
  209. if [ -f ~/awsinfo/scripts/awsinfo.bash ]; then
  210. alias awsinfo=~/awsinfo/scripts/awsinfo.bash
  211. fi
  212. alias python='python3'
  213. # WHen were passwords changed
  214. #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
  215. if [[ "$(uname -s)" == "Darwin" ]]; then
  216. # Print password expirations:
  217. echo
  218. echo -n Password Expiration:
  219. u=$(dscl . list /Users | egrep -v '^_|daemon|nobody|root')
  220. for i in $u; do
  221. printf \\n$i\\t;
  222. currentUser=$i;
  223. t=$(dscl . read /Users/"$currentUser" | grep -A1 passwordLastSetTime | grep real | awk -F'real>|</real' '{print $2}');
  224. t=$(echo "$t" | cut -f1 -d".");
  225. t=$(expr $t + 5184000);
  226. echo -n $(date -j -f "%s" "$t" 2> /dev/null);
  227. done;
  228. echo
  229. fi
  230. #if [[ -x `which bw` ]]; then
  231. # export LANG=en_CA.UTF-8;export LOCALE=en_CA.UTF-8; `which bw` slab
  232. #fi
  233. if [[ -x `which microk8s` ]]; then
  234. alias kubectl='microk8s kubectl'
  235. fi
  236. # May be incompatible with tf14+
  237. export TF_PLUGIN_CACHE_DIR=~/.terraform.d/plugin-cache
  238. [[ -d "$TF_PLUGIN_CACHE_DIR" ]] || mkdir -p $TF_PLUGIN_CACHE_DIR
  239. # Better colors
  240. export LSCOLORS="gxfxcxdxbxegedabagacad"
  241. # Disable bell for tab completion
  242. #bind 'set bell-style none'
  243. export EDITOR=vim
  244. # Import crowdstrike-specific settings
  245. [[ -f ~/.bashrc.crowdstrike ]] && source ~/.bashrc.crowdstrike
  246. alias activate='source env/bin/activate'
  247. echo ""
  248. echo "Reminder: Use command-shift-s to save your window arrangement, command-shift-r to restore."
  249. echo ""