.bashrc 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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 pip directory to path
  117. if [ -d /Users/fdamstra/Library/Python/3.10/bin ]; then
  118. export PATH=$PATH:/Users/fdamstra/Library/Python/3.10/bin
  119. fi
  120. # Add homebrew directories to the path
  121. if [ -d /opt/homebrew/bin ]; then
  122. export PATH=$PATH:/opt/homebrew/bin
  123. fi
  124. # Add scripts directories to the path
  125. if [ -d ~/scripts ]; then
  126. for D in ~/scripts/*; do
  127. export PATH=$PATH:$D
  128. done
  129. export PATH=$PATH:~/scripts
  130. fi
  131. # Add bin directories to the path
  132. if [ -d ~/bin ]; then
  133. export PATH=$PATH:~/bin
  134. fi
  135. # Add python bin directories to the path
  136. if [ -d ~/Library/Python/3.8/bin ]; then
  137. export PATH=$PATH:~/Library/Python/3.8/bin
  138. fi
  139. if [ -d ~/.chefdk/gem/ruby/2.6.0/bin ]; then
  140. export PATH=$PATH:~/.chefdk/gem/ruby/2.6.0/bin
  141. fi
  142. if [ -d ~/.local/bin ]; then
  143. export PATH=$PATH:~/.local/bin
  144. fi
  145. if [ -d ~/.gem/ruby/2.6.0/bin ]; then
  146. export PATH=$PATH:~/.gem/ruby/2.6.0/bin
  147. fi
  148. if [ -d ~/xdr-terraform-live/bin ]; then
  149. export PATH=$PATH:~/xdr-terraform-live/bin
  150. fi
  151. if [ -d ${KREW_ROOT:-$HOME/.krew}/bin ]; then
  152. export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
  153. fi
  154. if [ -d $HOME/.cargo ]; then
  155. . "$HOME/.cargo/env"
  156. fi
  157. # Add autocompletion for git
  158. source ~/.bash/git-completion.bash
  159. # Gitrob token
  160. [ -f ~/.git_token ] && source ~/.git_token
  161. # Add autocompletion for aws
  162. #[ -x /usr/local/bin/aws_completer ] && complete -C '/usr/local/bin/aws_completer' aws
  163. ## iTerm integration
  164. #[ -f ~/.iterm2_shell_integration.bash ] && source ~/.iterm2_shell_integration.bash
  165. # Additional possible paths
  166. [ -d /usr/local/heroku/bin ] && export PATH="/usr/local/heroku/bin:$PATH"
  167. [ -d $GOPATH/bin ] && export PATH="$GOPATH/bin:$PATH"
  168. [ -d ~/terraform ] && export PATH="~/terraform:$PATH"
  169. [ -d ~/esp/crosstool-NG/builds/xtensa-esp32-elf ] && export PATH="~/esp/crosstool-NG/builds/xtensa-esp32-elf:$PATH"
  170. # We want SSH keys to have passwords, so load the ssh agent
  171. SSH_ENV="$HOME/.ssh/environment"
  172. function start_agent {
  173. echo "Initialising new SSH agent..."
  174. /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
  175. echo succeeded
  176. chmod 600 "${SSH_ENV}"
  177. . "${SSH_ENV}" > /dev/null
  178. if [[ "$OSTYPE" == "darwin21" ]]; then
  179. /usr/bin/ssh-add --apple-load-keychain
  180. else
  181. /usr/bin/ssh-add
  182. fi
  183. }
  184. # Source SSH settings, if applicable
  185. if [ -f "${SSH_ENV}" ]; then
  186. . "${SSH_ENV}" > /dev/null
  187. #ps ${SSH_AGENT_PID} doesn't work under cywgin
  188. ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
  189. start_agent;
  190. }
  191. else
  192. start_agent;
  193. fi
  194. # Make less allow colors
  195. export LESS="-R"
  196. [ -f /opt/homebrew/bin/thefuck ] && eval $(/opt/homebrew/bin/thefuck --alias)
  197. # These are legacy
  198. #export ANSIBLE_INVENTORY=~/ansible/ansible_hosts
  199. #export ANSIBLE_HOST_KEY_CHECKING=False
  200. # Make sure vundle is installed
  201. [ -f ~/.vim/bundle/Vundle.vim/autoload/vundle.vim ] || git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
  202. [[ $(type -P fortune) ]] && [[ $(type -P cowsay) ]] && [[ $(type -P lolcat) ]] && fortune | cowsay | lolcat
  203. # tabtab source for serverless package
  204. # uninstall by removing these lines or running `tabtab uninstall serverless`
  205. [ -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
  206. # tabtab source for sls package
  207. # uninstall by removing these lines or running `tabtab uninstall sls`
  208. [ -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
  209. [ -f ~/MyEnvironment/iterm2_shell_integration.bash ] && . ~/MyEnvironment/iterm2_shell_integration.bash
  210. [ -f "`which chef`" ] && eval "$(chef shell-init bash)"
  211. # Python venv?
  212. if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
  213. if [ -f ~/awsinfo/scripts/awsinfo.bash ]; then
  214. alias awsinfo=~/awsinfo/scripts/awsinfo.bash
  215. fi
  216. alias python='python3'
  217. # WHen were passwords changed
  218. #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
  219. if [[ "$(uname -s)" == "Darwin" ]]; then
  220. # Print password expirations:
  221. echo
  222. echo -n Password Expiration:
  223. u=$(dscl . list /Users | egrep -v '^_|daemon|nobody|root')
  224. for i in $u; do
  225. printf \\n$i\\t;
  226. currentUser=$i;
  227. t=$(dscl . read /Users/"$currentUser" | grep -A1 passwordLastSetTime | grep real | awk -F'real>|</real' '{print $2}');
  228. t=$(echo "$t" | cut -f1 -d".");
  229. t=$(expr $t + 5184000);
  230. echo -n $(date -j -f "%s" "$t" 2> /dev/null);
  231. done;
  232. echo
  233. fi
  234. #if [[ -x `which bw` ]]; then
  235. # export LANG=en_CA.UTF-8;export LOCALE=en_CA.UTF-8; `which bw` slab
  236. #fi
  237. if [[ -x `which microk8s` ]]; then
  238. alias kubectl='microk8s kubectl'
  239. fi
  240. # May be incompatible with tf14+
  241. export TF_PLUGIN_CACHE_DIR=~/.terraform.d/plugin-cache
  242. [[ -d "$TF_PLUGIN_CACHE_DIR" ]] || mkdir -p $TF_PLUGIN_CACHE_DIR
  243. # Better colors
  244. export LSCOLORS="gxfxcxdxbxegedabagacad"
  245. # Disable bell for tab completion
  246. #bind 'set bell-style none'
  247. export EDITOR=vim
  248. # Import crowdstrike-specific settings
  249. [[ -f ~/.bashrc.crowdstrike ]] && source ~/.bashrc.crowdstrike
  250. alias activate='source env/bin/activate'
  251. echo ""
  252. echo "Reminder: Use command-shift-s to save your window arrangement, command-shift-r to restore."
  253. echo ""