From 4eae09ee7144fe65b48ec18b81ae9f10365580da Mon Sep 17 00:00:00 2001 From: Matei Adriel Date: Fri, 9 Feb 2024 20:15:32 +0100 Subject: [PATCH] Move fish keybinds to nix file --- home/features/cli/fish/config.fish | 29 +------------------------- home/features/cli/fish/default.nix | 33 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/home/features/cli/fish/config.fish b/home/features/cli/fish/config.fish index 6190dd0..502e154 100644 --- a/home/features/cli/fish/config.fish +++ b/home/features/cli/fish/config.fish @@ -20,37 +20,10 @@ set fish_greeting # }}} # {{{ Keybinds function fish_user_key_bindings - # {{{ Use vim-style keybinds - # Use the vim keybinds fish_vi_key_bindings + fish_nix_key_bindings - bind -e -M insert -k f10 # unbinds f10 bind -M insert -m default -k f10 'commandline -f repaint' # Exit insert mode with - # }}} - # {{{ C-x to clear screen - bind -M default \cx "clear && commandline -f repaint" - bind -M insert \cx "clear && commandline -f repaint" - # }}} - # {{{ C-z to run `fg` - bind -M default \cz "fg && commandline -f repaint" - bind -M insert \cz "fg && commandline -f repaint" - # }}} - # {{{ C-enter to run command through less - bind -M default \e\[13\;2u "commandline -a ' | less' && commandline -f execute" - bind -M insert \e\[13\;2u "commandline -a ' | less' && commandline -f execute" - # }}} - # {{{ C-g to open neogit - bind -M default \cg "nvim +Neogit" - bind -M insert \cg "nvim +Neogit" - # }}} - # {{{ C-e to open $EDITOR - bind -M default \ce "$EDITOR" - bind -M insert \ce "$EDITOR" - # }}} - # {{{ C-S-e to open commandline in $EDITOR - bind -M default \e\[69\;5u "commandline -f edit_command_buffer" - bind -M insert \e\[69\;5u "commandline -f edit_command_buffer" - # }}} end # }}} # {{{ Helpers diff --git a/home/features/cli/fish/default.nix b/home/features/cli/fish/default.nix index 92650c3..0365bdb 100644 --- a/home/features/cli/fish/default.nix +++ b/home/features/cli/fish/default.nix @@ -1,4 +1,32 @@ { pkgs, config, lib, ... }: +let + repaint = "commandline -f repaint"; + fishKeybinds = { + # C-x to clear screen + "\\cx" = "clear && ${repaint}"; + # C-z to return to background process + "\\cz" = "fg && ${repaint}"; + # C-y to yank current command + # TODO: make this work in xorg as well + "\\cy" = "wl-copy \$(commandline)"; + # C-e to launch $EDITOR + "\\ce" = "$EDITOR"; + # C-S-e to edit commandline using $EDITOR + "\\e\\[69\\;5u" = "edit_command_buffer"; + # C-enter to run command through a pager + "\\e\\[13\\;2u" = "commandline -a ' | $PAGER' && commandline -f execute"; + # C-g to open neogit + "\\cg" = "nvim +Neogit"; + }; + + mkKeybind = key: value: + let escaped = lib.escapeShellArg value; + in + '' + bind -M default ${key} ${escaped} + bind -M insert ${key} ${escaped} + ''; +in { # {{{ Fzf programs.fzf = { @@ -21,6 +49,11 @@ programs.fish = { enable = true; interactiveShellInit = '' + # ❄️ Fish keybinds generated using nix ^~^ + function fish_nix_key_bindings + ${lib.concatStringsSep "\n" (lib.mapAttrsToList mkKeybind fishKeybinds)} + end + ${builtins.readFile ./config.fish} # Modify nix-shell to use `fish` as it's default shell