From 8c23a498edc71cbc0b113d3b4b5cb48d3b4b791c Mon Sep 17 00:00:00 2001 From: Igor Savchuk <3583824+trollfred@users.noreply.github.com> Date: Wed, 6 May 2026 15:33:48 +0300 Subject: [PATCH] Add inline mode --- README.md | 1 + functions/__based_inline.fish | 42 ++++++++++++++++++++++++++ functions/__based_or_history.fish | 8 +++-- functions/based_user_key_bindings.fish | 7 +++-- 4 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 functions/__based_inline.fish diff --git a/README.md b/README.md index 635e6de..09ff9c4 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ You can customize the behavior of based.fish by setting environment variables in - `BASED_NO_CONFIRMATION`: If set to `1`, automatically executes the selected suggestion without confirmation, otherwise, it requires another Enter key press to execute the suggestion. - `BASED_NO_FUZZY`: If set to `1`, disables fuzzy matching for completions and only commands that start with the typed prefix will be suggested. - `BASED_EXCLUDED_PATHS`: A list of path patterns to exclude from history logging. Supports glob patterns like `*` and `?`. Useful for excluding temporary directories, sensitive locations, or paths where you don't want command history tracked. +- `BASED_INLINE_MODE`: If set to `1`, replaces the fzf dropdown with inline cycling. Pressing `Arrow Up` walks through the same context-aware suggestion list one entry at a time (best match first), rewriting the command line in place; `Arrow Down` walks back. With a typed prefix, results are filtered by that prefix and prioritized to the current directory; with an empty prompt, you cycle through this directory's history first, then fall back to global history. E.g. to disable fuzzy behavior when searching for completions diff --git a/functions/__based_inline.fish b/functions/__based_inline.fish new file mode 100644 index 0000000..2cbf971 --- /dev/null +++ b/functions/__based_inline.fish @@ -0,0 +1,42 @@ +function __based_inline --argument-names direction + set -l current (commandline --current-buffer) + + # Reset state if the buffer differs from what we last wrote. + # This covers fresh prompts and any edits the user made between presses. + if not set -q __based_inline_last_written + or test "$current" != "$__based_inline_last_written" + set -g __based_inline_prefix $current + set -g __based_inline_results (__based) + set -g __based_inline_index 0 + set -g __based_inline_last_written $current + end + + set -l count (count $__based_inline_results) + if test $count -eq 0 + return + end + + switch $direction + case up + if test $__based_inline_index -ge $count + return + end + set -g __based_inline_index (math $__based_inline_index + 1) + case down + if test $__based_inline_index -le 0 + return + end + set -g __based_inline_index (math $__based_inline_index - 1) + end + + if test $__based_inline_index -eq 0 + commandline -r -- "$__based_inline_prefix" + set -g __based_inline_last_written $__based_inline_prefix + else + set -l choice $__based_inline_results[$__based_inline_index] + commandline -r -- "$choice" + set -g __based_inline_last_written $choice + end + + commandline -f repaint +end diff --git a/functions/__based_or_history.fish b/functions/__based_or_history.fish index 9e18d33..e7787d1 100644 --- a/functions/__based_or_history.fish +++ b/functions/__based_or_history.fish @@ -1,3 +1,7 @@ -function __based_or_history - __based_fzf_popup +function __based_or_history --argument-names direction + if set -q BASED_INLINE_MODE; and test "$BASED_INLINE_MODE" != 0 + __based_inline $direction + else + __based_fzf_popup + end end diff --git a/functions/based_user_key_bindings.fish b/functions/based_user_key_bindings.fish index 3549b73..2e9bc4e 100644 --- a/functions/based_user_key_bindings.fish +++ b/functions/based_user_key_bindings.fish @@ -1,5 +1,6 @@ function fish_user_key_bindings - # Arrow up and down for smart history - bind \e\[A __based_or_history - bind \e\[B __based_or_history + # Arrow up and down for smart history. + # Direction is always passed; the fzf popup ignores it, the inline mode uses it. + bind \e\[A '__based_or_history up' + bind \e\[B '__based_or_history down' end