.profile 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. ###############################################################################
  2. # Non-interactive shell configuration
  3. ###############################################################################
  4. OS=$(uname -s)
  5. # Add user-specific bin dirs to PATH
  6. export PATH="$PATH:$HOME/.local/bin:$HOME/bin"
  7. # Setup user-specific Python overrides
  8. if [ "$OS" = "Darwin" ]; then
  9. export PATH="$HOME/Library/Python/2.7/bin:$PATH:$HOME/bin"
  10. fi
  11. # Homebrew
  12. if [ "$OS" = "Darwin" ]; then
  13. export PATH="$PATH:$HOME/homebrew/bin"
  14. BREW_BIN=$(command -v brew 2>/dev/null)
  15. if [ "$BREW_BIN" ]; then
  16. BREW_PREFIX=$(brew --prefix)
  17. export HOMEBREW_CASK_OPTS="--appdir=$HOME/Applications --require-sha"
  18. export HOMEBREW_NO_INSECURE_REDIRECT=1
  19. fi
  20. fi
  21. # Default editor
  22. export EDITOR="vim"
  23. # Help things find Google Chrome
  24. if [ "$OS" = "Darwin" ]; then
  25. CHROME_BIN="$HOME/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
  26. ! [ -f "$CHROME_BIN" ] || export CHROME_BIN
  27. fi
  28. # Configure go lang
  29. if [ "$OS" = "Darwin" ]; then
  30. export GOROOT="$BREW_PREFIX/opt/go/libexec"
  31. else
  32. export GOROOT="$HOME/golang"
  33. fi
  34. export PATH="$PATH:$GOROOT/bin"
  35. export GOPATH="$HOME/go"
  36. export PATH="$PATH:$GOPATH/bin"
  37. # Configure less allow colors
  38. export LESS="-FRX"
  39. # If not running interactively, don't do anything else
  40. [ "$PS1" ] || return
  41. ###############################################################################
  42. # Interactive shell configuration
  43. ###############################################################################
  44. # tweak history behavior a bit
  45. HISTSIZE=50000
  46. if [ ! "$ZSH_VERSION" ]; then
  47. HISTFILESIZE=500000
  48. HISTCONTROL="ignoreboth"
  49. shopt -s histappend
  50. PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
  51. else
  52. SAVEHIST=500000
  53. # https://www.refining-linux.org/archives/49-ZSH-Gem-15-Shared-history.html
  54. setopt inc_append_history
  55. setopt share_history
  56. fi
  57. # check window size after each command
  58. if [ ! "$ZSH_VERSION" ]; then
  59. shopt -s checkwinsize
  60. fi
  61. # Custom shell aliases
  62. if [ "$OS" = "Darwin" ]; then
  63. export CLICOLOR=1
  64. else
  65. alias ls="ls --color=auto"
  66. alias pbcopy="xclip -selection clipboard"
  67. alias pbpaste="xclip -selection clipboard -o"
  68. fi
  69. alias la="ls -Fa"
  70. alias ll="ls -Fla"
  71. alias l="ls -FC"
  72. alias d="l"
  73. alias tree="tree -CF"
  74. alias grep="grep --color --exclude-dir={.svn,.git,node_modules}"
  75. alias node-print="node -p -e 'const [,f=\".\",e=\"this\"]=process.argv; (function(){ with(this) return eval(e); }).call(require(path.resolve(f)))'"
  76. alias ts-node-print="TS_NODE_FILES=true node -r ts-node/register -p -e 'const [,f=\".\",e=\"this\"]=process.argv; (function(){ with(this) return eval(e); }).call(require(path.resolve(f)))'"
  77. # color diffs
  78. ! command -v colordiff &>/dev/null || alias diff="colordiff"
  79. # color json
  80. ! command -v json &>/dev/null || alias json="json -o inspect"
  81. # MacVim shell aliases
  82. if [ "$OS" = "Darwin" ]; then
  83. alias gvim="mvim"
  84. fi
  85. # fancy shell prompts
  86. if [ "$ZSH_VERSION" ]; then
  87. ANTIGEN_DIR="$HOME/.antigen"
  88. [ -d "$ANTIGEN_DIR" ] || mkdir "$ANTIGEN_DIR"
  89. ANTIGEN_BIN="$ANTIGEN_DIR/antigen.zsh"
  90. [ -f "$ANTIGEN_BIN" ] || curl -L git.io/antigen > "$ANTIGEN_BIN"
  91. source "$ANTIGEN_BIN"
  92. BUNDLES=(
  93. zsh-users/zsh-syntax-highlighting
  94. mafredri/zsh-async
  95. sindresorhus/pure
  96. ael-code/zsh-colored-man-pages
  97. )
  98. for B in ${=BUNDLES}; do
  99. antigen bundle "$B"
  100. done
  101. antigen apply
  102. # use emacs-style for most defaults
  103. bindkey -e
  104. # jump more like bash did
  105. bindkey "^[f" vi-forward-word
  106. bindkey "^[b" vi-backward-word
  107. # editor
  108. autoload -z edit-command-line
  109. zle -N edit-command-line
  110. bindkey "^X^E" edit-command-line
  111. # enable completion menu
  112. zstyle ':completion:*' menu select
  113. # allow trailing slashes on ".."
  114. zstyle ':completion:*' special-dirs true
  115. # ensure proper ls-style colors in completion
  116. zstyle ':completion:*' list-colors 'di=34:ln=35:so=32:pi=33:ex=31:bd=46;34:cd=43;34:su=41;30:sg=46;30:tw=42;30:ow=43;30'
  117. else
  118. # tab completion FTW
  119. if [ "$OS" = "Darwin" ]; then
  120. F="$BREW_PREFIX/etc/bash_completion"; ! [ -f "$F" ] || source "$F"
  121. F="$(xcode-select -p)/usr/share/git-core/git-completion.$SHELL_NAME"; ! [ -f "$F" ] || source "$F"
  122. else
  123. F="/etc/bash_completion"; ! [ -f "$F" ] || source "$F"
  124. fi
  125. F="$HOME/.liquidprompt/liquidprompt"; ! [ -f "$F" ] || source "$F"
  126. fi
  127. # gimme gimme
  128. [ -d "$HOME/.gimme" ] || curl -fsSL "https://github.com/KylePDavis/gimme/raw/master/gimme" | bash -
  129. #F="$HOME/.gimme/gimme"; ! [ -f "$F" ] || source "$F"
  130. # The VS Code terminal needs a few tweaks
  131. if [ "$TERM_PROGRAM" = "vscode" ]; then
  132. # patch to restore some of the option as meta escape key in VS Code on Mac
  133. if [ "$ZSH_VERSION" ]; then
  134. bindkey "≥" insert-last-word
  135. fi
  136. # detect if in a fully resolved HOME path and cd back to the shorter version
  137. if [ "$PWD" != "$HOME" ]; then
  138. ABS_HOME="$(cd "$HOME" && pwd -P)"
  139. if [ "$ABS_HOME" != "$HOME" ]; then
  140. if [[ "$PWD" =~ $ABS_HOME* ]]; then
  141. cd "$HOME${PWD##$ABS_HOME}" || :
  142. fi
  143. fi
  144. fi
  145. fi