.profile 4.4 KB

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