setopt null_glob source /usr/local/share/antigen/antigen.zsh if [[ "$OSTYPE" == "darwin"* ]]; then # antigen bundle osx # Required for z to work source `brew --prefix`/etc/profile.d/z.sh fi antigen bundle git antigen bundle yarn antigen bundle docker antigen bundle docker-compose antigen bundle gitfast antigen bundle Seinh/git-prune antigen bundle zsh-users/zsh-syntax-highlighting antigen bundle zsh-users/zsh-autosuggestions antigen bundle zsh-completions # Tell Antigen that you're done. antigen apply autoload -U compinit compdef compinit # prefer nvim as $EDITOR if which nvim > /dev/null; then export EDITOR=nvim alias vi=nvim alias vim=nvim else export EDITOR=vim alias nvim=vim fi export GIT_EDITOR=$EDITOR export VISUAL=$EDITOR setopt inc_append_history setopt hist_ignore_all_dups # Ensures that glob failures don't cause the # command to be aborted, meaning that the # caret (^) works as expected # https://stackoverflow.com/questions/6091827/git-show-head-doesnt-seem-to-be-working-is-this-normal setopt NO_NOMATCH # Set GUI editor export GUI_EDITOR="IntelliJ\ IDEA\ Ultimate" # Vi mode bindkey -v '^?' backward-delete-char # https://superuser.com/questions/476532/how-can-i-make-zshs-vi-mode-behave-more-like-bashs-vi-mode # bindkey -mv # 10ms for key sequences # https://www.johnhawthorn.com/2012/09/vi-escape-delays/ KEYTIMEOUT=1 # fzf setup [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh if [ -f ~/.fzf.zsh ]; then export FZF_DEFAULT_OPTS=--inline-info export FZF_DEFAULT_COMMAND='rg --files --hidden --follow --glob "!{.git,node_modules}/*"' # To apply the command to CTRL-T as well export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" source ~/.fzf.zsh # Re-bind to match most modern editors bindkey '\C-p' fzf-file-widget # MacOS doesn't use Alt in terminal, so re-bind bindkey '\C-o' fzf-cd-widget fi if which direnv > /dev/null; then # Set up direnv eval "$(direnv hook zsh)" fi # node (nvm) export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # ruby (rvm) if which rbenv > /dev/null; then eval "$(rbenv init -)" fi # Enable docker completion for commands such as docker exec -it zstyle ':completion:*:*:docker:*' option-stacking yes zstyle ':completion:*:*:docker-*:*' option-stacking yes # Load aliases source ~/dotfiles/zsh/aliases.inc.zsh; # Load custom executable functions for file in ~/dotfiles/zsh/functions/*.inc.zsh; do source "$file" done # Load in custom configs for file in ~/dotfiles/zsh/conf.d/*.inc.zsh; do source "$file" done eval "$(starship init zsh)" # Source: https://github.com/ohmyzsh/ohmyzsh/blob/master/lib/git.zsh # Outputs the name of the current branch # Usage example: git pull origin $(git_current_branch) # Using '--quiet' with 'symbolic-ref' will not cause a fatal error (128) if # it's not a symbolic ref, but in a Git repo. # ------------- # We wrap in a local function instead of exporting the variable directly in # order to avoid interfering with manually-run git commands by the user. __git_prompt_git() { GIT_OPTIONAL_LOCKS=0 command git "$@" } git_current_branch() { local ref ref=$(__git_prompt_git symbolic-ref --quiet HEAD 2> /dev/null) local ret=$? if [[ $ret != 0 ]]; then [[ $ret == 128 ]] && return # no git repo. ref=$(__git_prompt_git rev-parse --short HEAD 2> /dev/null) || return fi echo ${ref#refs/heads/} } # GIT heart FZF # https://gist.github.com/junegunn/8b572b8d4b5eddd8b85e5f4d40f17236 # ------------- is_in_git_repo() { git rev-parse HEAD > /dev/null 2>&1 } fzf-down() { fzf --height 50% "$@" --border } fzf-gf() { is_in_git_repo || return git -c color.status=always status --short | fzf-down -m --ansi --nth 2..,.. \ --preview '(git diff --color=always -- {-1} | sed 1,4d; cat {-1}) | head -500' | cut -c4- | sed 's/.* -> //' } fzf-gb() { is_in_git_repo || return git branch -a --color=always | grep -v '/HEAD\s' | sort | fzf-down --ansi --multi --tac --preview-window right:70% \ --preview 'git log --oneline --graph --date=short --color=always --pretty="format:%C(auto)%cd %h%d %s" $(sed s/^..// <<< {} | cut -d" " -f1) | head -'$LINES | sed 's/^..//' | cut -d' ' -f1 | sed 's#^remotes/##' } fzf-gt() { is_in_git_repo || return git tag --sort -version:refname | fzf-down --multi --preview-window right:70% \ --preview 'git show --color=always {} | head -'$LINES } fzf-gg() { is_in_git_repo || return git log --date=short --format="%C(green)%C(bold)%cd %C(auto)%h%d %s (%an)" --graph --color=always | fzf-down --ansi --no-sort --reverse --multi --bind 'ctrl-s:toggle-sort' \ --header 'Press CTRL-S to toggle sort' \ --preview 'grep -o "[a-f0-9]\{7,\}" <<< {} | xargs git show --color=always | head -'$LINES | grep -o "[a-f0-9]\{7,\}" } fzf-gr() { is_in_git_repo || return git remote -v | awk '{print $1 "\t" $2}' | uniq | fzf-down --tac \ --preview 'git log --oneline --graph --date=short --pretty="format:%C(auto)%cd %h%d %s" {1} | head -200' | cut -d$'\t' -f1 } # Bindings join-lines() { local item while read item; do echo -n "${(q)item} " done } bind-git-helper() { local c for c in $@; do eval "fzf-g$c-widget() { local result=\$(fzf-g$c | join-lines); zle reset-prompt; LBUFFER+=\$result }" eval "zle -N fzf-g$c-widget" eval "bindkey '^$c' fzf-g$c-widget" done } bind-git-helper b unset -f bind-git-helper