You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

179 lines
5.1 KiB

#
# Executes commands at the start of an interactive session.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
# Source Prezto.
if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh"
fi
if command -v direnv &> /dev/null; then
eval "$(direnv hook zsh)"
fi
export NIX_PATH=${NIX_PATH:+$NIX_PATH:}$HOME/.nix-defexpr/channels:/nix/var/nix/profiles/per-user/root/channels
zstyle :prompt:pure:prompt:success color green
export EDITOR=nvim
export VISUAL=nvim
export RPROMPT=
unsetopt correct # Don't autocorrect
unsetopt flowcontrol # So ^S and ^Q can be used
setopt no_nomatch # Pass bad matches on
setopt no_share_history
bindkey "\ep" history-beginning-search-backward
bindkey "\en" history-beginning-search-forward
alias be='bundle exec'
alias tat='tmux new-session -As `basename $PWD | ruby -e "puts ARGF.read.strip.downcase.gsub(/[^\w]+/, ?-)"`'
alias plz=sudo
alias ls=exa
alias emacs="emacs --no-window"
alias tmux="direnv exec / tmux"
alias ,df="git --git-dir=$HOME/.dotfiles.git --work-tree=$HOME"
function eject { command hdiutil eject `df | grep Volumes | grep -i "$@" | ruby -ne 'puts $_[/^[^ ]*/]'`; }
eval "$(brew shellenv)"
if [ -e $HOMEBREW_PREFIX/opt/fzf/shell/completion.zsh ]; then
source $HOMEBREW_PREFIX/opt/fzf/shell/key-bindings.zsh
source $HOMEBREW_PREFIX/opt/fzf/shell/completion.zsh
fi
[ -x "$(command -v kubectl)" ] && source <(kubectl completion zsh)
if [ -x "$(command -v terraform)" ]; then
autoload -U +X bashcompinit && bashcompinit
complete -o nospace -C /opt/homebrew/bin/terraform terraform
fi
if [ $commands[fzf] ]; then
[[ $- == *i* ]] && source "/opt/homebrew/opt/fzf/shell/completion.zsh" 2> /dev/null
source "/opt/homebrew/opt/fzf/shell/key-bindings.zsh"
export FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border'
export FZF_DEFAULT_COMMAND="fd --type f"
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_ALT_C_COMMAND="fd --type d"
# alias fzf=fzf-tmux
# https://github.com/junegunn/fzf/issues/164#issuecomment-581837757
bindkey "ç" fzf-cd-widget
z() {
[ $# -gt 0 ] && fasd_cd -d "$*" && return
local dir
dir="$(fasd -Rdl "$1" | fzf -1 -0 --no-sort +m)" && cd "${dir}" || return 1
}
# https://junegunn.kr/2016/07/fzf-git/
is_in_git_repo() {
git rev-parse HEAD > /dev/null 2>&1
}
fzf-down() {
fzf --height 50% --min-height 20 --border --bind ctrl-/:toggle-preview "$@"
}
_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})' |
cut -c4- | sed 's/.* -> //'
}
# this B is capitalized so it maybe will work w/tmux?
_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)' |
sed 's/^..//' | cut -d' ' -f1 |
sed 's#^remotes/##'
}
_gt() {
is_in_git_repo || return
git tag --sort -version:refname |
fzf-down --multi --preview-window right:70% \
--preview 'git show --color=always {}'
}
_gh() {
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' |
grep -o "[a-f0-9]\{7,\}"
}
_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}' |
cut -d$'\t' -f1
}
_gs() {
is_in_git_repo || return
git stash list | fzf-down --reverse -d: --preview 'git show --color=always {1}' |
cut -d: -f1
}
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=\$(_g$c | join-lines); zle reset-prompt; LBUFFER+=\$result }"
eval "zle -N fzf-g$c-widget"
eval "bindkey '^g$c' fzf-g$c-widget" # So it works in tmux
eval "bindkey '^g^$c' fzf-g$c-widget"
done
}
bind-git-helper f B t r h s
unset -f bind-git-helper
if [ $commands[fasd] ]; then
# https://github.com/junegunn/fzf/wiki/examples#with-fasd-1
fasd_fzf() {
local dir
dir="$(fasd -Rds "$1" | fzf -1 -0 --no-sort +m | sed -r 's/^[^[:space:]]+[[:space:]]+//')" && cd "${dir}" || return 1
}
alias j=fasd_fzf # override prezto's fasd integration
fi
fi
if [ $commands[exa] ]; then
export EXA_COLORS="di=34"
fi
# https://docs.brew.sh/Shell-Completion
if type brew &>/dev/null
then
FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"
autoload -Uz compinit
compinit
fi
# allow for pasting commands from the interwebs with a preceding $ prompt
function \$() { "$@" }
[[ -s "$HOME/.zshrc.local" ]] && . "$HOME/.zshrc.local"