From 0a862f9c09ad288f1fe4779db16a27e0bc77123d Mon Sep 17 00:00:00 2001 From: Nguyen Khac Trieu Date: Thu, 10 Oct 2024 00:52:36 +0700 Subject: [PATCH] fix: Do NOT load on WSL1 because of https://github.com/microsoft/WSL/issues/2395 * zdharma/fast-syntax-highlighting MUST load before zsh-users/zsh-autosuggestions or auto-complate will NOT work + Add `duf` for better `df` --- meta/configs/brew.yaml | 1 + shells/zsh/config/zsh/zshrc | 64 +++++++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/meta/configs/brew.yaml b/meta/configs/brew.yaml index bcf30d6..abe5778 100644 --- a/meta/configs/brew.yaml +++ b/meta/configs/brew.yaml @@ -19,6 +19,7 @@ - direnv - screen # 5.0 to support True Color - byobu # screen + tmux + - duf # a better 'df' alternative, see https://freedium.cfd/https://blog.devops.dev/6-linux-utilities-you-should-install-right-now-75470963a021 - link: ~/.screenrc: apps/screen/screenrc diff --git a/shells/zsh/config/zsh/zshrc b/shells/zsh/config/zsh/zshrc index e092b71..a0a9ff6 100644 --- a/shells/zsh/config/zsh/zshrc +++ b/shells/zsh/config/zsh/zshrc @@ -37,6 +37,7 @@ for file in ${${config_files:#*/path.zsh}:#*/completion.zsh}; do source "$file" done +# !NOTE: use Calling compinit With Turbo Mode instead, see https://github.com/zdharma-continuum/zinit?tab=readme-ov-file#calling-compinit-with-turbo-mode # autoload -Uz compinit # typeset -i updated_at=$(date +'%j' -r ${ZDOTDIR:-$HOME}/.zcompdump 2>/dev/null || stat -f '%Sm' -t '%j' ${ZDOTDIR:-$HOME}/.zcompdump 2>/dev/null) # if [ $(date +'%j') != $updated_at ]; then @@ -45,10 +46,10 @@ done # compinit -C -i # fi -# load every completion after autocomplete loads -for file in ${(M)config_files:#*/completion.zsh}; do - source "$file" -done +# # load every completion after autocomplete loads +# for file in ${(M)config_files:#*/completion.zsh}; do +# source "$file" +# done unset config_files updated_at @@ -218,7 +219,6 @@ zinit wait lucid light-mode for \ OMZL::directories.zsh \ OMZL::grep.zsh \ OMZL::key-bindings.zsh \ - atuinsh/atuin \ OMZP::fzf \ atload" alias dcupb='docker-compose up --build' @@ -251,11 +251,13 @@ zinit wait lucid light-mode for \ # IMPORTANT: # These plugins should be loaded after ohmyzsh plugins +# !NOTE: zdharma/fast-syntax-highlighting MUST load before zsh-users/zsh-autosuggestions or auto-complate will not work +# See https://github.com/zdharma-continuum/fast-syntax-highlighting#zinit zinit wait lucid for \ - light-mode atinit"ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20" atload"!_zsh_autosuggest_start" \ - zsh-users/zsh-autosuggestions \ light-mode atinit"typeset -gA FAST_HIGHLIGHT; FAST_HIGHLIGHT[git-cmsg-len]=100; ZINIT[COMPINIT_OPTS]=-C; zpcompinit; zpcdreplay" \ zdharma/fast-syntax-highlighting \ + light-mode atinit"ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20" atload"!_zsh_autosuggest_start" \ + zsh-users/zsh-autosuggestions \ atpull"%atclone" atclone"_fix-omz-plugin" \ OMZP::colored-man-pages \ atpull"%atclone" atclone"_fix-omz-plugin" nocompile \ @@ -351,7 +353,9 @@ zinit wait lucid light-mode for \ if"[[ $+commands[go] ]]" OMZP::golang \ if"[[ $+commands[npm] ]]" OMZP::npm \ OMZP::urltools \ - pick"zshrc" tcnksm/docker-alias + pick"zshrc" tcnksm/docker-alias \ + if"[[ $+commands[atuin] ]] && [[ ! $(uname -r) =~ ^.*Microsoft$ ]]" atuinsh/atuin # !BUG: Do NOT load on WSL1 because of https://github.com/microsoft/WSL/issues/2395 + # !BUG: svn: E160013: '/sorin-ionescu/prezto/trunk/modules/archive' path not found # See https://github.blog/news-insights/product-news/sunsetting-subversion-support/ # zinit svn wait'!' for \ @@ -365,7 +369,7 @@ zinit wait lucid light-mode for \ # !NOTE: MUST reload using wait'!' at last for history to work? (ENTER any command also make history work) # wait'!...', prompt is reset after load. Zsh can start 80% (i.e.: 5x) faster thanks to postponed loading. zinit wait'!' silent light-mode for \ - atpull"%atclone" atclone"_fix-pzt-module" \ + atpull"%atclone" atclone"_fix-pzt-module" atload"unalias duf" \ PZTM::utility # ############################################################################### @@ -847,6 +851,48 @@ fi debug_echo "Loading Mise for ZSH..." eval "$(mise activate zsh)" +# See https://news.ycombinator.com/item?id=35249933 +CUR_SHELL=zsh +atuin-setup() { + if ! which atuin &> /dev/null; then return 1; fi + bindkey '^E' _atuin_search_widget + + export ATUIN_NOBIND="true" + eval "$(atuin init "$CUR_SHELL")" + fzf-atuin-history-widget() { + local selected num + setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases 2>/dev/null + + # local atuin_opts="--cmd-only --limit ${ATUIN_LIMIT:-5000}" + local atuin_opts="--cmd-only" + local fzf_opts=( + --height=${FZF_TMUX_HEIGHT:-80%} + --tac + "-n2..,.." + --tiebreak=index + "--query=${LBUFFER}" + "+m" + "--bind=ctrl-d:reload(atuin search $atuin_opts -c $PWD),ctrl-r:reload(atuin search $atuin_opts)" + ) + + selected=$( + eval "atuin search ${atuin_opts}" | + fzf "${fzf_opts[@]}" + ) + local ret=$? + if [ -n "$selected" ]; then + # the += lets it insert at current pos instead of replacing + LBUFFER+="${selected}" + fi + zle reset-prompt + return $ret + } + zle -N fzf-atuin-history-widget + bindkey '^R' fzf-atuin-history-widget +} +# !BUG: atuin still throw `Error: error returned from database: (code: 4618) disk I/O error` on WSL1 because of https://github.com/microsoft/WSL/issues/2395 +# atuin-setup + # Display message of the day # run-parts /etc/update-motd.d 2>/dev/null