.bashrc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. # Also do color ls
  54. export CLICOLOR=true
  55. else
  56. PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
  57. fi
  58. unset color_prompt force_color_prompt
  59. # If this is an xterm set the title to user@host:dir
  60. case "$TERM" in
  61. xterm*|rxvt*)
  62. PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
  63. ;;
  64. *)
  65. ;;
  66. esac
  67. # enable color support of ls and also add handy aliases
  68. if [ -x /usr/bin/dircolors ]; then
  69. test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
  70. alias ls='ls --color=auto'
  71. #alias dir='dir --color=auto'
  72. #alias vdir='vdir --color=auto'
  73. alias grep='grep --color=auto'
  74. alias fgrep='fgrep --color=auto'
  75. alias egrep='egrep --color=auto'
  76. fi
  77. # some more ls aliases
  78. alias ll='ls -alF'
  79. alias la='ls -A'
  80. alias l='ls -CF'
  81. # Add an "alert" alias for long running commands. Use like so:
  82. # sleep 10; alert
  83. 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$//'\'')"'
  84. # Alias definitions.
  85. # You may want to put all your additions into a separate file like
  86. # ~/.bash_aliases, instead of adding them here directly.
  87. # See /usr/share/doc/bash-doc/examples in the bash-doc package.
  88. if [ -f ~/.bash_aliases ]; then
  89. . ~/.bash_aliases
  90. fi
  91. # enable programmable completion features (you don't need to enable
  92. # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
  93. # sources /etc/bash.bashrc).
  94. if ! shopt -oq posix; then
  95. if [ -f /usr/share/bash-completion/bash_completion ]; then
  96. . /usr/share/bash-completion/bash_completion
  97. elif [ -f /etc/bash_completion ]; then
  98. . /etc/bash_completion
  99. fi
  100. fi
  101. export GOPATH=$HOME/go
  102. #export GOROOT=/usr/lib/go
  103. #export PATH=$PATH:$GOROOT/bin
  104. # Add scripts directories to the path
  105. if [ -d ~/scripts ]; then
  106. for D in ~/scripts/*; do
  107. export PATH=$PATH:$D
  108. done
  109. export PATH=$PATH:~/scripts
  110. fi
  111. # Add autocompletion for git
  112. source ~/.bash/git-completion.bash
  113. # Gitrob token
  114. [ -f ~/.git_token ] && source ~/.git_token
  115. # Add autocompletion for aws
  116. [ -x /usr/local/bin/aws_completer ] && complete -C '/usr/local/bin/aws_completer' aws
  117. ## iTerm integration
  118. #[ -f ~/.iterm2_shell_integration.bash ] && source ~/.iterm2_shell_integration.bash
  119. # Additional possible paths
  120. [ -d /usr/local/heroku/bin ] && export PATH="/usr/local/heroku/bin:$PATH"
  121. [ -d $GOPATH/bin ] && export PATH="$GOPATH/bin:$PATH"
  122. [ -d ~/terraform ] && export PATH="~/terraform:$PATH"
  123. [ -d ~/esp/crosstool-NG/builds/xtensa-esp32-elf ] && export PATH="~/esp/crosstool-NG/builds/xtensa-esp32-elf:$PATH"
  124. # We want SSH keys to have passwords, so load the ssh agent
  125. SSH_ENV="$HOME/.ssh/environment"
  126. function start_agent {
  127. echo "Initialising new SSH agent..."
  128. /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
  129. echo succeeded
  130. chmod 600 "${SSH_ENV}"
  131. . "${SSH_ENV}" > /dev/null
  132. /usr/bin/ssh-add;
  133. }
  134. # Source SSH settings, if applicable
  135. if [ -f "${SSH_ENV}" ]; then
  136. . "${SSH_ENV}" > /dev/null
  137. #ps ${SSH_AGENT_PID} doesn't work under cywgin
  138. ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
  139. start_agent;
  140. }
  141. else
  142. start_agent;
  143. fi
  144. # Make less allow colors
  145. export LESS="-R"
  146. eval $(thefuck --alias)
  147. export ANSIBLE_INVENTORY=~/ansible/ansible_hosts
  148. export ANSIBLE_HOST_KEY_CHECKING=False
  149. # Make sure vundle is installed
  150. [ -f ~/.vim/bundle/Vundle.vim/autoload/vundle.vim ] || git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
  151. [[ $(type -P fortune) ]] && [[ $(type -P cowsay) ]] && [[ $(type -P lolcat) ]] && fortune | cowsay | lolcat
  152. # tabtab source for serverless package
  153. # uninstall by removing these lines or running `tabtab uninstall serverless`
  154. [ -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
  155. # tabtab source for sls package
  156. # uninstall by removing these lines or running `tabtab uninstall sls`
  157. [ -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
  158. # Python venv?
  159. if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
  160. alias python='python3'