.bashrc 9.4 KB

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