Update 2026-02-09

This commit is contained in:
2026-02-09 22:52:34 +02:00
parent 5324f54618
commit 13c0558017
50 changed files with 4171 additions and 117 deletions

View File

@@ -0,0 +1,20 @@
function __insert_unquoted_path --description "Insert a path token without quotes; preserve ~ when possible"
set -l p $argv[1]
# Rewrite /home/user/... -> ~/...
if string match -q -- "$HOME/*" $p
set p "~/"(string sub -s (math (string length -- "$HOME/") + 1) -- $p)
end
# Escape as a single token using backslashes (not quotes), so ~ keeps working.
# This produces things like: ~/My\ Dir/file.txt
set -l escaped (string escape --style=script -- $p)
# If fish decided to use quotes anyway, fall back to the raw (unescaped) string.
# (This avoids `'~/...'` which breaks tilde expansion.)
if string match -qr -- '^".*"$|^\'.*\'$' $escaped
set escaped $p
end
commandline -t -- $escaped
end

View File

@@ -0,0 +1,7 @@
function cd
if test (count $argv) -eq 0
z $HOME && eza -a --icons --group-directories-first
else
z $argv && eza -a --icons --group-directories-first
end
end

View File

@@ -0,0 +1,26 @@
function fish_user_key_bindings
# Accept autosuggestion and enter insert mode with Shift+A
bind -M default A vi_append_accept
# Tab completion with fzf (zsh fzf-tab style)
bind -M insert \t fzf_complete
bind -M default \t fzf_complete
# bind -M insert \co 'yazicd; commandline -f repaint'
# Ctrl+O for yazicd
# bind -M default \co 'yazicd; commandline -f repaint'
bind -M insert \co 'yazicd; printf "\e[5 q"; commandline -f repaint'
bind -M default \co 'yazicd; printf "\e[5 q"; commandline -f repaint'
# Ctrl+N to open nvim in current directory
bind -M insert \cn open_nvim_here
bind -M default \cn open_nvim_here
# Ctrl+F for sesh
bind -M insert \cF fzf_sesh_connect
bind -M default \cF fzf_sesh_connect
# Ctrl+E to edit command line in editor
bind -M insert \ce edit_command_buffer
bind -M default \ce edit_command_buffer
end

View File

@@ -0,0 +1,59 @@
function fzf_complete --description "fzf-tab style completion for fish"
set -l cmd (commandline -opc)
set -l token (commandline -t)
# Get all fish completions for the current command line
set -l completions (complete -C(commandline -cp))
# If no completions, fallback to default behavior
if test (count $completions) -eq 0
commandline -f complete
return
end
# If only one completion, insert it directly
if test (count $completions) -eq 1
set -l comp (string split \t -- $completions[1])[1]
__insert_unquoted_path $comp
commandline -f repaint
return
end
# Multiple completions - show in fzf
set -l selected (
printf '%s\n' $completions |
fzf --ansi \
--height=50% \
--reverse \
--border \
--cycle \
--info=inline \
--tabstop=4 \
--prompt=' ' \
--pointer='▶' \
--marker='✓' \
--bind 'tab:down,btab:up' \
--preview-window='right:50%:wrap' \
--preview='
set item (string split \t {})[1]
set real (eval echo $item 2>/dev/null || echo $item)
if test -d "$real"
eza --color=always -la "$real" 2>/dev/null
else if test -f "$real"
bat --color=always --style=numbers --line-range=:500 "$real" 2>/dev/null || cat "$real"
else if test -e "$real"
ls -lah "$real"
else
echo "$item"
end
'
)
if test -n "$selected"
# Extract the actual completion (first field before tab)
set -l comp (string split \t -- $selected)[1]
__insert_unquoted_path $comp
end
commandline -f repaint
end

View File

