mirror of
https://github.com/edu4rdshl/based.fish.git
synced 2026-07-17 23:24:46 +00:00
Add inline mode
This commit is contained in:
parent
aa00038f28
commit
8c23a498ed
4 changed files with 53 additions and 5 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
42
functions/__based_inline.fish
Normal file
42
functions/__based_inline.fish
Normal file
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue