From cafb3f1ecb51192af5dbe26a7c6975dca197a58f Mon Sep 17 00:00:00 2001 From: Davide Frattarolo Date: Mon, 20 Apr 2026 09:40:17 +0200 Subject: [PATCH] Varius --- conf.d/atuin.fish | 87 +++++++++++++ conf.d/fish_frozen_key_bindings.fish | 14 ++ conf.d/fnm.fish | 1 + conf.d/myabbrs.fish | 9 +- conf.d/pyenv.fish | 21 ++- conf.d/zoxide.fish | 16 ++- config.fish | 18 ++- functions/duh.fish | 12 ++ functions/ezals.fish | 3 - functions/fish_preexec.fish | 3 + functions/fish_prompt.fish | 176 +++++++++++++++++--------- functions/fish_right_prompt.fish | 2 + functions/fish_user_key_bindings.fish | 6 + functions/git-refresh.fish | 4 +- functions/lls.fish | 3 + functions/wt.fish | 15 +++ functions/y.fish | 15 ++- functions/zjs.fish | 8 ++ 18 files changed, 321 insertions(+), 92 deletions(-) create mode 100644 conf.d/atuin.fish create mode 100644 conf.d/fish_frozen_key_bindings.fish create mode 100644 conf.d/fnm.fish create mode 100644 functions/duh.fish delete mode 100644 functions/ezals.fish create mode 100644 functions/fish_preexec.fish create mode 100644 functions/fish_right_prompt.fish create mode 100644 functions/fish_user_key_bindings.fish create mode 100644 functions/lls.fish create mode 100644 functions/wt.fish create mode 100644 functions/zjs.fish diff --git a/conf.d/atuin.fish b/conf.d/atuin.fish new file mode 100644 index 0000000..faa507a --- /dev/null +++ b/conf.d/atuin.fish @@ -0,0 +1,87 @@ +set -gx ATUIN_SESSION (atuin uuid) +set --erase ATUIN_HISTORY_ID + +function _atuin_preexec --on-event fish_preexec + if not test -n "$fish_private_mode" + set -g ATUIN_HISTORY_ID (atuin history start -- "$argv[1]") + end +end + +function _atuin_postexec --on-event fish_postexec + set -l s $status + + if test -n "$ATUIN_HISTORY_ID" + ATUIN_LOG=error atuin history end --exit $s -- $ATUIN_HISTORY_ID &>/dev/null & + disown + end + + set --erase ATUIN_HISTORY_ID +end + +function _atuin_search + set -l keymap_mode + switch $fish_key_bindings + case fish_vi_key_bindings + switch $fish_bind_mode + case default + set keymap_mode vim-normal + case insert + set keymap_mode vim-insert + end + case '*' + set keymap_mode emacs + end + + # In fish 3.4 and above we can use `"$(some command)"` to keep multiple lines separate; + # but to support fish 3.3 we need to use `(some command | string collect)`. + # https://fishshell.com/docs/current/relnotes.html#id24 (fish 3.4 "Notable improvements and fixes") + set -l ATUIN_H (ATUIN_SHELL=fish ATUIN_LOG=error ATUIN_QUERY=(commandline -b) atuin search --keymap-mode=$keymap_mode $argv -i 3>&1 1>&2 2>&3 | string collect) + + if test -n "$ATUIN_H" + if string match --quiet '__atuin_accept__:*' "$ATUIN_H" + set -l ATUIN_HIST (string replace "__atuin_accept__:" "" -- "$ATUIN_H" | string collect) + commandline -r "$ATUIN_HIST" + commandline -f repaint + commandline -f execute + return + else + commandline -r "$ATUIN_H" + end + end + + commandline -f repaint +end + +function _atuin_bind_up + # Fallback to fish's builtin up-or-search if we're in search or paging mode + if commandline --search-mode; or commandline --paging-mode + up-or-search + return + end + + # Only invoke atuin if we're on the top line of the command + set -l lineno (commandline --line) + + switch $lineno + case 1 + _atuin_search --shell-up-key-binding + case '*' + up-or-search + end +end + +if string match -q '4.*' $version + bind ctrl-r _atuin_search + bind up _atuin_bind_up + if bind -M insert >/dev/null 2>&1 + bind -M insert ctrl-r _atuin_search + bind -M insert up _atuin_bind_up + end +else + bind \cr _atuin_search + bind -k up _atuin_bind_up; bind \eOA _atuin_bind_up; bind \e\[A _atuin_bind_up + if bind -M insert >/dev/null 2>&1 + bind -M insert \cr _atuin_search + bind -M insert -k up _atuin_bind_up; bind -M insert \eOA _atuin_bind_up; bind -M insert \e\[A _atuin_bind_up + end +end diff --git a/conf.d/fish_frozen_key_bindings.fish b/conf.d/fish_frozen_key_bindings.fish new file mode 100644 index 0000000..dfed4d6 --- /dev/null +++ b/conf.d/fish_frozen_key_bindings.fish @@ -0,0 +1,14 @@ +# This file was created by fish when upgrading to version 4.3, to migrate +# the 'fish_key_bindings' variable from its old default scope (universal) +# to its new default scope (global). We recommend you delete this file +# and configure key bindings in ~/.config/fish/config.fish if needed. + +set --global fish_key_bindings fish_vi_key_bindings + +# Prior to version 4.3, fish shipped an event handler that runs +# `set --universal fish_key_bindings fish_default_key_bindings` +# whenever the fish_key_bindings variable is erased. +# This means that as long as any fish < 4.3 is still running on this system, +# we cannot complete the migration. +# As a workaround, erase the universal variable at every shell startup. +set --erase --universal fish_key_bindings diff --git a/conf.d/fnm.fish b/conf.d/fnm.fish new file mode 100644 index 0000000..abdb15a --- /dev/null +++ b/conf.d/fnm.fish @@ -0,0 +1 @@ +eval "$(fnm env)" diff --git a/conf.d/myabbrs.fish b/conf.d/myabbrs.fish index 34d557c..c172a79 100644 --- a/conf.d/myabbrs.fish +++ b/conf.d/myabbrs.fish @@ -3,14 +3,17 @@ abbr -a -- opc opencode abbr -a -- opcc opencode -c abbr -a -- cl clear abbr -a -- g git -abbr -a -- l ezals -abbr -a -- ll 'ezals -TL2' +abbr -a -- l lls +abbr -a -- ls lls +abbr -a -- ll 'lls -TL2' abbr -a -- q exit abbr -a -- v nvim abbr -a -- vs nvim --server /tmp/nvim-server.sock abbr -a -- vo nvim --server /tmp/nvim-server.sock --remote-tab -abbr -a -- kc kubectl +abbr -a -- kc kubectl --context abbr -a -- kcc kubectl ctx abbr -a -- zj zellij abbr -a -- sysc systemctl abbr -a -- syscu systemctl --user +abbr -a -- diswn disown \(jobs -p\) +abbr -a -- rg rg --hyperlink-format kitty diff --git a/conf.d/pyenv.fish b/conf.d/pyenv.fish index 3956ea8..1840c9e 100644 --- a/conf.d/pyenv.fish +++ b/conf.d/pyenv.fish @@ -1,7 +1,16 @@ -set -Ux PYENV_ROOT $HOME/.pyenv -set -U fish_user_paths $PYENV_ROOT/bin $fish_user_paths +while set pyenv_index (contains -i -- "/home/df/.pyenv/shims" $PATH) +set -eg PATH[$pyenv_index]; end; set -e pyenv_index +set -gx PATH '/home/df/.pyenv/shims' $PATH +set -gx PYENV_SHELL fish +command pyenv rehash +function pyenv + set command $argv[1] + set -e argv[1] -# Load pyenv automatically by appending -# the following to ~/.config/fish/config.fish: - -# Restart your shell for the changes to take effect. + switch "$command" + case rehash shell + source (pyenv "sh-$command" $argv|psub) + case "*" + command pyenv "$command" $argv + end +end diff --git a/conf.d/zoxide.fish b/conf.d/zoxide.fish index 1d10e44..1e5d4d5 100644 --- a/conf.d/zoxide.fish +++ b/conf.d/zoxide.fish @@ -11,7 +11,11 @@ end # A copy of fish's internal cd function. This makes it possible to use # `alias cd=z` without causing an infinite loop. if ! builtin functions --query __zoxide_cd_internal - string replace --regex -- '^function cd\s' 'function __zoxide_cd_internal ' <$__fish_data_dir/functions/cd.fish | source + if status list-files functions/cd.fish &>/dev/null + status get-file functions/cd.fish | string replace --regex -- '^function cd\s' 'function __zoxide_cd_internal ' | source + else + string replace --regex -- '^function cd\s' 'function __zoxide_cd_internal ' <$__fish_data_dir/functions/cd.fish | source + end end # cd + custom logic based on the value of _ZO_ECHO. @@ -86,11 +90,13 @@ end # Commands for zoxide. Disable these using --no-cmd. # -abbr --erase z &>/dev/null -alias z=__zoxide_z +abbr --erase cd &>/dev/null +complete --erase --command cd +alias cd=__zoxide_z -abbr --erase zi &>/dev/null -alias zi=__zoxide_zi +abbr --erase cdi &>/dev/null +complete --erase --command cdi +alias cdi=__zoxide_zi # ============================================================================= # diff --git a/config.fish b/config.fish index 02727fb..2b629f9 100644 --- a/config.fish +++ b/config.fish @@ -9,8 +9,6 @@ set -g TERM xterm-256color #set -gx NVIM_LISTEN_ADDRESS /tmp/nvim-server.sock # Set correct TERM and TERMINAL for kitty -set -gx TERM xterm-kitty -set -gx TERMINAL kitty if status is-interactive # Commands to run in interactive sessions can go here @@ -31,7 +29,13 @@ if status is-interactive set -g fish_sequence_key_delay_ms 200 bind -M insert -m default j,k cancel repaint-mode - bind -M insert \cn \\t + + # \c Ctrl, \e Alt + bind -M insert \cy 'y; commandline -f repaint' + bind -M insert \cv 'nvim; commandline -f repaint' + bind -M insert \cz 'zellij; commandline -f repaint' + bind -M insert \cx 'set -l dir (zoxide query -l | fzf --height 40% --reverse); and cd $dir; commandline -f repaint' + bind -M insert \cu forward-char set -q KREW_ROOT; and set -gx PATH $PATH $KREW_ROOT/.krew/bin; or set -gx PATH $PATH $HOME/.krew/bin set -U autovenv_enable yes @@ -63,3 +67,11 @@ set -gx PATH $PATH /home/df/.lmstudio/bin # bun set --export BUN_INSTALL "$HOME/.bun" set --export PATH $BUN_INSTALL/bin $PATH + +# Go +fish_add_path $HOME/go/bin + +# Cargo (Rust) +fish_add_path $HOME/.cargo/bin + +alias claude 'claude --allow-dangerously-skip-permissions' diff --git a/functions/duh.fish b/functions/duh.fish new file mode 100644 index 0000000..9723cb2 --- /dev/null +++ b/functions/duh.fish @@ -0,0 +1,12 @@ +function duh --description "Disk usage utility" + if test (count $argv) -eq 0 + #echo "duh: missing operand" >&2 + #return 1 + set fold '.' + else + set fold $argv + end + + + du -hd1 $fold | sort -h +end diff --git a/functions/ezals.fish b/functions/ezals.fish deleted file mode 100644 index c632b10..0000000 --- a/functions/ezals.fish +++ /dev/null @@ -1,3 +0,0 @@ -function ezals --wraps='eza --icons --git --no-user --octal-permissions --no-permissions --group-directories-first -s name -lah' --description 'Base exa' - eza --icons --git --no-user --octal-permissions --no-permissions --group-directories-first -s name --hyperlink -lah $argv -end diff --git a/functions/fish_preexec.fish b/functions/fish_preexec.fish new file mode 100644 index 0000000..af09449 --- /dev/null +++ b/functions/fish_preexec.fish @@ -0,0 +1,3 @@ +function fish_preexec --on-event fish_preexec + set -g __fish_prompt_command_ran 1 +end diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 5199d0a..0ba1338 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -1,69 +1,119 @@ function fish_prompt --description 'Write out the prompt' - set -l last_pipestatus $pipestatus - set -lx __fish_last_status $status # Export for __fish_print_pipestatus. - - if not set -q __fish_git_prompt_show_informative_status - set -g __fish_git_prompt_show_informative_status 1 - end - if not set -q __fish_git_prompt_hide_untrackedfiles - set -g __fish_git_prompt_hide_untrackedfiles 1 - end - if not set -q __fish_git_prompt_color_branch - set -g __fish_git_prompt_color_branch magenta --bold - end - if not set -q __fish_git_prompt_showupstream - set -g __fish_git_prompt_showupstream informative - end - if not set -q __fish_git_prompt_color_dirtystate - set -g __fish_git_prompt_color_dirtystate blue - end - if not set -q __fish_git_prompt_color_stagedstate - set -g __fish_git_prompt_color_stagedstate yellow - end - if not set -q __fish_git_prompt_color_invalidstate - set -g __fish_git_prompt_color_invalidstate red - end - if not set -q __fish_git_prompt_color_untrackedfiles - set -g __fish_git_prompt_color_untrackedfiles $fish_color_normal - end - if not set -q __fish_git_prompt_color_cleanstate - set -g __fish_git_prompt_color_cleanstate green --bold - end - - set -l color_cwd - set -l suffix - if functions -q fish_is_root_user; and fish_is_root_user - if set -q fish_color_cwd_root - set color_cwd $fish_color_cwd_root - else - set color_cwd $fish_color_cwd - end - set suffix '#' + set -l last_pipestatus $pipestatus + set -lx __fish_last_status $status # Export for __fish_print_pipestatus. + + # Blank line before prompt only after a command was executed + if set -q __fish_prompt_command_ran + echo + set -e __fish_prompt_command_ran + end + + if not set -q __fish_git_prompt_show_informative_status + set -g __fish_git_prompt_show_informative_status 1 + end + if not set -q __fish_git_prompt_hide_untrackedfiles + set -g __fish_git_prompt_hide_untrackedfiles 1 + end + if not set -q __fish_git_prompt_color_branch + set -g __fish_git_prompt_color_branch magenta --bold + end + if not set -q __fish_git_prompt_showupstream + set -g __fish_git_prompt_showupstream informative + end + if not set -q __fish_git_prompt_color_dirtystate + set -g __fish_git_prompt_color_dirtystate blue + end + if not set -q __fish_git_prompt_color_stagedstate + set -g __fish_git_prompt_color_stagedstate yellow + end + if not set -q __fish_git_prompt_color_invalidstate + set -g __fish_git_prompt_color_invalidstate red + end + if not set -q __fish_git_prompt_color_untrackedfiles + set -g __fish_git_prompt_color_untrackedfiles $fish_color_normal + end + if not set -q __fish_git_prompt_color_cleanstate + set -g __fish_git_prompt_color_cleanstate green --bold + end + + set -l color_cwd + if functions -q fish_is_root_user; and fish_is_root_user + if set -q fish_color_cwd_root + set color_cwd $fish_color_cwd_root else - set color_cwd $fish_color_cwd - set suffix '$' + set color_cwd $fish_color_cwd end - - # PWD - set_color $color_cwd - echo -n (prompt_pwd) + else + set color_cwd $fish_color_cwd + end + + # Time + set_color brblack + echo -n (date '+%H:%M:%S') + set_color normal + echo -n ' ' + + # Last command duration + if test -n "$CMD_DURATION" -a "$CMD_DURATION" -gt 0 + set -l secs (math --scale=0 "$CMD_DURATION / 1000") + if test $secs -gt 0 + set_color yellow + if test $secs -ge 60 + set -l mins (math --scale=0 "$secs / 60") + set -l rem (math --scale=0 "$secs % 60") + echo -n $mins"m"$rem"s " + else + echo -n $secs"s " + end + set_color normal + end + end + + # User@host + set_color brgreen + echo -n $USER + set_color normal + echo -n @ + set_color brblue + echo -n (prompt_hostname) + set_color normal + echo -n ' ' + + # PWD + set_color $color_cwd + echo -n (prompt_pwd) + set_color normal + + # Git + Kubernetes cluster + set -l vcs (fish_vcs_prompt) + if test -n "$vcs" + printf '%s' $vcs + # Kubernetes context + if command -sq kubectl + set -l kctx (kubectl config current-context 2>/dev/null) + if test -n "$kctx" + set_color brblack + echo -n " [$kctx]" + set_color normal + end + end + end + echo -n ' ' + + set -l status_color (set_color $fish_color_status) + set -l statusb_color (set_color --bold $fish_color_status) + set -l prompt_status (__fish_print_pipestatus "[" "]" "|" "$status_color" "$statusb_color" $last_pipestatus) + echo -n $prompt_status + set_color normal + + # Background jobs counter + set -l jobs_count (count (jobs -p)) + if test $jobs_count -gt 0 + set_color yellow + echo -n "[$jobs_count] " set_color normal - - printf '%s ' (fish_vcs_prompt) - - set -l status_color (set_color $fish_color_status) - set -l statusb_color (set_color --bold $fish_color_status) - set -l prompt_status (__fish_print_pipestatus "[" "]" "|" "$status_color" "$statusb_color" $last_pipestatus) - echo -n $prompt_status - set_color normal + end - # Background jobs counter - set -l jobs_count (count (jobs -p)) - if test $jobs_count -gt 0 - set_color yellow - echo -n "[$jobs_count] " - set_color normal - end - - echo -n "$suffix " + # Prompt on new line + echo end diff --git a/functions/fish_right_prompt.fish b/functions/fish_right_prompt.fish new file mode 100644 index 0000000..c1b019e --- /dev/null +++ b/functions/fish_right_prompt.fish @@ -0,0 +1,2 @@ +function fish_right_prompt +end diff --git a/functions/fish_user_key_bindings.fish b/functions/fish_user_key_bindings.fish new file mode 100644 index 0000000..40b3988 --- /dev/null +++ b/functions/fish_user_key_bindings.fish @@ -0,0 +1,6 @@ +function fish_user_key_bindings + # Bind k to Atuin search in vim normal mode + if type -q atuin + bind -M default k _atuin_bind_up + end +end diff --git a/functions/git-refresh.fish b/functions/git-refresh.fish index fa76bdd..d5c005d 100644 --- a/functions/git-refresh.fish +++ b/functions/git-refresh.fish @@ -5,8 +5,8 @@ # * $path package path # * $dependencies package dependencies -# Timeout in seconds before allowing another git pull (default: 15 minutes) -set -q GIT_REFRESH_TIMEOUT; or set -g GIT_REFRESH_TIMEOUT 900 +# Timeout in seconds before allowing another git pull (default: 60 minutes) +set -q GIT_REFRESH_TIMEOUT; or set -g GIT_REFRESH_TIMEOUT 3600 function git-refresh --on-variable PWD \ --description "git pull automatically wherever inside a git repository" diff --git a/functions/lls.fish b/functions/lls.fish new file mode 100644 index 0000000..b02f9e8 --- /dev/null +++ b/functions/lls.fish @@ -0,0 +1,3 @@ +function lls --wraps='eza --icons --git --no-user --octal-permissions --no-permissions --group-directories-first -s name -lah' --description 'Base exa' + eza --icons --git --no-user --octal-permissions --no-permissions --group-directories-first -s name --hyperlink -lah $argv +end diff --git a/functions/wt.fish b/functions/wt.fish new file mode 100644 index 0000000..dc2fdcf --- /dev/null +++ b/functions/wt.fish @@ -0,0 +1,15 @@ +# worktrunk shell integration for fish +# Sources full integration from binary on first use. +# Docs: https://worktrunk.dev/config/#shell-integration +# Check: wt config show | Uninstall: wt config shell uninstall + +function wt + command wt config shell init fish | source + # Check both command exit code ($pipestatus[1]) and source exit code ($pipestatus[2]) + # If source fails, the function isn't replaced and we'd infinite-loop calling ourselves + set -l wt_status $pipestatus[1] + set -l source_status $pipestatus[2] + test $wt_status -eq 0; or return $wt_status + test $source_status -eq 0; or return $source_status + wt $argv +end diff --git a/functions/y.fish b/functions/y.fish index 8d6d44a..01cdde2 100644 --- a/functions/y.fish +++ b/functions/y.fish @@ -1,9 +1,10 @@ function y - set tmp (mktemp -t "yazi-cwd.XXXXXX") - yazi $argv --cwd-file="$tmp" - if read -z cwd < "$tmp"; and [ -n "$cwd" ]; and [ "$cwd" != "$PWD" ] - builtin cd -- "$cwd" - end - rm -f -- "$tmp" + set tmp (mktemp -t "yazi-cwd.XXXXXX") + yazi $argv --cwd-file="$tmp" + if read -z cwd <"$tmp"; and [ -n "$cwd" ]; and [ "$cwd" != "$PWD" ] + builtin cd -- "$cwd" + end + rm -f -- "$tmp" + clear + lls end - diff --git a/functions/zjs.fish b/functions/zjs.fish new file mode 100644 index 0000000..e22d66e --- /dev/null +++ b/functions/zjs.fish @@ -0,0 +1,8 @@ +function zjs -d "Avvia zellij in una nuova finestra TERM" + if test (count $argv) -eq 0 + $TERM -e zellij & + else + $TERM -e zellij attach -c $argv[1] & + end + disown +end