.profile 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. # help build tools find all the brew-based bits
  20. export CFLAGS="-I$BREW_PREFIX/include/"
  21. export CXXFLAGS="-I$BREW_PREFIX/include/"
  22. export LDFLAGS="-L$BREW_PREFIX/lib/"
  23. fi
  24. fi
  25. # Default editor
  26. export EDITOR="vim"
  27. # Help things find Google Chrome
  28. if [ "$OS" = "Darwin" ]; then
  29. CHROME_BIN="$HOME/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
  30. ! [ -f "$CHROME_BIN" ] || export CHROME_BIN
  31. fi
  32. # Configure go lang
  33. if [ "$OS" = "Darwin" ]; then
  34. export GOROOT="$BREW_PREFIX/opt/go/libexec"
  35. else
  36. export GOROOT="$HOME/golang"
  37. fi
  38. export PATH="$PATH:$GOROOT/bin"
  39. export GOPATH="$HOME/go"
  40. export PATH="$PATH:$GOPATH/bin"
  41. # Configure less allow colors
  42. export LESS="-FRX"
  43. # If not running interactively, don't do anything else
  44. [ "$PS1" ] || return
  45. ###############################################################################
  46. # Interactive shell configuration
  47. ###############################################################################
  48. # tweak history behavior a bit
  49. HISTSIZE=60000
  50. if [ ! "$ZSH_VERSION" ]; then
  51. HISTFILESIZE=50000
  52. HISTCONTROL="ignoreboth"
  53. shopt -s histappend
  54. PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
  55. else
  56. SAVEHIST=50000
  57. setopt HIST_EXPIRE_DUPS_FIRST
  58. # https://www.refining-linux.org/archives/49-ZSH-Gem-15-Shared-history.html
  59. setopt INC_APPEND_HISTORY
  60. setopt SHARE_HISTORY
  61. fi
  62. # check window size after each command
  63. if [ ! "$ZSH_VERSION" ]; then
  64. shopt -s checkwinsize
  65. fi
  66. # Custom shell aliases
  67. if [ "$OS" = "Darwin" ]; then
  68. export CLICOLOR=1
  69. else
  70. alias ls="ls --color=auto"
  71. alias pbcopy="xclip -selection clipboard"
  72. alias pbpaste="xclip -selection clipboard -o"
  73. fi
  74. alias la="ls -Fa"
  75. alias ll="ls -Fla"
  76. alias l="ls -FC"
  77. alias d="l"
  78. alias tree="tree -C -F"
  79. alias grep="grep --color --exclude-dir={.svn,.git,node_modules}"
  80. 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'
  81. alias vi=vim
  82. # aliases for node
  83. 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,e=>{console.error(e);process.exit(1)})'"
  84. alias node-print-json="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(o=>console.log(JSON.stringify(o,null,2)),e=>{console.error(e);process.exit(1)})'"
  85. alias node-print-deep="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(o=>console.log(require(\"util\").inspect(o,{depth:process.env.DEPTH||Infinity})),e=>{console.error(e);process.exit(1)})'"
  86. alias node-print-repl="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((r)=>(console.log(r,\`\n = \\\$1\`),repl.start().context.\$1=r),e=>{console.error(e);process.exit(1)})'"
  87. alias env-ts-node="TS_NODE_FILES=true NODE_OPTIONS=\"-r ts-node/register \$NODE_OPTIONS\""
  88. alias ts-node-print="env-ts-node node-print"
  89. # color diffs
  90. ! command -v colordiff >/dev/null || alias diff="colordiff"
  91. # color json
  92. ! command -v json >/dev/null || alias json="json -o inspect"
  93. # MacVim shell aliases
  94. if [ "$OS" = "Darwin" ]; then
  95. alias gvim="mvim"
  96. fi
  97. # fancy shell prompts
  98. if [ "$ZSH_VERSION" ]; then
  99. if [ "$OS" = "Darwin" ]; then
  100. # Enable zsh completions from brew
  101. ZSH_SITE_FUNC_DIR="$BREW_PREFIX/share/zsh/site-functions"
  102. FPATH="$ZSH_SITE_FUNC_DIR:$FPATH"
  103. # Auto fetch some community completions
  104. for ID in _yarn; do
  105. [ -f "$ZSH_SITE_FUNC_DIR/$ID" ] || curl -s -o "$ZSH_SITE_FUNC_DIR/$ID" "https://raw.githubusercontent.com/zsh-users/zsh-completions/master/src/$ID"
  106. done
  107. fi
  108. ANTIGEN_DIR="$HOME/.antigen"
  109. [ -d "$ANTIGEN_DIR" ] || mkdir "$ANTIGEN_DIR"
  110. ANTIGEN_BIN="$ANTIGEN_DIR/antigen.zsh"
  111. [ -f "$ANTIGEN_BIN" ] || curl -L git.io/antigen > "$ANTIGEN_BIN"
  112. source "$ANTIGEN_BIN"
  113. BUNDLES=(
  114. zsh-users/zsh-syntax-highlighting
  115. mafredri/zsh-async
  116. sindresorhus/pure@main
  117. )
  118. for B in ${=BUNDLES}; do
  119. antigen bundle "$B"
  120. done
  121. antigen apply
  122. # use emacs-style for most defaults
  123. bindkey -e
  124. # jump more like bash did
  125. bindkey "^[f" vi-forward-word
  126. bindkey "^[b" vi-backward-word
  127. # editor
  128. autoload -z edit-command-line
  129. zle -N edit-command-line
  130. bindkey "^X^E" edit-command-line
  131. # enable completion menu
  132. zstyle ':completion:*' menu select
  133. # allow trailing slashes on ".."
  134. zstyle ':completion:*' special-dirs true
  135. # ensure proper ls-style colors in completion
  136. 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'
  137. else
  138. # tab completion FTW
  139. if [ "$OS" = "Darwin" ]; then
  140. F="$BREW_PREFIX/etc/bash_completion"; ! [ -f "$F" ] || source "$F"
  141. F="$(xcode-select -p)/usr/share/git-core/git-completion.$SHELL_NAME"; ! [ -f "$F" ] || source "$F"
  142. else
  143. F="/etc/bash_completion"; ! [ -f "$F" ] || source "$F"
  144. fi
  145. F="$HOME/.liquidprompt/liquidprompt"; ! [ -f "$F" ] || source "$F"
  146. fi
  147. # gimme gimme
  148. [ -d "$HOME/.gimme" ] || curl -fsSL "https://github.com/KylePDavis/gimme/raw/master/gimme" | bash -
  149. #F="$HOME/.gimme/gimme"; ! [ -f "$F" ] || source "$F"
  150. # The VS Code terminal needs a few tweaks
  151. if [ "$TERM_PROGRAM" = "vscode" ]; then
  152. # patch to restore some of the option as meta escape key in VS Code on Mac
  153. if [ "$ZSH_VERSION" ]; then
  154. bindkey "≥" insert-last-word
  155. fi
  156. # detect if in a fully resolved HOME path and cd back to the shorter version
  157. if [ "$PWD" != "$HOME" ]; then
  158. ABS_HOME="$(cd "$HOME" && pwd -P)"
  159. if [ "$ABS_HOME" != "$HOME" ]; then
  160. if [[ "$PWD" =~ $ABS_HOME* ]]; then
  161. cd "$HOME${PWD##"$ABS_HOME"}" || :
  162. fi
  163. fi
  164. fi
  165. fi