.profile 7.3 KB

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