@@ -0,0 +1,46 @@
# Always installs bindings for insert and default mode for simplicity and b/c it has almost no side-effect
# https://gitter.im/fish-shell/fish-shell?at=60a55915ee77a74d685fa6b1
function fzf_configure_bindings --description "Installs the default key bindings for fzf.fish with user overrides passed as options."
# no need to install bindings if not in interactive mode or running tests
status is-interactive || test "$CI" = true; or return
set -f options_spec h/help 'directory=?' 'git_log=?' 'git_status=?' 'history=?' 'processes=?' 'variables=?'
argparse --max-args=0 --ignore-unknown $options_spec -- $argv 2>/dev/null
if test $status -ne 0
echo "Invalid option or a positional argument was provided." >&2
_fzf_configure_bindings_help
return 22
else if set --query _flag_help
_fzf_configure_bindings_help
return
else
# Initialize with default key sequences and then override or disable them based on flags
# index 1 = directory, 2 = git_log, 3 = git_status, 4 = history, 5 = processes, 6 = variables
set -f key_sequences \e\cf \e\cl \e\cs \cr \e\cp \cv # \c = control, \e = escape
set --query _flag_directory && set key_sequences[1] "$_flag_directory"
set --query _flag_git_log && set key_sequences[2] "$_flag_git_log"
set --query _flag_git_status && set key_sequences[3] "$_flag_git_status"
set --query _flag_history && set key_sequences[4] "$_flag_history"
set --query _flag_processes && set key_sequences[5] "$_flag_processes"
set --query _flag_variables && set key_sequences[6] "$_flag_variables"
# If fzf bindings already exists, uninstall it first for a clean slate
if functions --query _fzf_uninstall_bindings
_fzf_uninstall_bindings
end
for mode in default insert
test -n $key_sequences[1] && bind --mode $mode $key_sequences[1] _fzf_search_directory
test -n $key_sequences[2] && bind --mode $mode $key_sequences[2] _fzf_search_git_log
test -n $key_sequences[3] && bind --mode $mode $key_sequences[3] _fzf_search_git_status
test -n $key_sequences[4] && bind --mode $mode $key_sequences[4] _fzf_search_history
test -n $key_sequences[5] && bind --mode $mode $key_sequences[5] _fzf_search_processes
test -n $key_sequences[6] && bind --mode $mode $key_sequences[6] "$_fzf_search_vars_command"
end
function _fzf_uninstall_bindings --inherit-variable key_sequences
bind --erase -- $key_sequences
bind --erase --mode insert -- $key_sequences
end
end
end

View File

@@ -0,0 +1,22 @@
function fzf_sesh_connect --description "fzf-powered sesh session selector"
set -l session (
sesh list --icons | fzf-tmux -p 80%,70% \
--no-sort --ansi \
--border-label ' sesh ' \
--prompt '⚡ ' \
--header ' ^a all ^t tmux ^g configs ^x zoxide ^d tmux kill ^f find' \
--bind 'tab:down,btab:up' \
--bind 'ctrl-a:change-prompt(⚡ )+reload(sesh list --icons)' \
--bind 'ctrl-t:change-prompt(🪟 )+reload(sesh list -t --icons)' \
--bind 'ctrl-g:change-prompt(⚙️ )+reload(sesh list -c --icons)' \
--bind 'ctrl-x:change-prompt(📁 )+reload(sesh list -z --icons)' \
--bind 'ctrl-f:change-prompt(🔎 )+reload(fd -H -d 2 -t d -E .Trash . ~)' \
--bind 'ctrl-d:execute(tmux kill-session -t $(echo {} | cut -d\" \" -f2-))+change-prompt(⚡ )+reload(sesh list --icons)' \
--preview-window 'right:55%' \
--preview 'sesh preview {}'
)
if test -n "$session"
sesh connect "$session"
end
end

View File

@@ -0,0 +1,9 @@
function lfcd
set tmp (mktemp -uq)
lf -last-dir-path="$tmp" $argv
if test -f "$tmp"
set dir (cat "$tmp")
test -d "$dir" && test "$dir" != (pwd) && z "$dir"
end
rm -f $tmp 2>/dev/null
end

View File

@@ -0,0 +1,10 @@
function open_nvim_here --description "Open nvim in cwd"
# Run nvim ($EDITOR) on the current dir
command $EDITOR .
# After returning, force fish to resync its vi mode + cursor
commandline -f vi-default 2>/dev/null
commandline -f vi-insert 2>/dev/null
printf '\e[5 q'
commandline -f repaint 2>/dev/null
end

View File

@@ -0,0 +1,3 @@
function tmux-window-name
$TMUX_PLUGIN_MANAGER_PATH/tmux-window-name/scripts/rename_session_windows.py &
end

View File

@@ -0,0 +1,8 @@
function vi_append_accept --description "Accept autosuggestion and append in vi mode"
commandline -f accept-autosuggestion
commandline -f end-of-line
set fish_bind_mode insert
fish_vi_cursor insert
commandline -f end-of-line
commandline -f repaint
end

View File

@@ -0,0 +1,13 @@
function yazicd --description "yazi wrapper that cd's to last directory"
set -l tmp (mktemp -t "yazi-cwd.XXXXXX")
command yazi $argv --cwd-file="$tmp"
if read -z cwd < "$tmp"; and [ "$cwd" != "$PWD" ]; and test -d "$cwd"
z -- "$cwd"
eza -a --icons --group-directories-first
end
rm -f -- "$tmp" >/dev/null
# restore insert cursor (beam)
printf '\e[5 q'
commandline -f repaint 2>/dev/null
end