.profile 5.2 KB

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