.profile 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. # color diffs
  77. ! command -v colordiff &>/dev/null || alias diff="colordiff"
  78. # color json
  79. ! command -v json &>/dev/null || alias json="json -o inspect"
  80. # MacVim shell aliases
  81. if [ "$OS" = "Darwin" ]; then
  82. alias gvim="mvim"
  83. fi
  84. # fancy shell prompts
  85. if [ "$ZSH_VERSION" ]; then
  86. ANTIGEN_DIR="$HOME/.antigen"
  87. [ -d "$ANTIGEN_DIR" ] || mkdir "$ANTIGEN_DIR"
  88. ANTIGEN_BIN="$ANTIGEN_DIR/antigen.zsh"
  89. [ -f "$ANTIGEN_BIN" ] || curl -L git.io/antigen > "$ANTIGEN_BIN"
  90. source "$ANTIGEN_BIN"
  91. BUNDLES=(
  92. zsh-users/zsh-syntax-highlighting
  93. mafredri/zsh-async
  94. sindresorhus/pure
  95. ael-code/zsh-colored-man-pages
  96. )
  97. for B in ${=BUNDLES}; do
  98. antigen bundle "$B"
  99. done
  100. antigen apply
  101. # use emacs-style for most defaults
  102. bindkey -e
  103. # jump more like bash did
  104. bindkey "^[f" vi-forward-word
  105. bindkey "^[b" vi-backward-word
  106. # editor
  107. autoload -z edit-command-line
  108. zle -N edit-command-line
  109. bindkey "^X^E" edit-command-line
  110. # enable completion menu
  111. zstyle ':completion:*' menu select
  112. # allow trailing slashes on ".."
  113. zstyle ':completion:*' special-dirs true
  114. # ensure proper ls-style colors in completion
  115. 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'
  116. else
  117. # tab completion FTW
  118. if [ "$OS" = "Darwin" ]; then
  119. F="$BREW_PREFIX/etc/bash_completion"; ! [ -f "$F" ] || source "$F"
  120. F="$(xcode-select -p)/usr/share/git-core/git-completion.$SHELL_NAME"; ! [ -f "$F" ] || source "$F"
  121. else
  122. F="/etc/bash_completion"; ! [ -f "$F" ] || source "$F"
  123. fi
  124. F="$HOME/.liquidprompt/liquidprompt"; ! [ -f "$F" ] || source "$F"
  125. fi
  126. # gimme gimme
  127. [ -d "$HOME/.gimme" ] || curl -fsSL "https://github.com/KylePDavis/gimme/raw/master/gimme" | bash -
  128. #F="$HOME/.gimme/gimme"; ! [ -f "$F" ] || source "$F"
  129. # The VS Code terminal needs a few tweaks
  130. if [ "$TERM_PROGRAM" = "vscode" ]; then
  131. # patch to restore some of the option as meta escape key in VS Code on Mac
  132. if [ "$ZSH_VERSION" ]; then
  133. bindkey "≥" insert-last-word
  134. fi
  135. # detect if in a fully resolved HOME path and cd back to the shorter version
  136. if [ "$PWD" != "$HOME" ]; then
  137. ABS_HOME="$(cd "$HOME" && pwd -P)"
  138. if [ "$ABS_HOME" != "$HOME" ]; then
  139. if [[ "$PWD" =~ $ABS_HOME* ]]; then
  140. cd "$HOME${PWD##$ABS_HOME}" || :
  141. fi
  142. fi
  143. fi
  144. fi