Minor zsh additions - atuin and colours

This commit is contained in:
2025-04-07 23:28:58 +02:00
parent 40e5365cd5
commit 44d1d32f3f
2 changed files with 125 additions and 4 deletions

View File

@@ -14,7 +14,7 @@ alias ls="command eza"
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias ip='ip --color=auto'
# Shortcuts
alias g="git"
alias h="history"

127
.zshrc
View File

@@ -61,7 +61,7 @@ if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
fi
bindkey '\ew' kill-region # [Esc-w] - Remove chars from the cursor to the mark
bindkey '^r' history-incremental-search-backward # [Ctrl-r] - Search backward incrementally for a specified string. The string may begin with ^ to anchor the search to the beginning of the line.
#bindkey '^r' history-incremental-search-backward # [Ctrl-r] - Search backward incrementally for a specified string. The string may begin with ^ to anchor the search to the beginning of the line.
if [[ "${terminfo[kpp]}" != "" ]]; then
bindkey "${terminfo[kpp]}" up-line-or-history # [PageUp] - Up a line of history
@@ -179,9 +179,9 @@ zinit snippet OMZP::colored-man-pages
zinit snippet OMZP::rust
zinit snippet OMZP::zoxide
zinit snippet OMZL::completion.zsh
zinit snippet https://github.com/hyprwm/Hyprland/blob/main/hyprctl/hyprctl.zsh
#zinit snippet https://github.com/hyprwm/Hyprland/blob/main/hyprctl/hyprctl.zsh
zinit snippet https://github.com/TheLocehiliosan/yadm/blob/master/completion/zsh/_yadm
zinit snippet https://github.com/fosskers/aura/blob/master/misc/completions/_aura
#zinit snippet https://github.com/fosskers/aura/blob/master/misc/completions/_aura
zinit wait lucid for \
atinit"ZINIT[COMPINIT_OPTS]=-C; zicompinit; zicdreplay" \
@@ -220,3 +220,124 @@ preexec() { print -Pn "\e]0;$1\a" }
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
(( ! ${+functions[p10k]} )) || p10k finalize
# shellcheck disable=SC2034,SC2153,SC2086,SC2155
# Above line is because shellcheck doesn't support zsh, per
# https://github.com/koalaman/shellcheck/wiki/SC1071, and the ignore: param in
# ludeeus/action-shellcheck only supports _directories_, not _files_. So
# instead, we manually add any error the shellcheck step finds in the file to
# the above line ...
# Source this in your ~/.zshrc
autoload -U add-zsh-hook
zmodload zsh/datetime 2>/dev/null
# If zsh-autosuggestions is installed, configure it to use Atuin's search. If
# you'd like to override this, then add your config after the $(atuin init zsh)
# in your .zshrc
_zsh_autosuggest_strategy_atuin() {
suggestion=$(ATUIN_QUERY="$1" atuin search --cmd-only --limit 1 --search-mode prefix)
}
if [ -n "${ZSH_AUTOSUGGEST_STRATEGY:-}" ]; then
ZSH_AUTOSUGGEST_STRATEGY=("atuin" "${ZSH_AUTOSUGGEST_STRATEGY[@]}")
else
ZSH_AUTOSUGGEST_STRATEGY=("atuin")
fi
export ATUIN_SESSION=$(atuin uuid)
ATUIN_HISTORY_ID=""
_atuin_preexec() {
local id
id=$(atuin history start -- "$1")
export ATUIN_HISTORY_ID="$id"
__atuin_preexec_time=${EPOCHREALTIME-}
}
_atuin_precmd() {
local EXIT="$?" __atuin_precmd_time=${EPOCHREALTIME-}
[[ -z "${ATUIN_HISTORY_ID:-}" ]] && return
local duration=""
if [[ -n $__atuin_preexec_time && -n $__atuin_precmd_time ]]; then
printf -v duration %.0f $(((__atuin_precmd_time - __atuin_preexec_time) * 1000000000))
fi
(ATUIN_LOG=error atuin history end --exit $EXIT ${duration:+--duration=$duration} -- $ATUIN_HISTORY_ID &) >/dev/null 2>&1
export ATUIN_HISTORY_ID=""
}
_atuin_search() {
emulate -L zsh
zle -I
# swap stderr and stdout, so that the tui stuff works
# TODO: not this
local output
# shellcheck disable=SC2048
output=$(ATUIN_SHELL_ZSH=t ATUIN_LOG=error ATUIN_QUERY=$BUFFER atuin search $* -i 3>&1 1>&2 2>&3)
zle reset-prompt
if [[ -n $output ]]; then
RBUFFER=""
LBUFFER=$output
if [[ $LBUFFER == __atuin_accept__:* ]]
then
LBUFFER=${LBUFFER#__atuin_accept__:}
zle accept-line
fi
fi
}
_atuin_search_vicmd() {
_atuin_search --keymap-mode=vim-normal
}
_atuin_search_viins() {
_atuin_search --keymap-mode=vim-insert
}
_atuin_up_search() {
# Only trigger if the buffer is a single line
if [[ ! $BUFFER == *$'\n'* ]]; then
_atuin_search --shell-up-key-binding "$@"
else
zle up-line
fi
}
_atuin_up_search_vicmd() {
_atuin_up_search --keymap-mode=vim-normal
}
_atuin_up_search_viins() {
_atuin_up_search --keymap-mode=vim-insert
}
add-zsh-hook preexec _atuin_preexec
add-zsh-hook precmd _atuin_precmd
zle -N atuin-search _atuin_search
zle -N atuin-search-vicmd _atuin_search_vicmd
zle -N atuin-search-viins _atuin_search_viins
#zle -N atuin-up-search _atuin_up_search
#zle -N atuin-up-search-vicmd _atuin_up_search_vicmd
#zle -N atuin-up-search-viins _atuin_up_search_viins
# These are compatibility widget names for "atuin <= 17.2.1" users.
zle -N _atuin_search_widget _atuin_search
zle -N _atuin_up_search_widget _atuin_up_search
bindkey -M emacs '^r' atuin-search
bindkey -M viins '^r' atuin-search-viins
bindkey -M vicmd '/' atuin-search
#bindkey -M emacs '^[[A' atuin-up-search
#bindkey -M vicmd '^[[A' atuin-up-search-vicmd
#bindkey -M viins '^[[A' atuin-up-search-viins
#bindkey -M emacs '^[OA' atuin-up-search
#bindkey -M vicmd '^[OA' atuin-up-search-vicmd
#bindkey -M viins '^[OA' atuin-up-search-viins
#bindkey -M vicmd 'k' atuin-up-search-vicmd
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh