.profile 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. # Configure go lang
  32. if [ "$OS" = "Darwin" ]; then
  33. export GOROOT="$BREW_PREFIX/opt/go/libexec"
  34. else
  35. export GOROOT="$HOME/golang"
  36. fi
  37. export PATH="$PATH:$GOROOT/bin"
  38. export GOPATH="$HOME/go"
  39. export PATH="$PATH:$GOPATH/bin"
  40. # Configure less allow colors
  41. export LESS="-FRX"
  42. # If not running interactively, don't do anything else
  43. [ "$PS1" ] || return
  44. ###############################################################################
  45. # Interactive shell configuration
  46. ###############################################################################
  47. # tweak history behavior a bit
  48. HISTSIZE=100000
  49. if [ ! "$ZSH_VERSION" ]; then
  50. HISTFILESIZE=$HISTSIZE
  51. HISTCONTROL="ignoreboth"
  52. shopt -s histappend
  53. PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
  54. else
  55. SAVEHIST=$HISTSIZE
  56. setopt SHARE_HISTORY
  57. setopt EXTENDED_HISTORY
  58. setopt HIST_EXPIRE_DUPS_FIRST
  59. setopt HIST_IGNORE_SPACE # ignore if leading space
  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 -C -F"
  74. alias grep="grep --color --exclude-dir={.svn,.git,node_modules}"
  75. 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'
  76. alias vi=vim
  77. # aliases for node
  78. 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)})'"
  79. 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)})'"
  80. 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)})'"
  81. 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)})'"
  82. 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)})'"
  83. alias env-ts-node="TS_NODE_FILES=true NODE_OPTIONS=\"-r ts-node/register \$NODE_OPTIONS\""
  84. alias ts-node-print="env-ts-node node-print"
  85. # color diffs
  86. ! command -v colordiff >/dev/null || alias diff="colordiff"
  87. # color json
  88. ! command -v json >/dev/null || alias json="json -o inspect"
  89. # color theme setup for bat (not aliased to cat directly because it's a bit slow)
  90. command -v bat >/dev/null || export BAT_THEME="$(defaults read -globalDomain AppleInterfaceStyle &> /dev/null && echo 'Visual Studio Dark+' || echo GitHub)"
  91. # fancy shell prompts
  92. if [ "$ZSH_VERSION" ]; then
  93. if [ "$OS" = "Darwin" ]; then
  94. # Enable zsh completions from brew
  95. ZSH_SITE_FUNC_DIR="$BREW_PREFIX/share/zsh/site-functions"
  96. FPATH="$ZSH_SITE_FUNC_DIR:$FPATH"
  97. # Auto fetch some community completions
  98. for ID in _yarn; do
  99. [ -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"
  100. done
  101. fi
  102. # use emacs-style for most defaults
  103. bindkey -e
  104. # jump more like bash did with Alt + Left/Right arrow
  105. bindkey "^[f" vi-forward-word
  106. bindkey "^[b" vi-backward-word
  107. # bindings for if you're not using Options as Meta key in Terminal (e.g., VSCode)
  108. bindkey "∑" vi-backward-kill-word # Alt + w
  109. bindkey "ƒ" vi-forward-word # Alt + f
  110. bindkey "∫" vi-backward-word # Alt + b
  111. bindkey "≥" insert-last-word # Alt + .
  112. # editor
  113. autoload -z edit-command-line
  114. zle -N edit-command-line
  115. bindkey "^X^E" edit-command-line
  116. # enable completion menu
  117. zstyle ':completion:*' menu select
  118. # allow trailing slashes on ".."
  119. zstyle ':completion:*' special-dirs true
  120. # enable inline comments since other shells allow it and sometimes they're nice to have
  121. setopt interactive_comments
  122. # ensure proper ls-style colors in completion
  123. 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'
  124. # setup zgenom and plugins for zsh
  125. ZGENOM_DIR="${HOME}/.zgenom"
  126. [ -d "$ZGENOM_DIR" ] || git clone https://github.com/jandamm/zgenom.git "$ZGENOM_DIR"
  127. source "$ZGENOM_DIR/zgenom.zsh"
  128. zgenom autoupdate
  129. if ! zgenom saved; then
  130. echo "Creating a zgenom save ..."
  131. zgenom loadall <<EOF
  132. sindresorhus/pure
  133. zsh-users/zsh-autosuggestions
  134. zsh-users/zsh-syntax-highlighting
  135. EOF
  136. zgenom save
  137. fi
  138. ZSH_AUTOSUGGEST_IGNORE_WIDGETS+=(backward-kill-word)
  139. else
  140. # check window size after each command
  141. shopt -s checkwinsize
  142. # tab completion FTW
  143. if [ "$OS" = "Darwin" ]; then
  144. F="$BREW_PREFIX/etc/bash_completion"; ! [ -f "$F" ] || source "$F"
  145. F="$(xcode-select -p)/usr/share/git-core/git-completion.$SHELL_NAME"; ! [ -f "$F" ] || source "$F"
  146. else
  147. F="/etc/bash_completion"; ! [ -f "$F" ] || source "$F"
  148. fi
  149. F="$HOME/.liquidprompt/liquidprompt"; ! [ -f "$F" ] || source "$F"
  150. fi
  151. # gimme gimme
  152. [ -d "$HOME/.gimme" ] || curl -fsSL "https://github.com/KylePDavis/gimme/raw/master/gimme" | bash -
  153. #F="$HOME/.gimme/gimme"; ! [ -f "$F" ] || source "$F"