From 6722deea3cf24e880ad047b5960057127eeb1cf9 Mon Sep 17 00:00:00 2001 From: rootiest Date: Wed, 29 Apr 2026 17:23:13 -0400 Subject: [PATCH] feat: add git and history utility functions - Add branch, fc, and gitup functions - Update README documentation for new functions and abbreviations - Remove obsolete push-vim function --- README.md | 11 ++++++++++- conf.d/abbr.fish | 2 +- functions/branch.fish | 14 ++++++++++++++ functions/fc.fish | 37 +++++++++++++++++++++++++++++++++++++ functions/gitup.fish | 15 +++++++++++++++ functions/push-vim.fish | 7 ------- 6 files changed, 77 insertions(+), 9 deletions(-) create mode 100644 functions/branch.fish create mode 100644 functions/fc.fish create mode 100644 functions/gitup.fish delete mode 100644 functions/push-vim.fish diff --git a/README.md b/README.md index 3840cfe..512c69e 100644 --- a/README.md +++ b/README.md @@ -193,6 +193,8 @@ rm -f file.txt # Falls through to standard rm -f | Function | Description | |---|---| +| `branch` | Switch to or create a git branch | +| `gitup` | Fetch updates and show git status | | `git-clean` | Fetch, prune, update current branch, delete orphaned local branches | | `git-clean --force` | Same but force-deletes unmerged orphaned branches | | `clone` | `clone-in-kitty` wrapper | @@ -257,6 +259,7 @@ rm -f file.txt # Falls through to standard rm -f |---|---| | `edit` / `e` | Open in Neovim | | `view` | Open in Neovim read-only mode | +| `fc` | Edit and execute the last command (Bash-style `fc`) | | `nvimup` | Update Neovim headlessly | | `nlazyup` | Sync Lazy.nvim plugins headlessly | @@ -338,6 +341,7 @@ Abbreviations expand in-place as you type, keeping your history clean. | Abbr | Expands To | |---|---| | `cm` / `cz` | `chezmoi` | +| `cmcd` | `chezmoi cd` | | `cme` | `chezmoi edit` | | `cmad` | `chezmoi add` | | `cmap` | `chezmoi apply` | @@ -387,7 +391,11 @@ Named context shortcuts (e.g. `dcr`, `dck`) live in `~/.config/.user-dots/fish/l | `ssc` | `sudo systemctl` | | `scu` | `systemctl --user` | | `st` | `systemctl status` | +| `scs` | `systemctl start` | | `scr` | `systemctl restart` | +| `ssct` | `sudo systemctl status` | +| `sscs` | `sudo systemctl start` | +| `sscr` | `sudo systemctl restart` | ### Beads (bd) @@ -395,7 +403,8 @@ Named context shortcuts (e.g. `dcr`, `dck`) live in `~/.config/.user-dots/fish/l |---|---| | `bl` | `bd list` | | `bs` | `bd sync` | -| `bc` | `bd create --title` | +| `bC` | `bd create --title` | +| `bsh` | `bd show` | | `lb` | `lazybeads` | --- diff --git a/conf.d/abbr.fish b/conf.d/abbr.fish index 21f6701..e05cb9e 100644 --- a/conf.d/abbr.fish +++ b/conf.d/abbr.fish @@ -218,7 +218,7 @@ abbr -a dcls 'docker context ls' ### Beads ### abbr -a bl 'bd list' abbr -a bs 'bd sync' -abbr -a bc 'bd create --title' +abbr -a bC 'bd create --title' abbr -a bsh 'bd show' abbr -a lb lazybeads diff --git a/functions/branch.fish b/functions/branch.fish new file mode 100644 index 0000000..fda521c --- /dev/null +++ b/functions/branch.fish @@ -0,0 +1,14 @@ +function branch --description 'Switch to or create a git branch' + if not git rev-parse --is-inside-work-tree >/dev/null 2>&1 + echo "Not a git repo." + return 1 + end + + # Check if the branch already exists locally + if git show-ref --verify --quiet refs/heads/$argv[1] + git checkout $argv + else + # If it doesn't exist, create it + git checkout -b $argv + end +end diff --git a/functions/fc.fish b/functions/fc.fish new file mode 100644 index 0000000..761d0ff --- /dev/null +++ b/functions/fc.fish @@ -0,0 +1,37 @@ +function fc --description "Edit and execute the last command (Bash-style fc)" + set -l tmpfile (mktemp /tmp/fish_fc.XXXXXX).fish + + if count $argv >/dev/null + # Search for a specific previous command + builtin history search --max=1 "$argv" | sed 's/^[0-9-]* [0-9:]* //' >$tmpfile + else + # Grab the last 2 commands, then take the 2nd one (the one before 'fc') + # This avoids the --skip flag entirely + builtin history --max=2 | sed 's/^[0-9-]* [0-9:]* //' | sed -n 2p >$tmpfile + end + + # Set editor with fallback + set -l editor $EDITOR + if test -z "$editor" + set editor vi + end + + # Only open editor if we actually got a command + if test -s $tmpfile + $editor $tmpfile + + # Final check if user cleared the file in the editor + if test -s $tmpfile + set -l command (cat $tmpfile) + rm $tmpfile + commandline -r "$command" + commandline -f execute + else + rm $tmpfile + echo "fc: Aborted (empty file)" + end + else + rm $tmpfile + echo "fc: Could not retrieve history" + end +end diff --git a/functions/gitup.fish b/functions/gitup.fish new file mode 100644 index 0000000..0a9dced --- /dev/null +++ b/functions/gitup.fish @@ -0,0 +1,15 @@ +function gitup --description 'Fetch updates and show git status' + # Check if we are even in a git repository + if not git rev-parse --is-inside-work-tree >/dev/null 2>&1 + echo "Check your map! You aren't in a git repository." + return 1 + end + + if count $argv >/dev/null + git fetch $argv + else + git fetch + end + + and git status +end diff --git a/functions/push-vim.fish b/functions/push-vim.fish deleted file mode 100644 index d2bc968..0000000 --- a/functions/push-vim.fish +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright (C) 2026 Rootiest -# SPDX-License-Identifier: AGPL-3.0-or-later - -function push-vim --wraps=/home/rootiest/projects/propogate-vim/send.sh --description 'alias push-vim=/home/rootiest/projects/propogate-vim/send.sh' - /home/rootiest/projects/propogate-vim/send.sh $argv - -end