| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- ################################################################################
- # Basic configuration
- ################################################################################
- setopt BEEP
- export TERM=alacritty
- export LANG=en_US.UTF-8
- # Disable the log builtin, so we don't conflict with /usr/bin/log
- disable log
- # Correctly display UTF-8 with combining characters.
- if [[ "$(locale LC_CTYPE)" == "UTF-8" ]]; then
- setopt COMBINING_CHARS
- fi
- # Use `nvim` as editor, preferring current instance if nested
- export EDITOR="${DOTFILES_DIR}/.scripts/nvim_editor.zsh"
- # Fixes plugin keymap conflicts
- export ZVM_INIT_MODE=sourcing
- ################################################################################
- # History
- ################################################################################
- HISTFILE=${ZDOTDIR}/.zsh_history
- HISTSIZE=2147483647
- SAVEHIST=$HISTSIZE
- export HISTORY_IGNORE="(ls|lsd|la|cd|pwd|exit)*"
- setopt HIST_EXPIRE_DUPS_FIRST
- setopt HIST_IGNORE_ALL_DUPS
- setopt HIST_IGNORE_DUPS
- setopt HIST_IGNORE_SPACE
- setopt HIST_REDUCE_BLANKS
- setopt HIST_VERIFY
- setopt INC_APPEND_HISTORY
- setopt SHARE_HISTORY
- ################################################################################
- # Prompt
- ################################################################################
- # A pleasant, informative, and transient prompt. Made possible by an arcane
- # incantation from [powerlevel10k](https://github.com/romkatv/powerlevel10k/),
- # as described in the project's issue tracker:
- # https://github.com/romkatv/powerlevel10k/issues/888#issuecomment-657969840
- autoload -Uz compinit
- compinit
- autoload -Uz vcs_info
- precmd_vcs_info() { vcs_info }
- setopt prompt_subst
- zstyle ':vcs_info:git:*' formats '%F{3}%F{8} %b '
- set-long-prompt() {
- if [ "$NEW_LINE_BEFORE_PROMPT" -eq 1 ]; then
- print ''
- else
- NEW_LINE_BEFORE_PROMPT=1
- fi
- PROMPT='%F{3}%F{8} %d %0(?..%F{3}%F{8} %? )${vcs_info_msg_0_}%F{3}%F{8} %m %F{3}%F{8} %n
- %F{3}$ %f%k'
- }
- set-short-prompt() {
- if [[ $PROMPT != '%F{3}$ %f%k' ]]; then
- PROMPT='%F{3}$ %f%k'
- zle .reset-prompt
- fi
- }
- precmd_functions=(
- set-long-prompt
- precmd_vcs_info
- )
- zle-line-finish() {
- set-short-prompt
- }
- zle -N zle-line-finish
- trap 'set-short-prompt; return 130' INT
- ################################################################################
- # Potentially interactive execution
- ################################################################################
- # Load SSH key into keychain
- if [[ $OSTYPE == darwin* ]] then
- ssh-add --apple-use-keychain $HOME/.ssh/id_rsa >/dev/null 2>&1
- else
- eval `keychain --eval --quiet id_rsa`
- fi
- ################################################################################
- # Aliases
- ################################################################################
- alias x="exit"
- alias c="clear && NEW_LINE_BEFORE_PROMPT=0"
- alias clear="clear && NEW_LINE_BEFORE_PROMPT=0"
- # nvim
- if command -v nvim &>/dev/null; then;
- alias n="nvim"
- fi;
- # granted
- if command -v assume &>/dev/null; then;
- alias assume=". assume"
- fi;
- # brew
- if command -v brew &>/dev/null; then;
- alias brewdump="(cd $XDG_CONFIG_HOME/brew/ && brew bundle dump --force --describe)"
- fi;
- # docker
- if command -v docker &>/dev/null; then;
- alias dockerprune="(docker system prune -a -f && docker system df -v) | less"
- fi;
- # git
- if command -v git &>/dev/null; then;
- alias g="git"
- alias gs="git s"
- alias gl="git l"
- fi;
- # lsd
- if command -v lsd &>/dev/null; then;
- alias ls="lsd -a"
- alias la="lsd -la"
- fi;
- # lazygit
- if command -v lazygit &>/dev/null; then;
- alias lg="lazygit"
- fi;
- # lazydocker
- if command -v lazydocker &>/dev/null; then;
- alias lg="lazydocker"
- fi;
- ################################################################################
- # From github.com/zsh-users:
- # * zsh-autosuggestions
- # * zsh-syntax-highlighting
- # Both can be installed through Homebrew.
- ################################################################################
- if command -v brew >> /dev/null; then
- source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh
- source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
- source $(brew --prefix)/opt/zsh-vi-mode/share/zsh-vi-mode/zsh-vi-mode.plugin.zsh
- fi
- ################################################################################
- # fzf
- ################################################################################
- if command -v fzf >> /dev/null; then
- eval "$(fzf --zsh)"
- fi
- ################################################################################
- # Keybinds
- ################################################################################
- # Ctrl+Y copies buffer to clipboard
- cmd_to_clip () { pbcopy <<< $BUFFER }
- zle -N cmd_to_clip
- bindkey '^Y' cmd_to_clip
- # Ctrl+G copies git-tracked file contents in directory to the clipboard
- copy_dir_llm_style () {
- git ls-files | column;
- if read -s -q "choice?Total files: $( git ls-files | wc -l) | Press 'y' to copy contents"; then;
- {
- echo "Here is the contents of \`$(basename "$PWD")/\`:\n";
- git ls-files -z |
- while IFS= read -r -d $'\0' f; do
- if [[ "$(file -b --mime-type "$f")" == "text/"* ]]; then
- echo "$f"; echo '```';
- cat "$f"; echo '```';
- echo;
- fi
- done;
- } | pbcopy
- echo "\nCopied!"
- else;
- echo "\nQuit without copying anything"
- fi
- }
- zle -N copy_dir_llm_style
- bindkey '^G' copy_dir_llm_style
|