feat(keybindings): scorciatoie fg-select, clear-repeat e palette

This commit is contained in:
2026-09-29 18:25:51 +02:00
parent b6f7b6fc68
commit a4f3f73dc1
6 changed files with 201 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
function __clear_repeat --description "Clear the screen and re-run the last command"
set -l last $history[1]
or return
clear
commandline -r -- $last
commandline -f execute
end
+25
View File
@@ -0,0 +1,25 @@
function __clear_repeat_loop --description "Re-run the last command on a timer, clearing the screen each iteration"
set -l last $history[1]
or return
read -l -P "Ripeti quante volte? (invio = infinito) " count
read -l -P "Ogni quanti secondi? (default 2) " sec
set -l sec (string match -r '^[0-9]+$' -- $sec)
or set sec 2
if test -z "$count"; or test "$count" -eq 0
while true
clear
eval $last
sleep $sec
end
else
for i in (seq $count)
clear
eval $last
sleep $sec
end
end
commandline -f repaint
end
+19
View File
@@ -0,0 +1,19 @@
function __fg_select --description 'Bring a background/stopped job to foreground, picking via fzf when multiple'
set -l jobs_list (jobs | string match -r '^[0-9]+\t.*')
set -l n (count $jobs_list)
if test $n -eq 0
echo 'no background jobs' >&2
return 1
end
set -l picked
if test $n -eq 1
set picked $jobs_list[1]
else
set picked (printf '%s\n' $jobs_list | fzf --no-multi --prompt='fg> ')
or return 1
end
set -l id (string match -r '^([0-9]+)\t' -- $picked)[2]
fg %$id
end
+21
View File
@@ -3,4 +3,25 @@ function fish_user_key_bindings
if type -q atuin
bind -M default k _atuin_bind_up
end
# Ctrl+Shift+Z -> fg (fzf pick when multiple background jobs)
bind -M insert ctrl-shift-z '__fg_select; commandline -f repaint'
bind -M default ctrl-shift-z '__fg_select; commandline -f repaint'
# Ctrl+Alt+L -> clear and re-run last command
bind -M insert ctrl-alt-l '__clear_repeat'
bind -M default ctrl-alt-l '__clear_repeat'
# Ctrl+Alt+Shift+L -> clear and re-run last command on a timer
bind -M insert ctrl-alt-shift-l '__clear_repeat_loop'
bind -M default ctrl-alt-shift-l '__clear_repeat_loop'
# Palette: switch between utilities / shells (fzf)
# Ctrl+Alt+P -> utilities, Ctrl+Alt+S -> shells, Ctrl+Alt+Shift+P -> both
bind -M insert ctrl-alt-p 'palette utility; commandline -f repaint'
bind -M default ctrl-alt-p 'palette utility; commandline -f repaint'
bind -M insert ctrl-alt-s 'palette shell; commandline -f repaint'
bind -M default ctrl-alt-s 'palette shell; commandline -f repaint'
bind -M insert ctrl-alt-shift-p 'palette both; commandline -f repaint'
bind -M default ctrl-alt-shift-p 'palette both; commandline -f repaint'
end
+126
View File
@@ -0,0 +1,126 @@
function palette --description 'Command palette: switch between shells and/or utilities via fzf'
set -l mode both
if set -q argv[1]
set mode $argv[1]
end
set -l lines
switch $mode
case both
set lines (__palette_lines utility; __palette_lines shell)
case shell
set lines (__palette_lines shell)
case utility util
set lines (__palette_lines utility)
case '*'
echo "usage: palette [both|shell|utility]" >&2
return 1
end
test -n "$lines"; or return 1
set -l picked (printf '%s\n' $lines | fzf --no-multi --no-sort \
--delimiter=\t --nth=1 --with-nth=1 \
--prompt="palette($mode)> " \
--preview='echo -n {} | cut -f4')
or return 1
__palette_dispatch "$picked"
end
function __palette_lines -a kind
switch $kind
case shell
set -l shells fish:fish bash:bash zsh:zsh nushell:nu dash:dash tcsh:tcsh
for s in $shells
set -l name (string split : -- $s)[1]
set -l bin (string split : -- $s)[2]
command -q $bin; or continue
test $bin = fish; and continue
printf '%s\tshell\t%s\t%s\n' $name $bin "switch to $name (nested)"
end
case utility
printf 'cd\tutil\tcd\tzoxide: jump to a directory\n'
printf 'files\tutil\tfiles\tfd/fzf: pick a file or directory\n'
printf 'history\tutil\thistory\tatuin: search command history\n'
printf 'yazi\tutil\tyazi\tyazi: file manager\n'
printf 'git\tutil\tgit\tgit: common actions\n'
printf 'jobs\tutil\tjobs\tfg: pick a background job\n'
end
end
function __palette_dispatch
set -l f (string split \t -- $argv[1])
set -l kind $f[2]
set -l action $f[3]
switch $kind
case util
__palette_run_util $action
case shell
command $action
commandline -f repaint
end
end
function __palette_run_util -a action
switch $action
case cd
zi
case files
__palette_file
case history
if functions -q _atuin_search
_atuin_search
else if type -q atuin
commandline -r -- (atuin search --interactive)
end
case yazi
y
case jobs
__fg_select
case git
__palette_git
end
commandline -f repaint
end
function __palette_file
command -q fd; or return 1
set -l pick (fd -0 -H -t f -t d --max-depth=8 . 2>/dev/null | fzf --read0 \
--delimiter=/ --with-nth=-1 --prompt='files> ' \
--preview='test -d "{}"; and lls "{}" 2>/dev/null; or bat --color=always --line-range=:80 "{}" 2>/dev/null; or cat "{}" 2>/dev/null')
or return 1
if test -d "$pick"
cd "$pick"
else
commandline -r -- (string escape -- $pick)
end
end
function __palette_git
set -l lines \
(string join \t -- status 'git status') \
(string join \t -- log 'git log --oneline -20') \
(string join \t -- switch '__palette_git_switch') \
(string join \t -- diff 'git diff') \
(string join \t -- 'add -p' 'git add -p') \
(string join \t -- commit 'git commit') \
(string join \t -- push 'git push')
set -l pick (printf '%s\n' $lines | fzf --delimiter=\t --with-nth=1 --prompt='git> ')
or return 1
set -l cmd (string split \t -- $pick)[2]
switch $cmd
case __palette_git_switch
__palette_git_switch
case '*'
commandline -r -- $cmd
end
end
function __palette_git_switch
set -l branch (git for-each-ref --format='%(refname:short)' refs/heads | fzf --prompt='branch> ')
or return 1
git switch $branch
end