.profile 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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=60000
  46. if [ ! "$ZSH_VERSION" ]; then
  47. HISTFILESIZE=50000
  48. HISTCONTROL="ignoreboth"
  49. shopt -s histappend
  50. PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
  51. else
  52. SAVEHIST=50000
  53. setopt HIST_EXPIRE_DUPS_FIRST
  54. # https://www.refining-linux.org/archives/49-ZSH-Gem-15-Shared-history.html
  55. setopt INC_APPEND_HISTORY
  56. setopt SHARE_HISTORY
  57. fi
  58. # check window size after each command
  59. if [ ! "$ZSH_VERSION" ]; then
  60. shopt -s checkwinsize
  61. fi
  62. # Custom shell aliases
  63. if [ "$OS" = "Darwin" ]; then
  64. export CLICOLOR=1
  65. else
  66. alias ls="ls --color=auto"
  67. alias pbcopy="xclip -selection clipboard"
  68. alias pbpaste="xclip -selection clipboard -o"
  69. fi
  70. alias la="ls -Fa"
  71. alias ll="ls -Fla"
  72. alias l="ls -FC"
  73. alias d="l"
  74. alias tree="tree -C -F"
  75. alias grep="grep --color --exclude-dir={.svn,.git,node_modules}"
  76. alias man='LESS_TERMCAP_md=$(tput bold && tput setaf 4 || :) LESS_TERMCAP_me=$(tput sgr0 || :) LESS_TERMCAP_mb=$(tput blink || :) LESS_TERMCAP_us=$(tput setaf 2 || :) LESS_TERMCAP_ue=$(tput sgr0 || :) LESS_TERMCAP_so=$(tput smso || :) LESS_TERMCAP_se=$(tput rmso || :) PAGER="${commands[less]:-$PAGER}" man'
  77. alias node-print="node -e 'let [,f=\".\",e=\"this\"]=process.argv,ctx; try{ctx=require(f)}catch{ctx=require(path.resolve(f))}; eval(\`(async function(){ with(this) return (\${e}); })\`).call(ctx).then(console.log,console.error)'"
  78. alias ts-node-print="TS_NODE_FILES=true node -r ts-node/register -e 'let [,f=\".\",e=\"this\"]=process.argv,ctx; try{ctx=require(f)}catch{ctx=require(path.resolve(f))} eval(\`(async function(){ with(this) return (\${e}); })\`).call(ctx).then(console.log,console.error)'"
  79. alias vi=vim
  80. # color diffs
  81. ! command -v colordiff >/dev/null || alias diff="colordiff"
  82. # color json
  83. ! command -v json >/dev/null || alias json="json -o inspect"
  84. # MacVim shell aliases
  85. if [ "$OS" = "Darwin" ]; then
  86. alias gvim="mvim"
  87. fi
  88. # fancy shell prompts
  89. if [ "$ZSH_VERSION" ]; then
  90. ANTIGEN_DIR="$HOME/.antigen"
  91. [ -d "$ANTIGEN_DIR" ] || mkdir "$ANTIGEN_DIR"
  92. ANTIGEN_BIN="$ANTIGEN_DIR/antigen.zsh"
  93. [ -f "$ANTIGEN_BIN" ] || curl -L git.io/antigen > "$ANTIGEN_BIN"
  94. source "$ANTIGEN_BIN"
  95. BUNDLES=(
  96. zsh-users/zsh-syntax-highlighting
  97. mafredri/zsh-async
  98. sindresorhus/pure@main
  99. )
  100. for B in ${=BUNDLES}; do
  101. antigen bundle "$B"
  102. done
  103. antigen apply
  104. # use emacs-style for most defaults
  105. bindkey -e
  106. # jump more like bash did
  107. bindkey "^[f" vi-forward-word
  108. bindkey "^[b" vi-backward-word
  109. # editor
  110. autoload -z edit-command-line
  111. zle -N edit-command-line
  112. bindkey "^X^E" edit-command-line
  113. # enable completion menu
  114. zstyle ':completion:*' menu select
  115. # allow trailing slashes on ".."
  116. zstyle ':completion:*' special-dirs true
  117. # ensure proper ls-style colors in completion
  118. 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'
  119. else
  120. # tab completion FTW
  121. if [ "$OS" = "Darwin" ]; then
  122. F="$BREW_PREFIX/etc/bash_completion"; ! [ -f "$F" ] || source "$F"
  123. F="$(xcode-select -p)/usr/share/git-core/git-completion.$SHELL_NAME"; ! [ -f "$F" ] || source "$F"
  124. else
  125. F="/etc/bash_completion"; ! [ -f "$F" ] || source "$F"
  126. fi
  127. F="$HOME/.liquidprompt/liquidprompt"; ! [ -f "$F" ] || source "$F"
  128. fi
  129. # gimme gimme
  130. [ -d "$HOME/.gimme" ] || curl -fsSL "https://github.com/KylePDavis/gimme/raw/master/gimme" | bash -
  131. #F="$HOME/.gimme/gimme"; ! [ -f "$F" ] || source "$F"
  132. # The VS Code terminal needs a few tweaks
  133. if [ "$TERM_PROGRAM" = "vscode" ]; then
  134. # patch to restore some of the option as meta escape key in VS Code on Mac
  135. if [ "$ZSH_VERSION" ]; then
  136. bindkey "≥" insert-last-word
  137. fi
  138. # detect if in a fully resolved HOME path and cd back to the shorter version
  139. if [ "$PWD" != "$HOME" ]; then
  140. ABS_HOME="$(cd "$HOME" && pwd -P)"
  141. if [ "$ABS_HOME" != "$HOME" ]; then
  142. if [[ "$PWD" =~ $ABS_HOME* ]]; then
  143. cd "$HOME${PWD##$ABS_HOME}" || :
  144. fi
  145. fi
  146. fi
  147. fi