├── .gitignore ├── config ├── secrets.example ├── completions ├── zfz ├── locale ├── rbenv ├── hub ├── pyenv ├── bat ├── broot ├── starship ├── yarn ├── mcfly ├── platformio ├── path ├── atuin ├── golang ├── iterm2 ├── jenv ├── cdpath ├── library_path ├── rtx ├── colordiff ├── imagemagick ├── deno ├── settings ├── 1password ├── rust ├── thefuck ├── vscode ├── java ├── python ├── pnpm ├── funky ├── qt ├── main ├── android-sdk ├── mocha ├── bashmyaws ├── bun ├── gcloud ├── homebrew ├── exa ├── conda ├── nvm ├── gitconfig ├── aliases ├── zshrc-withcomments └── _git ├── README.md ├── scripts └── zz ├── zshrc └── git-completion.bash /.gitignore: -------------------------------------------------------------------------------- 1 | secrets 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /config/secrets.example: -------------------------------------------------------------------------------- 1 | export GH_TOKEN= 2 | -------------------------------------------------------------------------------- /config/completions: -------------------------------------------------------------------------------- 1 | fpath=(~/bin/completions $fpath) 2 | -------------------------------------------------------------------------------- /config/zfz: -------------------------------------------------------------------------------- 1 | test -f ~/.fzf.zsh && source ~/.fzf.zsh 2 | -------------------------------------------------------------------------------- /config/locale: -------------------------------------------------------------------------------- 1 | export LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 2 | -------------------------------------------------------------------------------- /config/rbenv: -------------------------------------------------------------------------------- 1 | test -d $HOME/.rbenv && eval "$(rbenv init -)" 2 | -------------------------------------------------------------------------------- /config/hub: -------------------------------------------------------------------------------- 1 | which hub > /dev/null 2>&1 && eval "$(hub alias -s)" 2 | -------------------------------------------------------------------------------- /config/pyenv: -------------------------------------------------------------------------------- 1 | test -x /usr/local/bin/pyenv && eval "$(pyenv init -)" 2 | -------------------------------------------------------------------------------- /config/bat: -------------------------------------------------------------------------------- 1 | if [ -x "$(which bat)" ]; then 2 | alias cat="bat" 3 | fi 4 | -------------------------------------------------------------------------------- /config/broot: -------------------------------------------------------------------------------- 1 | test -d ~/.config/broot && source ~/.config/broot/launcher/bash/br 2 | -------------------------------------------------------------------------------- /config/starship: -------------------------------------------------------------------------------- 1 | which starship >/dev/null 2>&1 && eval "$(starship init zsh)" 2 | -------------------------------------------------------------------------------- /config/yarn: -------------------------------------------------------------------------------- 1 | [ -d "$HOME/.yarn/bin" ] && export PATH="$HOME/.yarn/bin:$PATH" 2 | -------------------------------------------------------------------------------- /config/mcfly: -------------------------------------------------------------------------------- 1 | if [ -x "$(which mcfly)" ]; then 2 | eval "$(mcfly init zsh)" 3 | fi 4 | -------------------------------------------------------------------------------- /config/platformio: -------------------------------------------------------------------------------- 1 | test -d ~/.platformio && export PATH=$PATH:~/.platformio/penv/bin 2 | -------------------------------------------------------------------------------- /config/path: -------------------------------------------------------------------------------- 1 | if [ -x /usr/libexec/path_helper ]; then 2 | eval `/usr/libexec/path_helper -s` 3 | fi 4 | -------------------------------------------------------------------------------- /config/atuin: -------------------------------------------------------------------------------- 1 | which atuin > /dev/null 2>&1 && eval "$(atuin init zsh --disable-up-arrow --disable-ctrl-r)" 2 | -------------------------------------------------------------------------------- /config/golang: -------------------------------------------------------------------------------- 1 | export GOPATH="$HOME/gocode" 2 | export PATH=$PATH:/usr/local/opt/go/libexec/bin:$GOPATH/bin 3 | -------------------------------------------------------------------------------- /config/iterm2: -------------------------------------------------------------------------------- 1 | test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh" 2 | -------------------------------------------------------------------------------- /config/jenv: -------------------------------------------------------------------------------- 1 | if [ -d "$HOME/.jenv" ]; then 2 | export PATH="$HOME/.jenv/bin:$PATH" 3 | eval "$(jenv init -)" 4 | fi 5 | -------------------------------------------------------------------------------- /config/cdpath: -------------------------------------------------------------------------------- 1 | cdpath=($HOME/code 2 | $HOME/gocode/src/github.com/fcoury 3 | $HOME/gocode/src/github.com/gistia 4 | $HOME) 5 | -------------------------------------------------------------------------------- /config/library_path: -------------------------------------------------------------------------------- 1 | if [ -x "$(which brew)" ]; then 2 | export LIBRARY_PATH="$LIBRARY_PATH:$(brew --prefix)/lib" 3 | fi 4 | -------------------------------------------------------------------------------- /config/rtx: -------------------------------------------------------------------------------- 1 | rtx_path=$(which rtx 2>/dev/null) 2 | if test -x "$rtx_path"; then 3 | eval "$($rtx_path activate zsh)" 4 | fi 5 | -------------------------------------------------------------------------------- /config/colordiff: -------------------------------------------------------------------------------- 1 | if [ -x "$(which colordiff)" ]; then 2 | function diff { 3 | colordiff -u "$@" | less -RF 4 | } 5 | fi 6 | -------------------------------------------------------------------------------- /config/imagemagick: -------------------------------------------------------------------------------- 1 | if [ -d /usr/local/opt/imagemagick@6/bin ]; then 2 | export PATH="/usr/local/opt/imagemagick@6/bin:$PATH" 3 | fi 4 | -------------------------------------------------------------------------------- /config/deno: -------------------------------------------------------------------------------- 1 | export DENO_INSTALL="/Users/fcoury/.deno" 2 | 3 | if [ -d "$DENO_INSTALL" ]; then 4 | export PATH="$DENO_INSTALL/bin:$PATH" 5 | fi 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # .zsh 2 | 3 | My minimalist zsh configuration files 4 | 5 | ``` 6 | git clone git@github.com:fcoury/dotzsh.git .zsh 7 | ln -s .zsh/zshrc .zshrc 8 | ``` 9 | -------------------------------------------------------------------------------- /config/settings: -------------------------------------------------------------------------------- 1 | #export PAGER='' 2 | #export LESS="-X" 3 | export EDITOR=/opt/homebrew/bin/nvim 4 | export CLICOLOR=1 5 | #export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx 6 | -------------------------------------------------------------------------------- /config/1password: -------------------------------------------------------------------------------- 1 | if command -v op > /dev/null 2>&1; then 2 | if [ -f "$HOME/.config/op/plugins.sh" ]; then 3 | source "$HOME/.config/op/plugins.sh" 4 | fi 5 | fi 6 | -------------------------------------------------------------------------------- /config/rust: -------------------------------------------------------------------------------- 1 | [ -d "$HOME/.cargo/bin" ] && export PATH="$HOME/.cargo/bin:$PATH" 2 | [ -f "$HOME/.cargo/env" ] && source $HOME/.cargo/env 3 | [ -x `which sccache` ] && export RUSTC_WRAPPER=sccache 4 | -------------------------------------------------------------------------------- /config/thefuck: -------------------------------------------------------------------------------- 1 | if test -x /opt/homebrew/bin/thefuck; then 2 | # eval $(thefuck --alias --enable-experimental-instant-mode) 3 | THEFUCK_INSTANT_MODE=False 4 | eval $(thefuck --alias) 5 | fi 6 | -------------------------------------------------------------------------------- /config/vscode: -------------------------------------------------------------------------------- 1 | if [[ "$TERM_PROGRAM" == "vscode" ]]; then 2 | . /Applications/Visual\ Studio\ Code.app/Contents/Resources/app/out/vs/workbench/contrib/terminal/browser/media/shellIntegration-rc.zsh 3 | fi 4 | -------------------------------------------------------------------------------- /config/java: -------------------------------------------------------------------------------- 1 | if [ -x /usr/libexec/java_home ]; then 2 | JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_301` 3 | if [ -d "$JAVA_HOME" ]; then 4 | export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_301` 5 | fi 6 | fi 7 | -------------------------------------------------------------------------------- /config/python: -------------------------------------------------------------------------------- 1 | test -d /Users/fcoury/Library/Python/3.8 && export PATH=/Users/fcoury/Library/Python/3.8/bin:$PATH 2 | test -d /Users/fcoury/Library/Python/3.9 && export PATH=/Users/fcoury/Library/Python/3.9/bin:$PATH 3 | -------------------------------------------------------------------------------- /config/pnpm: -------------------------------------------------------------------------------- 1 | if [ -d /Users/fcoury/Library/pnpm ]; then 2 | export PNPM_HOME="/Users/fcoury/Library/pnpm" 3 | case ":$PATH:" in 4 | *":$PNPM_HOME:"*) ;; 5 | *) export PATH="$PNPM_HOME:$PATH" ;; 6 | esac 7 | fi 8 | -------------------------------------------------------------------------------- /config/funky: -------------------------------------------------------------------------------- 1 | test -f /usr/local/lib/python3.9/site-packages/scripts/shell/funky.sh && source /usr/local/lib/python3.9/site-packages/scripts/shell/funky.sh 2 | test -f /usr/local/lib/python3.9/site-packages/scripts/shell/funky.sh && alias fu=funky 3 | -------------------------------------------------------------------------------- /config/qt: -------------------------------------------------------------------------------- 1 | if [ -d /usr/local/opt/qt ]; then 2 | export PATH="/usr/local/opt/qt/bin:$PATH" 3 | export LDFLAGS="-L/usr/local/opt/qt/lib" 4 | export CPPFLAGS="-I/usr/local/opt/qt/include" 5 | export PKG_CONFIG_PATH="/usr/local/opt/qt/lib/pkgconfig" 6 | fi 7 | -------------------------------------------------------------------------------- /config/main: -------------------------------------------------------------------------------- 1 | setopt share_history # share command history data 2 | setopt HIST_IGNORE_SPACE 3 | setopt APPEND_HISTORY # write history only when closing 4 | setopt EXTENDED_HISTORY # add more info 5 | 6 | HISTFILE=~/.zsh_history 7 | SAVEHIST=10000 8 | HISTSIZE=10000 9 | -------------------------------------------------------------------------------- /config/android-sdk: -------------------------------------------------------------------------------- 1 | ANDROID_HOME=$HOME/Library/Android/sdk 2 | if [ -d "$ANDROID_HOME" ]; then 3 | export ANDROID_HOME=$HOME/Library/Android/sdk 4 | export PATH=$PATH:$ANDROID_HOME/tools 5 | export PATH=$PATH:$ANDROID_HOME/tools/bin 6 | export PATH=$PATH:$ANDROID_HOME/platform-tools 7 | fi 8 | -------------------------------------------------------------------------------- /config/mocha: -------------------------------------------------------------------------------- 1 | mocha() { 2 | if type whence &> /dev/null; then 3 | mocha=$(whence -p mocha) 4 | else 5 | mocha=$(type -P mocha) 6 | fi 7 | substitution='s/\x1b\[90m/\x1b[92m/g' 8 | 9 | $mocha -c "$@" > >(perl -pe "$substitution") 2> >(perl -pe "$substitution" 1>&2) 10 | } 11 | -------------------------------------------------------------------------------- /config/bashmyaws: -------------------------------------------------------------------------------- 1 | if test -d "$HOME/.bash-my-aws"; then 2 | export PATH="$PATH:$HOME/.bash-my-aws/bin" 3 | source ~/.bash-my-aws/aliases 4 | 5 | autoload -U +X compinit && compinit 6 | autoload -U +X bashcompinit && bashcompinit 7 | 8 | source ~/.bash-my-aws/bash_completion.sh 9 | fi 10 | -------------------------------------------------------------------------------- /config/bun: -------------------------------------------------------------------------------- 1 | export BUN_INSTALL="/Users/fcoury/.bun" 2 | 3 | if [ -d "$BUN_INSTALL" ]; then 4 | # bun completions 5 | [ -s "/Users/fcoury/.bun/_bun" ] && source "/Users/fcoury/.bun/_bun" 6 | 7 | # bun 8 | export BUN_INSTALL="$HOME/.bun" 9 | export PATH="$BUN_INSTALL/bin:$PATH" 10 | fi 11 | -------------------------------------------------------------------------------- /scripts/zz: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ZJ_SESSIONS=$(zellij list-sessions) 3 | NO_SESSIONS=$(echo "${ZJ_SESSIONS}" | wc -l) 4 | 5 | if [ "${NO_SESSIONS}" -ge 2 ]; then 6 | zellij attach \ 7 | "$(echo "${ZJ_SESSIONS}" | sk --ansi | awk '{print $1}')" 8 | else 9 | zellij attach -c 10 | fi 11 | -------------------------------------------------------------------------------- /config/gcloud: -------------------------------------------------------------------------------- 1 | # The next line updates PATH for the Google Cloud SDK. 2 | if [ -f "$HOME/Downloads/google-cloud-sdk/path.zsh.inc" ]; then . "$HOME/Downloads/google-cloud-sdk/path.zsh.inc"; fi 3 | 4 | # The next line enables shell command completion for gcloud. 5 | if [ -f "$HOME/Downloads/google-cloud-sdk/completion.zsh.inc" ]; then . "$HOME/Downloads/google-cloud-sdk/completion.zsh.inc"; fi 6 | -------------------------------------------------------------------------------- /config/homebrew: -------------------------------------------------------------------------------- 1 | export PATH="/usr/local/sbin:$PATH" 2 | test -d /opt/homebrew/bin && export PATH=/opt/homebrew/bin:/opt/homebrew/sbin:$PATH 3 | test -d /opt/homebrew/bin && export CPLUS_INCLUDE_PATH=/opt/homebrew/include 4 | 5 | if type brew &>/dev/null; then 6 | FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}" 7 | 8 | autoload -Uz compinit 9 | compinit 10 | fi 11 | -------------------------------------------------------------------------------- /config/exa: -------------------------------------------------------------------------------- 1 | unalias ls 2 | 3 | if [ -x "$(which eza)" ]; then 4 | ls() { 5 | # Check if the -rt flag is present 6 | if [[ $@ == *"-rt"* ]]; then 7 | # If the flag is present, replace it with -snew and pass the arguments to eza 8 | eza ${@//"-rt"/"-snew"} 9 | else 10 | # If the flag is not present, pass the arguments to eza as-is 11 | eza "$@" 12 | fi 13 | } 14 | fi 15 | -------------------------------------------------------------------------------- /config/conda: -------------------------------------------------------------------------------- 1 | initconda() { 2 | # >>> conda initialize >>> 3 | # !! Contents within this block are managed by 'conda init' !! 4 | __conda_setup="$('/Users/fcoury/opt/miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)" 5 | if [ $? -eq 0 ]; then 6 | eval "$__conda_setup" 7 | else 8 | if [ -f "/Users/fcoury/opt/miniconda3/etc/profile.d/conda.sh" ]; then 9 | . "/Users/fcoury/opt/miniconda3/etc/profile.d/conda.sh" 10 | else 11 | export PATH="/Users/fcoury/opt/miniconda3/bin:$PATH" 12 | fi 13 | fi 14 | unset __conda_setup 15 | # <<< conda initialize <<< 16 | } 17 | 18 | export PATH="/Users/fcoury/opt/miniconda3/bin:$PATH" 19 | -------------------------------------------------------------------------------- /config/nvm: -------------------------------------------------------------------------------- 1 | export NVM_DIR="$HOME/.nvm" 2 | 3 | if [ -d "$NVM_DIR" ]; then 4 | [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm 5 | 6 | autoload -U add-zsh-hook 7 | load-nvmrc() { 8 | local node_version="$(nvm version)" 9 | local nvmrc_path="$(nvm_find_nvmrc)" 10 | 11 | if [ -n "$nvmrc_path" ]; then 12 | local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")") 13 | 14 | if [ "$nvmrc_node_version" = "N/A" ]; then 15 | nvm install 16 | elif [ "$nvmrc_node_version" != "$node_version" ]; then 17 | nvm use 18 | fi 19 | elif [ "$node_version" != "$(nvm version default)" ]; then 20 | echo "Reverting to nvm default version" 21 | nvm use default 22 | fi 23 | } 24 | add-zsh-hook chpwd load-nvmrc 25 | load-nvmrc 26 | fi 27 | -------------------------------------------------------------------------------- /config/gitconfig: -------------------------------------------------------------------------------- 1 | [user] 2 | name = Felipe Coury 3 | email = felipe.coury@gmail.com 4 | signingKey = 29AFDC56A8469F3AF21A89A5F577F79FA4872E03 5 | [github] 6 | user = fcoury 7 | [core] 8 | ; editor = code --wait 9 | editor = /opt/homebrew/bin/nvim 10 | pager = delta 11 | [color] 12 | ui = true 13 | [push] 14 | default = simple 15 | autoSetupRemote = true 16 | [pull] 17 | rebase = false 18 | [alias] 19 | st = status -sb 20 | co = checkout 21 | [credential] 22 | helper = 23 | helper = /usr/local/share/gcm-core/git-credential-manager 24 | [credential "https://dev.azure.com"] 25 | useHttpPath = true 26 | [filter "lfs"] 27 | process = git-lfs filter-process 28 | required = true 29 | clean = git-lfs clean -- %f 30 | smudge = git-lfs smudge -- %f 31 | [commit] 32 | gpgSign = true 33 | [tag] 34 | forceSignAnnotated = true 35 | [gpg] 36 | format = openpgp 37 | program = /opt/homebrew/bin/gpg 38 | -------------------------------------------------------------------------------- /zshrc: -------------------------------------------------------------------------------- 1 | export ZSH=$HOME/.oh-my-zsh 2 | # ZSH_THEME="bureau" 3 | 4 | # Display red dots whilst waiting for completion. 5 | COMPLETION_WAITING_DOTS="true" 6 | 7 | # Disables compfix, preventing "Insecure completion-dependent directories detected" 8 | ZSH_DISABLE_COMPFIX=true 9 | 10 | # Execution time stamp shown in the history command output. 11 | HIST_STAMPS="yyyy-mm-dd" 12 | 13 | # User configuration 14 | 15 | export PATH="$HOME/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$HOME/.zsh/scripts:$PATH" 16 | source $ZSH/oh-my-zsh.sh 17 | 18 | ### User loaders section 19 | 20 | source ~/.zsh/config/locale 21 | source ~/.zsh/config/cdpath 22 | source ~/.zsh/config/aliases 23 | source ~/.zsh/config/settings 24 | source ~/.zsh/config/iterm2 25 | source ~/.zsh/config/path 26 | source ~/.zsh/config/hub 27 | source ~/.zsh/config/python 28 | source ~/.zsh/config/nvm 29 | source ~/.zsh/config/golang 30 | source ~/.zsh/config/bun 31 | source ~/.zsh/config/homebrew 32 | source ~/.zsh/config/rust 33 | source ~/.zsh/config/colordiff 34 | source ~/.zsh/config/vscode 35 | source ~/.zsh/config/jenv 36 | source ~/.zsh/config/exa 37 | source ~/.zsh/config/bat 38 | source ~/.zsh/config/deno 39 | source ~/.zsh/config/yarn 40 | source ~/.zsh/config/rtx 41 | source ~/.zsh/config/atuin 42 | source ~/.zsh/config/pnpm 43 | source ~/.zsh/config/thefuck 44 | source ~/.zsh/config/library_path 45 | source ~/.zsh/config/1password 46 | source ~/.zsh/config/rust 47 | test -f ~/.zsh/secrets && source ~/.zsh/secrets 48 | 49 | # source ~/.zsh/config/zellij # loads zellij automatically 50 | # source ~/.zsh/mcfly 51 | # source ~/.zsh/imagemagick 52 | # source ~/.zsh/rbenv 53 | # source ~/.zsh/bashmyaws 54 | # source ~/.zsh/qt 55 | # source ~/.zsh/pyenv 56 | # source ~/.zsh/broot 57 | # source ~/.zsh/funky 58 | # source ~/.zsh/zfz 59 | # source ~/.zsh/python 60 | # source ~/.zsh/java 61 | # source ~/.zsh/android-sdk 62 | # source ~/.zsh/completions 63 | # test -d /Users/fcoury/opt/miniconda3 && source ~/.zsh/conda 64 | # test -f ~/.iterm2_shell_integration.zh && source ~/.iterm2_shell_integration.zsh 65 | 66 | # Plugins 67 | # plugins=(docker zsh-syntax-highlighting zsh-nvm-auto-switch) 68 | # plugins=(zsh-nvm-auto-switch zsh-autosuggestions zsh-syntax-highlighting) 69 | 70 | # Load Git completion 71 | zstyle ':completion:*:*:git:*' script ~/.zsh/git-completion.bash 72 | fpath=(~/.zsh $fpath) 73 | 74 | autoload -Uz compinit && compinit 75 | 76 | ### Starship prompt 77 | 78 | eval "$(starship init zsh)" 79 | 80 | plugins=(zsh-nvm-auto-switch zsh-autosuggestions zsh-syntax-highlighting) 81 | -------------------------------------------------------------------------------- /config/aliases: -------------------------------------------------------------------------------- 1 | edng() { 2 | atom "~/ng-book2/manuscript/code/$*" 3 | } 4 | 5 | rl() { 6 | sed -i '' -e "${1}d" $HOME/.ssh/known_hosts 7 | } 8 | 9 | syncall() { 10 | folders=( 11 | 'config' 'workflow-engine' 'page-builder' 'page-builder-interface' 12 | 'case-management' 'mongodb-promise' 'providers' 13 | ) 14 | 15 | for i in $folders; do 16 | cd "$HOME/code/$i" 17 | hub sync 18 | done 19 | } 20 | 21 | rename() { 22 | for i in $1* 23 | do 24 | mv "$i" "${i/$1/$2}" 25 | done 26 | } 27 | 28 | initconda() { 29 | # >>> conda initialize >>> 30 | # !! Contents within this block are managed by 'conda init' !! 31 | __conda_setup="$('/Users/fcoury/opt/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)" 32 | if [ $? -eq 0 ]; then 33 | eval "$__conda_setup" 34 | else 35 | if [ -f "/Users/fcoury/opt/anaconda3/etc/profile.d/conda.sh" ]; then 36 | . "/Users/fcoury/opt/anaconda3/etc/profile.d/conda.sh" 37 | else 38 | export PATH="/Users/fcoury/opt/anaconda3/bin:$PATH" 39 | fi 40 | fi 41 | unset __conda_setup 42 | # <<< conda initialize <<< 43 | } 44 | 45 | alias r='bin/rails' 46 | alias be='bundle exec' 47 | alias gl="git log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" 48 | alias gp='git pull' 49 | alias gps='git push' 50 | alias gs='git status' 51 | # alias grb='DEFBRANCH=`git defbranch` && git co "$DEFBRANCH" && git pull && git branch --merged "$DEFBRANCH" | grep -v "\* $DEFBRANCH" | grep -v master | xargs -n 1 git branch -d' 52 | alias gpr='hub pull-request|xargs open' 53 | alias gtr='git track' 54 | alias gap='git add -p' 55 | 56 | alias tv='tidy-viewer' 57 | alias vi='nvim' 58 | alias vim='nvim' 59 | 60 | alias vivi='cd ~/.config/nvim/lua/user && nvim' 61 | 62 | # MSuite 63 | mc() { 64 | dir="$1" 65 | if [ -z "$1" ]; then 66 | dir=`pwd` 67 | fi 68 | 69 | # Store the current directory 70 | local prev_dir=$(pwd) 71 | 72 | # Use trap to ensure we change back to the previous directory 73 | # upon any signal or normal exit. 74 | trap "cd $prev_dir" EXIT 75 | 76 | cd /Users/fcoury/code/msuite.workspace/msuite 77 | cargo run -- -d config --env-file "${dir}/.env" --path "${dir}" --watch 78 | 79 | # Since we used trap, this line is not strictly necessary, 80 | # but it's good to leave it for clarity. 81 | cd $prev_dir 82 | } 83 | 84 | tt() { 85 | dir=`pwd` 86 | test="$1" 87 | if [ -z "$1" ]; then 88 | test="." 89 | fi 90 | 91 | # Store the current directory 92 | local prev_dir=$(pwd) 93 | 94 | # Use trap to ensure we change back to the previous directory 95 | # upon any signal or normal exit. 96 | trap "cd $prev_dir" EXIT SIGINT 97 | 98 | cd /Users/fcoury/code/msuite.workspace/msuite 99 | cargo watch -x 'run -- config --path '"${dir}"' --env-file '"${dir}/.env"' test '"${dir}/$1"' --watch' 100 | 101 | # Since we used trap, this line is not strictly necessary, 102 | # but it's good to leave it for clarity. 103 | cd $prev_dir 104 | } 105 | -------------------------------------------------------------------------------- /config/zshrc-withcomments: -------------------------------------------------------------------------------- 1 | # Path to your oh-my-zsh installation. 2 | export ZSH=$HOME/.oh-my-zsh 3 | 4 | # Set name of the theme to load. 5 | # Look in ~/.oh-my-zsh/themes/ 6 | # Optionally, if you set this to "random", it'll load a random theme each 7 | # time that oh-my-zsh is loaded. 8 | # ZSH_THEME="robbyrussell" 9 | ZSH_THEME="bureau" 10 | # ZSH_THEME="felipe" 11 | 12 | # Uncomment the following line to use case-sensitive completion. 13 | # CASE_SENSITIVE="true" 14 | 15 | # Uncomment the following line to use hyphen-insensitive completion. Case 16 | # sensitive completion must be off. _ and - will be interchangeable. 17 | # HYPHEN_INSENSITIVE="true" 18 | 19 | # Uncomment the following line to disable bi-weekly auto-update checks. 20 | # DISABLE_AUTO_UPDATE="true" 21 | 22 | # Uncomment the following line to change how often to auto-update (in days). 23 | # export UPDATE_ZSH_DAYS=13 24 | 25 | # Uncomment the following line to disable colors in ls. 26 | # DISABLE_LS_COLORS="true" 27 | 28 | # Uncomment the following line to disable auto-setting terminal title. 29 | # DISABLE_AUTO_TITLE="true" 30 | 31 | # Uncomment the following line to enable command auto-correction. 32 | # ENABLE_CORRECTION="true" 33 | 34 | # Uncomment the following line to display red dots whilst waiting for completion. 35 | COMPLETION_WAITING_DOTS="true" 36 | 37 | # Uncomment the following line if you want to disable marking untracked files 38 | # under VCS as dirty. This makes repository status check for large repositories 39 | # much, much faster. 40 | # DISABLE_UNTRACKED_FILES_DIRTY="true" 41 | 42 | # Disables compfix, preventing "Insecure completion-dependent directories detected" 43 | ZSH_DISABLE_COMPFIX=true 44 | 45 | # Uncomment the following line if you want to change the command execution time 46 | # stamp shown in the history command output. 47 | # The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd" 48 | # HIST_STAMPS="mm/dd/yyyy" 49 | 50 | # Would you like to use another custom folder than $ZSH/custom? 51 | # ZSH_CUSTOM=/path/to/new-custom-folder 52 | 53 | # Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*) 54 | # Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/ 55 | # Example format: plugins=(rails git textmate ruby lighthouse) 56 | # Add wisely, as too many plugins slow down shell startup. 57 | source ~/.zsh/nvm 58 | plugins=(docker zsh-syntax-highlighting zsh-nvm-auto-switch) 59 | 60 | # User configuration 61 | 62 | export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$HOME/.zsh/bin" 63 | # export MANPATH="/usr/local/man:$MANPATH" 64 | 65 | source $ZSH/oh-my-zsh.sh 66 | 67 | # You may need to manually set your language environment 68 | # export LANG=en_US.UTF-8 69 | 70 | # Preferred editor for local and remote sessions 71 | # if [[ -n $SSH_CONNECTION ]]; then 72 | # export EDITOR='vim' 73 | # else 74 | # export EDITOR='mvim' 75 | # fi 76 | 77 | # Compilation flags 78 | # export ARCHFLAGS="-arch x86_64" 79 | 80 | # ssh 81 | # export SSH_KEY_PATH="~/.ssh/dsa_id" 82 | 83 | # Set personal aliases, overriding those provided by oh-my-zsh libs, 84 | # plugins, and themes. Aliases can be placed here, though oh-my-zsh 85 | # users are encouraged to define aliases within the ZSH_CUSTOM folder. 86 | # For a full list of active aliases, run `alias`. 87 | # 88 | # Example aliases 89 | # alias zshconfig="mate ~/.zshrc" 90 | # alias ohmyzsh="mate ~/.oh-my-zsh" 91 | 92 | ### User specific section 93 | source ~/.zsh/cdpath 94 | source ~/.zsh/golang 95 | source ~/.zsh/rbenv 96 | source ~/.zsh/aliases 97 | source ~/.zsh/settings 98 | source ~/.zsh/iterm2 99 | source ~/.zsh/imagemagick 100 | #source ~/.zsh/1pass 101 | source ~/.zsh/nvm 102 | source ~/.zsh/path 103 | source ~/.zsh/bashmyaws 104 | source ~/.zsh/rust 105 | source ~/.zsh/qt 106 | source ~/.zsh/pyenv 107 | test -f ~/.zsh/secrets && source ~/.zsh/secrets 108 | test -f ~/.iterm2_shell_integration.zh && source ~/.iterm2_shell_integration.zsh 109 | source ~/.zsh/homebrew 110 | source ~/.zsh/broot 111 | source ~/.zsh/funky 112 | source ~/.zsh/zfz 113 | source ~/.zsh/hub 114 | source ~/.zsh/python 115 | source ~/.zsh/java 116 | source ~/.zsh/android-sdk 117 | source ~/.zsh/thefuck 118 | # source ~/.zsh/completions 119 | #test -d /Users/fcoury/opt/miniconda3 && source ~/.zsh/conda 120 | 121 | # [[ -s "$HOME/.avn/bin/avn.sh" ]] && source "$HOME/.avn/bin/avn.sh" # load avn 122 | # autoload -U +X bashcompinit && bashcompinit 123 | # complete -o nospace -C /usr/local/bin/bitcomplete bit 124 | # autoload -U +X bashcompinit && bashcompinit 125 | # complete -o nospace -C /usr/local/bin/bit bit 126 | 127 | # Load Git completion 128 | zstyle ':completion:*:*:git:*' script ~/.zsh/git-completion.bash 129 | fpath=(~/.zsh $fpath) 130 | 131 | autoload -Uz compinit && compinit 132 | 133 | eval "$(starship init zsh)" 134 | -------------------------------------------------------------------------------- /config/_git: -------------------------------------------------------------------------------- 1 | #compdef git gitk 2 | 3 | # zsh completion wrapper for git 4 | # 5 | # Copyright (c) 2012-2020 Felipe Contreras 6 | # 7 | # The recommended way to install this script is to make a copy of it as a 8 | # file named '_git' inside any directory in your fpath. 9 | # 10 | # For example, create a directory '~/.zsh/', copy this file to '~/.zsh/_git', 11 | # and then add the following to your ~/.zshrc file: 12 | # 13 | # fpath=(~/.zsh $fpath) 14 | # 15 | # You need git's bash completion script installed. By default bash-completion's 16 | # location will be used (e.g. pkg-config --variable=completionsdir bash-completion). 17 | # 18 | # If your bash completion script is somewhere else, you can specify the 19 | # location in your ~/.zshrc: 20 | # 21 | # zstyle ':completion:*:*:git:*' script ~/.git-completion.bash 22 | # 23 | 24 | zstyle -T ':completion:*:*:git:*' tag-order && \ 25 | zstyle ':completion:*:*:git:*' tag-order 'common-commands' 26 | 27 | zstyle -s ":completion:*:*:git:*" script script 28 | if [ -z "$script" ]; then 29 | local -a locations 30 | local e bash_completion 31 | 32 | bash_completion=$(pkg-config --variable=completionsdir bash-completion 2>/dev/null) || 33 | bash_completion='/usr/share/bash-completion/completions/' 34 | 35 | locations=( 36 | "$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash 37 | "$HOME/.local/share/bash-completion/completions/git" 38 | "$bash_completion/git" 39 | '/etc/bash_completion.d/git' # old debian 40 | ) 41 | for e in $locations; do 42 | test -f $e && script="$e" && break 43 | done 44 | fi 45 | 46 | local old_complete="$functions[complete]" 47 | functions[complete]=: 48 | GIT_SOURCING_ZSH_COMPLETION=y . "$script" 49 | functions[complete]="$old_complete" 50 | 51 | __gitcomp () 52 | { 53 | emulate -L zsh 54 | 55 | local cur_="${3-$cur}" 56 | 57 | case "$cur_" in 58 | --*=) 59 | ;; 60 | --no-*) 61 | local c IFS=$' \t\n' 62 | local -a array 63 | for c in ${=1}; do 64 | if [[ $c == "--" ]]; then 65 | continue 66 | fi 67 | c="$c${4-}" 68 | case $c in 69 | --*=|*.) ;; 70 | *) c="$c " ;; 71 | esac 72 | array+=("$c") 73 | done 74 | compset -P '*[=:]' 75 | compadd -Q -S '' -p "${2-}" -a -- array && _ret=0 76 | ;; 77 | *) 78 | local c IFS=$' \t\n' 79 | local -a array 80 | for c in ${=1}; do 81 | if [[ $c == "--" ]]; then 82 | c="--no-...${4-}" 83 | array+=("$c ") 84 | break 85 | fi 86 | c="$c${4-}" 87 | case $c in 88 | --*=|*.) ;; 89 | *) c="$c " ;; 90 | esac 91 | array+=("$c") 92 | done 93 | compset -P '*[=:]' 94 | compadd -Q -S '' -p "${2-}" -a -- array && _ret=0 95 | ;; 96 | esac 97 | } 98 | 99 | __gitcomp_direct () 100 | { 101 | emulate -L zsh 102 | 103 | compset -P '*[=:]' 104 | compadd -Q -S '' -- ${(f)1} && _ret=0 105 | } 106 | 107 | __gitcomp_nl () 108 | { 109 | emulate -L zsh 110 | 111 | compset -P '*[=:]' 112 | compadd -Q -S "${4- }" -p "${2-}" -- ${(f)1} && _ret=0 113 | } 114 | 115 | __gitcomp_file () 116 | { 117 | emulate -L zsh 118 | 119 | compset -P '*[=:]' 120 | compadd -f -p "${2-}" -- ${(f)1} && _ret=0 121 | } 122 | 123 | __gitcomp_direct_append () 124 | { 125 | __gitcomp_direct "$@" 126 | } 127 | 128 | __gitcomp_nl_append () 129 | { 130 | __gitcomp_nl "$@" 131 | } 132 | 133 | __gitcomp_file_direct () 134 | { 135 | __gitcomp_file "$1" "" 136 | } 137 | 138 | _git_zsh () 139 | { 140 | __gitcomp "v1.1" 141 | } 142 | 143 | __git_complete_command () 144 | { 145 | emulate -L zsh 146 | 147 | local command="$1" 148 | local completion_func="_git_${command//-/_}" 149 | if (( $+functions[$completion_func] )); then 150 | emulate ksh -c $completion_func 151 | return 0 152 | else 153 | return 1 154 | fi 155 | } 156 | 157 | __git_zsh_bash_func () 158 | { 159 | emulate -L ksh 160 | 161 | local command=$1 162 | 163 | __git_complete_command "$command" && return 164 | 165 | local expansion=$(__git_aliased_command "$command") 166 | if [ -n "$expansion" ]; then 167 | words[1]=$expansion 168 | __git_complete_command "$expansion" 169 | fi 170 | } 171 | 172 | __git_zsh_cmd_common () 173 | { 174 | local -a list 175 | list=( 176 | add:'add file contents to the index' 177 | bisect:'find by binary search the change that introduced a bug' 178 | branch:'list, create, or delete branches' 179 | checkout:'checkout a branch or paths to the working tree' 180 | clone:'clone a repository into a new directory' 181 | commit:'record changes to the repository' 182 | diff:'show changes between commits, commit and working tree, etc' 183 | fetch:'download objects and refs from another repository' 184 | grep:'print lines matching a pattern' 185 | init:'create an empty Git repository or reinitialize an existing one' 186 | log:'show commit logs' 187 | merge:'join two or more development histories together' 188 | mv:'move or rename a file, a directory, or a symlink' 189 | pull:'fetch from and merge with another repository or a local branch' 190 | push:'update remote refs along with associated objects' 191 | rebase:'forward-port local commits to the updated upstream head' 192 | reset:'reset current HEAD to the specified state' 193 | restore:'restore working tree files' 194 | rm:'remove files from the working tree and from the index' 195 | show:'show various types of objects' 196 | status:'show the working tree status' 197 | switch:'switch branches' 198 | tag:'create, list, delete or verify a tag object signed with GPG') 199 | _describe -t common-commands 'common commands' list && _ret=0 200 | } 201 | 202 | __git_zsh_cmd_alias () 203 | { 204 | local -a list 205 | list=(${${(0)"$(git config -z --get-regexp '^alias\.*')"}#alias.}) 206 | list=(${(f)"$(printf "%s:alias for '%s'\n" ${(f@)list})"}) 207 | _describe -t alias-commands 'aliases' list && _ret=0 208 | } 209 | 210 | __git_zsh_cmd_all () 211 | { 212 | local -a list 213 | emulate ksh -c __git_compute_all_commands 214 | list=( ${=__git_all_commands} ) 215 | _describe -t all-commands 'all commands' list && _ret=0 216 | } 217 | 218 | __git_zsh_main () 219 | { 220 | local curcontext="$curcontext" state state_descr line 221 | typeset -A opt_args 222 | local -a orig_words 223 | 224 | orig_words=( ${words[@]} ) 225 | 226 | _arguments -C \ 227 | '(-p --paginate --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \ 228 | '(-p --paginate)--no-pager[do not pipe git output into a pager]' \ 229 | '--git-dir=-[set the path to the repository]: :_directories' \ 230 | '--bare[treat the repository as a bare repository]' \ 231 | '(- :)--version[prints the git suite version]' \ 232 | '--exec-path=-[path to where your core git programs are installed]:: :_directories' \ 233 | '--html-path[print the path where git''s HTML documentation is installed]' \ 234 | '--info-path[print the path where the Info files are installed]' \ 235 | '--man-path[print the manpath (see `man(1)`) for the man pages]' \ 236 | '--work-tree=-[set the path to the working tree]: :_directories' \ 237 | '--namespace=-[set the git namespace]' \ 238 | '--no-replace-objects[do not use replacement refs to replace git objects]' \ 239 | '(- :)--help[prints the synopsis and a list of the most commonly used commands]: :->arg' \ 240 | '(-): :->command' \ 241 | '(-)*:: :->arg' && return 242 | 243 | case $state in 244 | (command) 245 | _tags common-commands alias-commands all-commands 246 | while _tags; do 247 | _requested common-commands && __git_zsh_cmd_common 248 | _requested alias-commands && __git_zsh_cmd_alias 249 | _requested all-commands && __git_zsh_cmd_all 250 | let _ret || break 251 | done 252 | ;; 253 | (arg) 254 | local command="${words[1]}" __git_dir __git_cmd_idx=1 255 | 256 | if (( $+opt_args[--bare] )); then 257 | __git_dir='.' 258 | else 259 | __git_dir=${opt_args[--git-dir]} 260 | fi 261 | 262 | (( $+opt_args[--help] )) && command='help' 263 | 264 | words=( ${orig_words[@]} ) 265 | 266 | __git_zsh_bash_func $command 267 | ;; 268 | esac 269 | } 270 | 271 | _git () 272 | { 273 | local _ret=1 274 | local cur cword prev 275 | 276 | cur=${words[CURRENT]} 277 | prev=${words[CURRENT-1]} 278 | let cword=CURRENT-1 279 | 280 | if (( $+functions[__${service}_zsh_main] )); then 281 | __${service}_zsh_main 282 | elif (( $+functions[__${service}_main] )); then 283 | emulate ksh -c __${service}_main 284 | elif (( $+functions[_${service}] )); then 285 | emulate ksh -c _${service} 286 | elif (( $+functions[_${service//-/_}] )); then 287 | emulate ksh -c _${service//-/_} 288 | fi 289 | 290 | let _ret && _default && _ret=0 291 | return _ret 292 | } 293 | 294 | _git 295 | -------------------------------------------------------------------------------- /git-completion.bash: -------------------------------------------------------------------------------- 1 | # bash/zsh completion support for core Git. 2 | # 3 | # Copyright (C) 2006,2007 Shawn O. Pearce 4 | # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/). 5 | # Distributed under the GNU General Public License, version 2.0. 6 | # 7 | # The contained completion routines provide support for completing: 8 | # 9 | # *) local and remote branch names 10 | # *) local and remote tag names 11 | # *) .git/remotes file names 12 | # *) git 'subcommands' 13 | # *) git email aliases for git-send-email 14 | # *) tree paths within 'ref:path/to/file' expressions 15 | # *) file paths within current working directory and index 16 | # *) common --long-options 17 | # 18 | # To use these routines: 19 | # 20 | # 1) Copy this file to somewhere (e.g. ~/.git-completion.bash). 21 | # 2) Add the following line to your .bashrc/.zshrc: 22 | # source ~/.git-completion.bash 23 | # 3) Consider changing your PS1 to also show the current branch, 24 | # see git-prompt.sh for details. 25 | # 26 | # If you use complex aliases of form '!f() { ... }; f', you can use the null 27 | # command ':' as the first command in the function body to declare the desired 28 | # completion style. For example '!f() { : git commit ; ... }; f' will 29 | # tell the completion to use commit completion. This also works with aliases 30 | # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '". 31 | # 32 | # If you have a command that is not part of git, but you would still 33 | # like completion, you can use __git_complete: 34 | # 35 | # __git_complete gl git_log 36 | # 37 | # Or if it's a main command (i.e. git or gitk): 38 | # 39 | # __git_complete gk gitk 40 | # 41 | # Compatible with bash 3.2.57. 42 | # 43 | # You can set the following environment variables to influence the behavior of 44 | # the completion routines: 45 | # 46 | # GIT_COMPLETION_CHECKOUT_NO_GUESS 47 | # 48 | # When set to "1", do not include "DWIM" suggestions in git-checkout 49 | # and git-switch completion (e.g., completing "foo" when "origin/foo" 50 | # exists). 51 | # 52 | # GIT_COMPLETION_SHOW_ALL 53 | # 54 | # When set to "1" suggest all options, including options which are 55 | # typically hidden (e.g. '--allow-empty' for 'git commit'). 56 | 57 | case "$COMP_WORDBREAKS" in 58 | *:*) : great ;; 59 | *) COMP_WORDBREAKS="$COMP_WORDBREAKS:" 60 | esac 61 | 62 | # Discovers the path to the git repository taking any '--git-dir=' and 63 | # '-C ' options into account and stores it in the $__git_repo_path 64 | # variable. 65 | __git_find_repo_path () 66 | { 67 | if [ -n "${__git_repo_path-}" ]; then 68 | # we already know where it is 69 | return 70 | fi 71 | 72 | if [ -n "${__git_C_args-}" ]; then 73 | __git_repo_path="$(git "${__git_C_args[@]}" \ 74 | ${__git_dir:+--git-dir="$__git_dir"} \ 75 | rev-parse --absolute-git-dir 2>/dev/null)" 76 | elif [ -n "${__git_dir-}" ]; then 77 | test -d "$__git_dir" && 78 | __git_repo_path="$__git_dir" 79 | elif [ -n "${GIT_DIR-}" ]; then 80 | test -d "$GIT_DIR" && 81 | __git_repo_path="$GIT_DIR" 82 | elif [ -d .git ]; then 83 | __git_repo_path=.git 84 | else 85 | __git_repo_path="$(git rev-parse --git-dir 2>/dev/null)" 86 | fi 87 | } 88 | 89 | # Deprecated: use __git_find_repo_path() and $__git_repo_path instead 90 | # __gitdir accepts 0 or 1 arguments (i.e., location) 91 | # returns location of .git repo 92 | __gitdir () 93 | { 94 | if [ -z "${1-}" ]; then 95 | __git_find_repo_path || return 1 96 | echo "$__git_repo_path" 97 | elif [ -d "$1/.git" ]; then 98 | echo "$1/.git" 99 | else 100 | echo "$1" 101 | fi 102 | } 103 | 104 | # Runs git with all the options given as argument, respecting any 105 | # '--git-dir=' and '-C ' options present on the command line 106 | __git () 107 | { 108 | git ${__git_C_args:+"${__git_C_args[@]}"} \ 109 | ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null 110 | } 111 | 112 | # Removes backslash escaping, single quotes and double quotes from a word, 113 | # stores the result in the variable $dequoted_word. 114 | # 1: The word to dequote. 115 | __git_dequote () 116 | { 117 | local rest="$1" len ch 118 | 119 | dequoted_word="" 120 | 121 | while test -n "$rest"; do 122 | len=${#dequoted_word} 123 | dequoted_word="$dequoted_word${rest%%[\\\'\"]*}" 124 | rest="${rest:$((${#dequoted_word}-$len))}" 125 | 126 | case "${rest:0:1}" in 127 | \\) 128 | ch="${rest:1:1}" 129 | case "$ch" in 130 | $'\n') 131 | ;; 132 | *) 133 | dequoted_word="$dequoted_word$ch" 134 | ;; 135 | esac 136 | rest="${rest:2}" 137 | ;; 138 | \') 139 | rest="${rest:1}" 140 | len=${#dequoted_word} 141 | dequoted_word="$dequoted_word${rest%%\'*}" 142 | rest="${rest:$((${#dequoted_word}-$len+1))}" 143 | ;; 144 | \") 145 | rest="${rest:1}" 146 | while test -n "$rest" ; do 147 | len=${#dequoted_word} 148 | dequoted_word="$dequoted_word${rest%%[\\\"]*}" 149 | rest="${rest:$((${#dequoted_word}-$len))}" 150 | case "${rest:0:1}" in 151 | \\) 152 | ch="${rest:1:1}" 153 | case "$ch" in 154 | \"|\\|\$|\`) 155 | dequoted_word="$dequoted_word$ch" 156 | ;; 157 | $'\n') 158 | ;; 159 | *) 160 | dequoted_word="$dequoted_word\\$ch" 161 | ;; 162 | esac 163 | rest="${rest:2}" 164 | ;; 165 | \") 166 | rest="${rest:1}" 167 | break 168 | ;; 169 | esac 170 | done 171 | ;; 172 | esac 173 | done 174 | } 175 | 176 | # The following function is based on code from: 177 | # 178 | # bash_completion - programmable completion functions for bash 3.2+ 179 | # 180 | # Copyright © 2006-2008, Ian Macdonald 181 | # © 2009-2010, Bash Completion Maintainers 182 | # 183 | # 184 | # This program is free software; you can redistribute it and/or modify 185 | # it under the terms of the GNU General Public License as published by 186 | # the Free Software Foundation; either version 2, or (at your option) 187 | # any later version. 188 | # 189 | # This program is distributed in the hope that it will be useful, 190 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 191 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 192 | # GNU General Public License for more details. 193 | # 194 | # You should have received a copy of the GNU General Public License 195 | # along with this program; if not, see . 196 | # 197 | # The latest version of this software can be obtained here: 198 | # 199 | # http://bash-completion.alioth.debian.org/ 200 | # 201 | # RELEASE: 2.x 202 | 203 | # This function can be used to access a tokenized list of words 204 | # on the command line: 205 | # 206 | # __git_reassemble_comp_words_by_ref '=:' 207 | # if test "${words_[cword_-1]}" = -w 208 | # then 209 | # ... 210 | # fi 211 | # 212 | # The argument should be a collection of characters from the list of 213 | # word completion separators (COMP_WORDBREAKS) to treat as ordinary 214 | # characters. 215 | # 216 | # This is roughly equivalent to going back in time and setting 217 | # COMP_WORDBREAKS to exclude those characters. The intent is to 218 | # make option types like --date= and : easy to 219 | # recognize by treating each shell word as a single token. 220 | # 221 | # It is best not to set COMP_WORDBREAKS directly because the value is 222 | # shared with other completion scripts. By the time the completion 223 | # function gets called, COMP_WORDS has already been populated so local 224 | # changes to COMP_WORDBREAKS have no effect. 225 | # 226 | # Output: words_, cword_, cur_. 227 | 228 | __git_reassemble_comp_words_by_ref() 229 | { 230 | local exclude i j first 231 | # Which word separators to exclude? 232 | exclude="${1//[^$COMP_WORDBREAKS]}" 233 | cword_=$COMP_CWORD 234 | if [ -z "$exclude" ]; then 235 | words_=("${COMP_WORDS[@]}") 236 | return 237 | fi 238 | # List of word completion separators has shrunk; 239 | # re-assemble words to complete. 240 | for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do 241 | # Append each nonempty word consisting of just 242 | # word separator characters to the current word. 243 | first=t 244 | while 245 | [ $i -gt 0 ] && 246 | [ -n "${COMP_WORDS[$i]}" ] && 247 | # word consists of excluded word separators 248 | [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ] 249 | do 250 | # Attach to the previous token, 251 | # unless the previous token is the command name. 252 | if [ $j -ge 2 ] && [ -n "$first" ]; then 253 | ((j--)) 254 | fi 255 | first= 256 | words_[$j]=${words_[j]}${COMP_WORDS[i]} 257 | if [ $i = $COMP_CWORD ]; then 258 | cword_=$j 259 | fi 260 | if (($i < ${#COMP_WORDS[@]} - 1)); then 261 | ((i++)) 262 | else 263 | # Done. 264 | return 265 | fi 266 | done 267 | words_[$j]=${words_[j]}${COMP_WORDS[i]} 268 | if [ $i = $COMP_CWORD ]; then 269 | cword_=$j 270 | fi 271 | done 272 | } 273 | 274 | if ! type _get_comp_words_by_ref >/dev/null 2>&1; then 275 | _get_comp_words_by_ref () 276 | { 277 | local exclude cur_ words_ cword_ 278 | if [ "$1" = "-n" ]; then 279 | exclude=$2 280 | shift 2 281 | fi 282 | __git_reassemble_comp_words_by_ref "$exclude" 283 | cur_=${words_[cword_]} 284 | while [ $# -gt 0 ]; do 285 | case "$1" in 286 | cur) 287 | cur=$cur_ 288 | ;; 289 | prev) 290 | prev=${words_[$cword_-1]} 291 | ;; 292 | words) 293 | words=("${words_[@]}") 294 | ;; 295 | cword) 296 | cword=$cword_ 297 | ;; 298 | esac 299 | shift 300 | done 301 | } 302 | fi 303 | 304 | # Fills the COMPREPLY array with prefiltered words without any additional 305 | # processing. 306 | # Callers must take care of providing only words that match the current word 307 | # to be completed and adding any prefix and/or suffix (trailing space!), if 308 | # necessary. 309 | # 1: List of newline-separated matching completion words, complete with 310 | # prefix and suffix. 311 | __gitcomp_direct () 312 | { 313 | local IFS=$'\n' 314 | 315 | COMPREPLY=($1) 316 | } 317 | 318 | # Similar to __gitcomp_direct, but appends to COMPREPLY instead. 319 | # Callers must take care of providing only words that match the current word 320 | # to be completed and adding any prefix and/or suffix (trailing space!), if 321 | # necessary. 322 | # 1: List of newline-separated matching completion words, complete with 323 | # prefix and suffix. 324 | __gitcomp_direct_append () 325 | { 326 | local IFS=$'\n' 327 | 328 | COMPREPLY+=($1) 329 | } 330 | 331 | __gitcompappend () 332 | { 333 | local x i=${#COMPREPLY[@]} 334 | for x in $1; do 335 | if [[ "$x" == "$3"* ]]; then 336 | COMPREPLY[i++]="$2$x$4" 337 | fi 338 | done 339 | } 340 | 341 | __gitcompadd () 342 | { 343 | COMPREPLY=() 344 | __gitcompappend "$@" 345 | } 346 | 347 | # Generates completion reply, appending a space to possible completion words, 348 | # if necessary. 349 | # It accepts 1 to 4 arguments: 350 | # 1: List of possible completion words. 351 | # 2: A prefix to be added to each possible completion word (optional). 352 | # 3: Generate possible completion matches for this word (optional). 353 | # 4: A suffix to be appended to each possible completion word (optional). 354 | __gitcomp () 355 | { 356 | local cur_="${3-$cur}" 357 | 358 | case "$cur_" in 359 | *=) 360 | ;; 361 | --no-*) 362 | local c i=0 IFS=$' \t\n' 363 | for c in $1; do 364 | if [[ $c == "--" ]]; then 365 | continue 366 | fi 367 | c="$c${4-}" 368 | if [[ $c == "$cur_"* ]]; then 369 | case $c in 370 | --*=|*.) ;; 371 | *) c="$c " ;; 372 | esac 373 | COMPREPLY[i++]="${2-}$c" 374 | fi 375 | done 376 | ;; 377 | *) 378 | local c i=0 IFS=$' \t\n' 379 | for c in $1; do 380 | if [[ $c == "--" ]]; then 381 | c="--no-...${4-}" 382 | if [[ $c == "$cur_"* ]]; then 383 | COMPREPLY[i++]="${2-}$c " 384 | fi 385 | break 386 | fi 387 | c="$c${4-}" 388 | if [[ $c == "$cur_"* ]]; then 389 | case $c in 390 | *=|*.) ;; 391 | *) c="$c " ;; 392 | esac 393 | COMPREPLY[i++]="${2-}$c" 394 | fi 395 | done 396 | ;; 397 | esac 398 | } 399 | 400 | # Clear the variables caching builtins' options when (re-)sourcing 401 | # the completion script. 402 | if [[ -n ${ZSH_VERSION-} ]]; then 403 | unset ${(M)${(k)parameters[@]}:#__gitcomp_builtin_*} 2>/dev/null 404 | else 405 | unset $(compgen -v __gitcomp_builtin_) 406 | fi 407 | 408 | # This function is equivalent to 409 | # 410 | # __gitcomp "$(git xxx --git-completion-helper) ..." 411 | # 412 | # except that the output is cached. Accept 1-3 arguments: 413 | # 1: the git command to execute, this is also the cache key 414 | # 2: extra options to be added on top (e.g. negative forms) 415 | # 3: options to be excluded 416 | __gitcomp_builtin () 417 | { 418 | # spaces must be replaced with underscore for multi-word 419 | # commands, e.g. "git remote add" becomes remote_add. 420 | local cmd="$1" 421 | local incl="${2-}" 422 | local excl="${3-}" 423 | 424 | local var=__gitcomp_builtin_"${cmd//-/_}" 425 | local options 426 | eval "options=\${$var-}" 427 | 428 | if [ -z "$options" ]; then 429 | local completion_helper 430 | if [ "${GIT_COMPLETION_SHOW_ALL-}" = "1" ]; then 431 | completion_helper="--git-completion-helper-all" 432 | else 433 | completion_helper="--git-completion-helper" 434 | fi 435 | # leading and trailing spaces are significant to make 436 | # option removal work correctly. 437 | options=" $incl $(__git ${cmd/_/ } $completion_helper) " || return 438 | 439 | for i in $excl; do 440 | options="${options/ $i / }" 441 | done 442 | eval "$var=\"$options\"" 443 | fi 444 | 445 | __gitcomp "$options" 446 | } 447 | 448 | # Variation of __gitcomp_nl () that appends to the existing list of 449 | # completion candidates, COMPREPLY. 450 | __gitcomp_nl_append () 451 | { 452 | local IFS=$'\n' 453 | __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }" 454 | } 455 | 456 | # Generates completion reply from newline-separated possible completion words 457 | # by appending a space to all of them. 458 | # It accepts 1 to 4 arguments: 459 | # 1: List of possible completion words, separated by a single newline. 460 | # 2: A prefix to be added to each possible completion word (optional). 461 | # 3: Generate possible completion matches for this word (optional). 462 | # 4: A suffix to be appended to each possible completion word instead of 463 | # the default space (optional). If specified but empty, nothing is 464 | # appended. 465 | __gitcomp_nl () 466 | { 467 | COMPREPLY=() 468 | __gitcomp_nl_append "$@" 469 | } 470 | 471 | # Fills the COMPREPLY array with prefiltered paths without any additional 472 | # processing. 473 | # Callers must take care of providing only paths that match the current path 474 | # to be completed and adding any prefix path components, if necessary. 475 | # 1: List of newline-separated matching paths, complete with all prefix 476 | # path components. 477 | __gitcomp_file_direct () 478 | { 479 | local IFS=$'\n' 480 | 481 | COMPREPLY=($1) 482 | 483 | # use a hack to enable file mode in bash < 4 484 | compopt -o filenames +o nospace 2>/dev/null || 485 | compgen -f /non-existing-dir/ >/dev/null || 486 | true 487 | } 488 | 489 | # Generates completion reply with compgen from newline-separated possible 490 | # completion filenames. 491 | # It accepts 1 to 3 arguments: 492 | # 1: List of possible completion filenames, separated by a single newline. 493 | # 2: A directory prefix to be added to each possible completion filename 494 | # (optional). 495 | # 3: Generate possible completion matches for this word (optional). 496 | __gitcomp_file () 497 | { 498 | local IFS=$'\n' 499 | 500 | # XXX does not work when the directory prefix contains a tilde, 501 | # since tilde expansion is not applied. 502 | # This means that COMPREPLY will be empty and Bash default 503 | # completion will be used. 504 | __gitcompadd "$1" "${2-}" "${3-$cur}" "" 505 | 506 | # use a hack to enable file mode in bash < 4 507 | compopt -o filenames +o nospace 2>/dev/null || 508 | compgen -f /non-existing-dir/ >/dev/null || 509 | true 510 | } 511 | 512 | # Execute 'git ls-files', unless the --committable option is specified, in 513 | # which case it runs 'git diff-index' to find out the files that can be 514 | # committed. It return paths relative to the directory specified in the first 515 | # argument, and using the options specified in the second argument. 516 | __git_ls_files_helper () 517 | { 518 | if [ "$2" == "--committable" ]; then 519 | __git -C "$1" -c core.quotePath=false diff-index \ 520 | --name-only --relative HEAD -- "${3//\\/\\\\}*" 521 | else 522 | # NOTE: $2 is not quoted in order to support multiple options 523 | __git -C "$1" -c core.quotePath=false ls-files \ 524 | --exclude-standard $2 -- "${3//\\/\\\\}*" 525 | fi 526 | } 527 | 528 | 529 | # __git_index_files accepts 1 or 2 arguments: 530 | # 1: Options to pass to ls-files (required). 531 | # 2: A directory path (optional). 532 | # If provided, only files within the specified directory are listed. 533 | # Sub directories are never recursed. Path must have a trailing 534 | # slash. 535 | # 3: List only paths matching this path component (optional). 536 | __git_index_files () 537 | { 538 | local root="$2" match="$3" 539 | 540 | __git_ls_files_helper "$root" "$1" "${match:-?}" | 541 | awk -F / -v pfx="${2//\\/\\\\}" '{ 542 | paths[$1] = 1 543 | } 544 | END { 545 | for (p in paths) { 546 | if (substr(p, 1, 1) != "\"") { 547 | # No special characters, easy! 548 | print pfx p 549 | continue 550 | } 551 | 552 | # The path is quoted. 553 | p = dequote(p) 554 | if (p == "") 555 | continue 556 | 557 | # Even when a directory name itself does not contain 558 | # any special characters, it will still be quoted if 559 | # any of its (stripped) trailing path components do. 560 | # Because of this we may have seen the same directory 561 | # both quoted and unquoted. 562 | if (p in paths) 563 | # We have seen the same directory unquoted, 564 | # skip it. 565 | continue 566 | else 567 | print pfx p 568 | } 569 | } 570 | function dequote(p, bs_idx, out, esc, esc_idx, dec) { 571 | # Skip opening double quote. 572 | p = substr(p, 2) 573 | 574 | # Interpret backslash escape sequences. 575 | while ((bs_idx = index(p, "\\")) != 0) { 576 | out = out substr(p, 1, bs_idx - 1) 577 | esc = substr(p, bs_idx + 1, 1) 578 | p = substr(p, bs_idx + 2) 579 | 580 | if ((esc_idx = index("abtvfr\"\\", esc)) != 0) { 581 | # C-style one-character escape sequence. 582 | out = out substr("\a\b\t\v\f\r\"\\", 583 | esc_idx, 1) 584 | } else if (esc == "n") { 585 | # Uh-oh, a newline character. 586 | # We cannot reliably put a pathname 587 | # containing a newline into COMPREPLY, 588 | # and the newline would create a mess. 589 | # Skip this path. 590 | return "" 591 | } else { 592 | # Must be a \nnn octal value, then. 593 | dec = esc * 64 + \ 594 | substr(p, 1, 1) * 8 + \ 595 | substr(p, 2, 1) 596 | out = out sprintf("%c", dec) 597 | p = substr(p, 3) 598 | } 599 | } 600 | # Drop closing double quote, if there is one. 601 | # (There is not any if this is a directory, as it was 602 | # already stripped with the trailing path components.) 603 | if (substr(p, length(p), 1) == "\"") 604 | out = out substr(p, 1, length(p) - 1) 605 | else 606 | out = out p 607 | 608 | return out 609 | }' 610 | } 611 | 612 | # __git_complete_index_file requires 1 argument: 613 | # 1: the options to pass to ls-file 614 | # 615 | # The exception is --committable, which finds the files appropriate commit. 616 | __git_complete_index_file () 617 | { 618 | local dequoted_word pfx="" cur_ 619 | 620 | __git_dequote "$cur" 621 | 622 | case "$dequoted_word" in 623 | ?*/*) 624 | pfx="${dequoted_word%/*}/" 625 | cur_="${dequoted_word##*/}" 626 | ;; 627 | *) 628 | cur_="$dequoted_word" 629 | esac 630 | 631 | __gitcomp_file_direct "$(__git_index_files "$1" "$pfx" "$cur_")" 632 | } 633 | 634 | # Lists branches from the local repository. 635 | # 1: A prefix to be added to each listed branch (optional). 636 | # 2: List only branches matching this word (optional; list all branches if 637 | # unset or empty). 638 | # 3: A suffix to be appended to each listed branch (optional). 639 | __git_heads () 640 | { 641 | local pfx="${1-}" cur_="${2-}" sfx="${3-}" 642 | 643 | __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \ 644 | "refs/heads/$cur_*" "refs/heads/$cur_*/**" 645 | } 646 | 647 | # Lists branches from remote repositories. 648 | # 1: A prefix to be added to each listed branch (optional). 649 | # 2: List only branches matching this word (optional; list all branches if 650 | # unset or empty). 651 | # 3: A suffix to be appended to each listed branch (optional). 652 | __git_remote_heads () 653 | { 654 | local pfx="${1-}" cur_="${2-}" sfx="${3-}" 655 | 656 | __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \ 657 | "refs/remotes/$cur_*" "refs/remotes/$cur_*/**" 658 | } 659 | 660 | # Lists tags from the local repository. 661 | # Accepts the same positional parameters as __git_heads() above. 662 | __git_tags () 663 | { 664 | local pfx="${1-}" cur_="${2-}" sfx="${3-}" 665 | 666 | __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \ 667 | "refs/tags/$cur_*" "refs/tags/$cur_*/**" 668 | } 669 | 670 | # List unique branches from refs/remotes used for 'git checkout' and 'git 671 | # switch' tracking DWIMery. 672 | # 1: A prefix to be added to each listed branch (optional) 673 | # 2: List only branches matching this word (optional; list all branches if 674 | # unset or empty). 675 | # 3: A suffix to be appended to each listed branch (optional). 676 | __git_dwim_remote_heads () 677 | { 678 | local pfx="${1-}" cur_="${2-}" sfx="${3-}" 679 | local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers 680 | 681 | # employ the heuristic used by git checkout and git switch 682 | # Try to find a remote branch that cur_es the completion word 683 | # but only output if the branch name is unique 684 | __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \ 685 | --sort="refname:strip=3" \ 686 | "refs/remotes/*/$cur_*" "refs/remotes/*/$cur_*/**" | \ 687 | uniq -u 688 | } 689 | 690 | # Lists refs from the local (by default) or from a remote repository. 691 | # It accepts 0, 1 or 2 arguments: 692 | # 1: The remote to list refs from (optional; ignored, if set but empty). 693 | # Can be the name of a configured remote, a path, or a URL. 694 | # 2: In addition to local refs, list unique branches from refs/remotes/ for 695 | # 'git checkout's tracking DWIMery (optional; ignored, if set but empty). 696 | # 3: A prefix to be added to each listed ref (optional). 697 | # 4: List only refs matching this word (optional; list all refs if unset or 698 | # empty). 699 | # 5: A suffix to be appended to each listed ref (optional; ignored, if set 700 | # but empty). 701 | # 702 | # Use __git_complete_refs() instead. 703 | __git_refs () 704 | { 705 | local i hash dir track="${2-}" 706 | local list_refs_from=path remote="${1-}" 707 | local format refs 708 | local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}" 709 | local match="${4-}" 710 | local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers 711 | 712 | __git_find_repo_path 713 | dir="$__git_repo_path" 714 | 715 | if [ -z "$remote" ]; then 716 | if [ -z "$dir" ]; then 717 | return 718 | fi 719 | else 720 | if __git_is_configured_remote "$remote"; then 721 | # configured remote takes precedence over a 722 | # local directory with the same name 723 | list_refs_from=remote 724 | elif [ -d "$remote/.git" ]; then 725 | dir="$remote/.git" 726 | elif [ -d "$remote" ]; then 727 | dir="$remote" 728 | else 729 | list_refs_from=url 730 | fi 731 | fi 732 | 733 | if [ "$list_refs_from" = path ]; then 734 | if [[ "$cur_" == ^* ]]; then 735 | pfx="$pfx^" 736 | fer_pfx="$fer_pfx^" 737 | cur_=${cur_#^} 738 | match=${match#^} 739 | fi 740 | case "$cur_" in 741 | refs|refs/*) 742 | format="refname" 743 | refs=("$match*" "$match*/**") 744 | track="" 745 | ;; 746 | *) 747 | for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD; do 748 | case "$i" in 749 | $match*) 750 | if [ -e "$dir/$i" ]; then 751 | echo "$pfx$i$sfx" 752 | fi 753 | ;; 754 | esac 755 | done 756 | format="refname:strip=2" 757 | refs=("refs/tags/$match*" "refs/tags/$match*/**" 758 | "refs/heads/$match*" "refs/heads/$match*/**" 759 | "refs/remotes/$match*" "refs/remotes/$match*/**") 760 | ;; 761 | esac 762 | __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \ 763 | "${refs[@]}" 764 | if [ -n "$track" ]; then 765 | __git_dwim_remote_heads "$pfx" "$match" "$sfx" 766 | fi 767 | return 768 | fi 769 | case "$cur_" in 770 | refs|refs/*) 771 | __git ls-remote "$remote" "$match*" | \ 772 | while read -r hash i; do 773 | case "$i" in 774 | *^{}) ;; 775 | *) echo "$pfx$i$sfx" ;; 776 | esac 777 | done 778 | ;; 779 | *) 780 | if [ "$list_refs_from" = remote ]; then 781 | case "HEAD" in 782 | $match*) echo "${pfx}HEAD$sfx" ;; 783 | esac 784 | __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \ 785 | "refs/remotes/$remote/$match*" \ 786 | "refs/remotes/$remote/$match*/**" 787 | else 788 | local query_symref 789 | case "HEAD" in 790 | $match*) query_symref="HEAD" ;; 791 | esac 792 | __git ls-remote "$remote" $query_symref \ 793 | "refs/tags/$match*" "refs/heads/$match*" \ 794 | "refs/remotes/$match*" | 795 | while read -r hash i; do 796 | case "$i" in 797 | *^{}) ;; 798 | refs/*) echo "$pfx${i#refs/*/}$sfx" ;; 799 | *) echo "$pfx$i$sfx" ;; # symbolic refs 800 | esac 801 | done 802 | fi 803 | ;; 804 | esac 805 | } 806 | 807 | # Completes refs, short and long, local and remote, symbolic and pseudo. 808 | # 809 | # Usage: __git_complete_refs [