From c698547b3b320bac379c6f8823007e4f6d81a8e9 Mon Sep 17 00:00:00 2001 From: Antoine Stevan <44101798+amtoine@users.noreply.github.com> Date: Fri, 26 May 2023 20:33:37 +0200 Subject: [PATCH] FEATURE: add some fuzzy keybindings (#512) * add `history`, `directories` and `modules` fuzzy keybindings * add a little README for the bindings --- custom-menus/fuzzy/README.md | 4 ++++ custom-menus/fuzzy/directory.nu | 16 ++++++++++++++++ custom-menus/fuzzy/history.nu | 17 +++++++++++++++++ custom-menus/fuzzy/modules.nu | 24 ++++++++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 custom-menus/fuzzy/README.md create mode 100644 custom-menus/fuzzy/directory.nu create mode 100644 custom-menus/fuzzy/history.nu create mode 100644 custom-menus/fuzzy/modules.nu diff --git a/custom-menus/fuzzy/README.md b/custom-menus/fuzzy/README.md new file mode 100644 index 0000000..5bb31d7 --- /dev/null +++ b/custom-menus/fuzzy/README.md @@ -0,0 +1,4 @@ +a few keybindings using the new `input list --fuzzy` command to interactively select what to do: +- `history.nu`: select a command from history +- `directories.nu`: select a directory, recursively from the current `PWD` +- `modules.nu`: recursively select and insert a `.nu` module from `NU_LIB_DIRS` inside a `use ...` command, ready to be run by pressing enter diff --git a/custom-menus/fuzzy/directory.nu b/custom-menus/fuzzy/directory.nu new file mode 100644 index 0000000..f1cf300 --- /dev/null +++ b/custom-menus/fuzzy/directory.nu @@ -0,0 +1,16 @@ +{ + name: fuzzy_dir + modifier: control + keycode: char_s + mode: [emacs, vi_normal, vi_insert] + event: { + send: executehostcommand + cmd: "commandline -a ( + ls **/* + | where type == dir + | get name + | input list --fuzzy + $'Please choose a (ansi magenta)directory(ansi reset) to (ansi cyan_underline)insert(ansi reset):' + )" + } +} diff --git a/custom-menus/fuzzy/history.nu b/custom-menus/fuzzy/history.nu new file mode 100644 index 0000000..5f87fe2 --- /dev/null +++ b/custom-menus/fuzzy/history.nu @@ -0,0 +1,17 @@ +{ + name: fuzzy_history + modifier: control + keycode: char_h + mode: [emacs, vi_normal, vi_insert] + event: { + send: executehostcommand + cmd: "commandline ( + history + | each { |it| $it.command } + | uniq + | reverse + | input list --fuzzy + $'Please choose a (ansi magenta)command from history(ansi reset):' + )" + } +} diff --git a/custom-menus/fuzzy/modules.nu b/custom-menus/fuzzy/modules.nu new file mode 100644 index 0000000..3f1b711 --- /dev/null +++ b/custom-menus/fuzzy/modules.nu @@ -0,0 +1,24 @@ +{ + name: fuzzy_module + modifier: control + keycode: char_u + mode: [emacs, vi_normal, vi_insert] + event: { + send: executehostcommand + cmd: ' + commandline --replace "use " + commandline --insert ( + $env.NU_LIB_DIRS + | each {|dir| + ls ($dir | path join "**" "*.nu") + | get name + | str replace $dir "" + | str trim -c "/" + } + | flatten + | input list --fuzzy + $"Please choose a (ansi magenta)module(ansi reset) to (ansi cyan_underline)load(ansi reset):" + ) + ' + } +}