feat(shell): add bash-style history expansions and interactive keybindings
- Replicate bash bang-operations (!^, !*, !string, etc.) via abbreviations - Add Ctrl+G for previous path head insertion - Add Ctrl+F for interactive history substitution - Add Ctrl+Alt+U to quickly replace command tokens - Update README documentation for all new features
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
function __substitute_typo
|
||||
set -l cursor_pos (commandline -C)
|
||||
set -l cmd (commandline)
|
||||
|
||||
# Check if the current line matches the ^old^new pattern
|
||||
if string match -qr '\^([^^]+)\^([^^]*)' -- "$cmd"
|
||||
set -l last_cmd $history[1]
|
||||
set -l captured (string match -r '\^([^^]+)\^([^^]*)' -- "$cmd")
|
||||
set -l old $captured[2]
|
||||
set -l new $captured[3]
|
||||
|
||||
if test -n "$old"
|
||||
set -l expanded (string replace -a -- "$old" "$new" "$last_cmd")
|
||||
commandline -r "$expanded"
|
||||
# No need to move cursor, it's a whole new line
|
||||
end
|
||||
else
|
||||
# If it's just a normal caret (not part of a pattern), just insert it
|
||||
commandline -i '^'
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user