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:
2026-04-30 01:03:13 -04:00
parent 6722deea3c
commit ada58e8818
12 changed files with 234 additions and 2 deletions
+15 -2
View File
@@ -1,7 +1,12 @@
# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
### Abreviations ###
#
# ╭──────────────────────────────────────────────────────────╮
# │ Abreviations │
# ╰──────────────────────────────────────────────────────────╯
#
# This file contains all the abbreviations for the terminal.
# It is sourced by Fish on startup.
# Neovim
abbr -a n nvim
@@ -232,3 +237,11 @@ abbr -a scr 'systemctl restart'
abbr -a ssct 'sudo systemctl status'
abbr -a sscs 'sudo systemctl start'
abbr -a sscr 'sudo systemctl restart'
### History Expansions and Substitutions ###
abbr -a !^ --position anywhere --function expand_bang_caret
abbr -a '!*' --position anywhere --function expand_bang_all
abbr -a typo_sub --position anywhere --regex '\^([^^]+)\^([^^]*)' --function expand_typo_sub
abbr -a bang_string --position anywhere --regex '![\w.-]+' --function expand_bang_string
abbr -a bang_search --position anywhere --regex '!\?[\w.-]+\??' --function expand_bang_search
abbr -a bang_minus_n --position anywhere --regex '!-(\d+)' --function expand_bang_minus_n
+55
View File
@@ -0,0 +1,55 @@
# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# ╭──────────────────────────────────────────────────────────╮
# │ Fish User Key Bindings │
# ╰──────────────────────────────────────────────────────────╯
#
# This file defines custom key bindings for the Fish shell.
# It is sourced by Fish on startup.
# ────────────────── Bind Prewious Path Head to Ctrl+G ─────────────────
# Bindings to insert the previous path head into the command line
# Behaves like `!$:h` does in bash
#
# Example: If the previous command was `cd /usr/local/bin`
# pressing Ctrl+G will insert `/usr/local` into the command line.
# ──────────────────────────────────────────────────────────────────────
# ──────────── Bind Interactive History Substitution to Ctrl+F ─────────
# Bindings to perform substitution on the previous command in the history
# Behaves like `!!:s/old/new/` does in bash
#
# Example: If the previous command was `echo this is a test`
# typing `this is/that was` and pressing Ctrl+F
# will insert `echo that was a test` into the command line.
# ──────────────────────────────────────────────────────────────────────
# ────────── Bind Replace First Command Token to Ctrl+Alt+U ────────────
# Strips the first command token and places cursor at start to retype it
#
# Example: If the current command text is `mkdir new_folder`
# pressing Ctrl+Alt+U will change the command line to ` new_folder`
# with the cursor at the start, allowing you to quickly change the command
# while keeping the arguments intact.
# To produce `cd new_folder` or `rm new_folder` etc.
# If the current command text is empty, the previous command's first token will be used instead.
# ──────────────────────────────────────────────────────────────────────
function fish_user_key_bindings
# ───────────────────────────── Set Bindings ─────────────────────────────
#
# Set Emacs mode bindings:
bind ctrl-g __insert_previous_path_head
bind ctrl-f __interactive_history_sub
bind ctrl-alt-u _replace_command_token
# Set bindings for all Vi modes:
# 'default' is Vi-Command, 'insert' is Vi-Insert, 'visual' is Vi-Visual
for mode in default insert visual
bind --mode $mode ctrl-g __insert_previous_path_head
bind --mode $mode ctrl-f __interactive_history_sub
bind --mode $mode ctrl-alt-u _replace_command_token
end
end