From a507b25c85e5be960bd34cc9bea01fd3f22641ee Mon Sep 17 00:00:00 2001 From: Prad Nukala Date: Sat, 29 Aug 2026 17:17:17 -0400 Subject: [PATCH] feat(config): add down-arrow binding for silent pj invocation on empty prompt --- dot_config/fish/functions/_pj_bind_down.fish | 18 ++++++++++++++++++ .../fish/functions/fish_user_key_bindings.fish | 5 +++++ dot_config/fish/functions/pj.fish | 4 +++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 dot_config/fish/functions/_pj_bind_down.fish diff --git a/dot_config/fish/functions/_pj_bind_down.fish b/dot_config/fish/functions/_pj_bind_down.fish new file mode 100644 index 0000000..87b8669 --- /dev/null +++ b/dot_config/fish/functions/_pj_bind_down.fish @@ -0,0 +1,18 @@ +function _pj_bind_down --description "down arrow: pj on an idle empty prompt, else the preset down-or-search" + # Mirror of atuin's up binding (atuin owns up, this owns down). Everything + # that legitimately needs the arrow keys keeps them: + # - non-empty buffer → multiline cursor movement / forward history search + # - paging mode → tab-completion pager navigation (tab on an empty + # line opens the pager with an empty buffer) + # - search mode → history-search navigation + set -l buf (commandline | string collect) + if test -n "$buf"; or commandline --paging-mode; or commandline --search-mode + commandline -f down-or-search + return + end + + # PJ_QUIET keeps pj silent when the tree has no package.json, so down is a + # no-op outside JS projects instead of printing an error on every press. + PJ_QUIET=1 pj + commandline -f repaint +end diff --git a/dot_config/fish/functions/fish_user_key_bindings.fish b/dot_config/fish/functions/fish_user_key_bindings.fish index 1e2e40b..2f1c283 100644 --- a/dot_config/fish/functions/fish_user_key_bindings.fish +++ b/dot_config/fish/functions/fish_user_key_bindings.fish @@ -19,6 +19,11 @@ function fish_user_key_bindings bind -M $mode ctrl-p 'pj; commandline -f repaint' bind -M $mode ctrl-a 'omp; commandline -f repaint' + # Arrow keys: atuin owns up (bound from config.fish, survives the + # fish_vi_key_bindings reset above because that only erases presets), + # down runs pj — but only on an idle, empty prompt; see _pj_bind_down. + bind -M $mode down _pj_bind_down + # ctrl-f: pick file(s) with television and open in nvim. bind -M $mode ctrl-f 'yy; commandline -f repaint' bind -M $mode ctrl-g 'lazygit; commandline -f repaint' diff --git a/dot_config/fish/functions/pj.fish b/dot_config/fish/functions/pj.fish index d7a799e..dd37c21 100644 --- a/dot_config/fish/functions/pj.fish +++ b/dot_config/fish/functions/pj.fish @@ -12,7 +12,9 @@ function pj --description "fzf package.json script runner with auto-detected pac end if test -z "$pkg" - echo "pj: no package.json found in this tree" >&2 + # PJ_QUIET: called from the down-arrow binding, where a missing + # package.json is the normal case and must not print anything. + test -n "$PJ_QUIET"; or echo "pj: no package.json found in this tree" >&2 return 1 end set -l root (path dirname $pkg)