feat(functions,bindings): add smart-execute, fast-cli; refactor qalc and rm

- Add _smart_execute: context-aware Ctrl+Enter that routes to qalc when
  the buffer ends with '=', or falls through to standard execute otherwise
- Refactor qalc_eval → _qalc_eval (private helper, same behavior)
- Bind Ctrl+Enter to _smart_execute in all vi modes
- Add fast-cli wrapper (fast.com speed test) and fast placeholder with
  a friendly ANSI redirect message
- Add speedtest-fast abbreviation expanding to fast-cli
- Enhance _replace_command_token to handle sudo-prefixed commands: places
  cursor at index 5 (between sudo and the replacement slot)
- Improve rm error reporting: colored output, culprit-path listing, and
  cleaned technical detail for non-missing-file errors
- Add SPDX copyright headers to cat, ld, claude-docs, claude-pr functions
- Update README: Ctrl+Enter binding, fast-cli/fast functions, speedtest-fast abbr
This commit is contained in:
2026-05-10 01:36:14 -04:00
parent 4dff7632cd
commit b62c2476da
13 changed files with 181 additions and 12 deletions
@@ -1,7 +1,8 @@
# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
function qalc_eval
# Returns the result of a qalc calculation
function _qalc_eval
# Get the current command line buffer
set -l cmd (commandline)
+30 -5
View File
@@ -1,10 +1,35 @@
# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# Removes the first token from the command line and places the cursor at the start
function _replace_command_token --description 'Remove first token from commandline and place cursor at start'
# Removes the first token from the command line and places the cursor at the position for replacement.
# If the command starts with 'sudo', preserves 'sudo' and removes the next token instead.
function _replace_command_token --description 'Remove first command token (or first after sudo) and place cursor for replacement'
set -l cmd (commandline)
set -l rest (string replace -r '^\S+' '' -- $cmd)
commandline -- $rest
commandline -C 0
# 1. Logic for commands starting with sudo
if string match -rq '^sudo\s+' -- "$cmd"
# regex explanation:
# ^sudo\s+ -> Matches 'sudo' and the following whitespace
# \S+ -> Matches the actual command (e.g., 'rm')
# \s* -> Consumes the space after the command so it's not captured
# (.*) -> Captures everything else (the arguments) into $1
set -l rest (string replace -r '^sudo\s+\S+\s*(.*)' 'sudo $1' -- "$cmd")
commandline -- "$rest"
# Place cursor between the two spaces after sudo
# 'sudo ' is 5 characters (indices 0-4), so index 5 is the sweet spot
commandline -C 5
# 2. Logic for standard commands (no sudo)
else
# regex explanation:
# ^\S+ -> Matches the first word/command
# \s* -> Consumes the trailing space
# (.*) -> Captures the rest of the line into $1
set -l rest (string replace -r '^\S+\s*(.*)' ' $1' -- "$cmd")
commandline -- "$rest"
# Place cursor at index 0 to immediately start typing the replacement
commandline -C 0
end
end
+29
View File
@@ -0,0 +1,29 @@
# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# Executes different functions based on the command line content
function _smart_execute --description 'Execute different functions based on the command line content'
# Get the current command line buffer
set -l cmd (commandline)
# 1. Handle empty buffer (Standard Enter behavior)
if test -z "$cmd"
commandline -f execute
return
end
# 2. Dispatch based on buffer content
switch "$cmd"
case '*='
# If it ends in =, run qalc
_qalc_eval
# case 'g *'
# # EXAMPLE FUTURE EXTENSION
# _some_git_helper
case '*'
# Default: execute the command line as-is
commandline -f execute
end
end
+1
View File
@@ -1,6 +1,7 @@
# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# Use bat for files and ls for directories when using cat
function cat --wraps='bat' --description 'Use bat for files and ls for directories'
# If no arguments are provided, cat usually waits for stdin.
# We'll maintain that behavior by skipping the directory check if $argv is empty.
+4
View File
@@ -1,3 +1,7 @@
# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# Update README.md with recent changes using Claude-code
function claude-docs --description 'Claude-code: Sync README with recent changes'
claude "Analyze the recent changes and update the README.md to ensure all features, setup instructions, and examples are 100% accurate. Prune any obsolete information."
end
+4
View File
@@ -1,3 +1,7 @@
# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# Create a new git branch, commit, push, and PR using Claude-code
function claude-pr --description 'Claude-code: New branch, commit, push, and PR'
claude "Act as a senior engineer. Execute this sequence: 1. Create a new git branch (kebab-case). 2. Stage changes and write a Conventional Commit message. 3. Self-verify the changes by running relevant build/test commands or linting. 4. Push to remote. 5. Create a PR to 'main' including a summary of changes and a 'Manual Verification' section containing a Markdown checklist (- [ ]) of specific, bite-sized steps required to manually verify the functionality."
end
+7
View File
@@ -0,0 +1,7 @@
# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# Run a speed test using fast.com
function fast-cli --description "Run a speed test using fast.com"
command fast $argv
end
+41
View File
@@ -0,0 +1,41 @@
# # Copyright (C) 2026 Rootiest
# # SPDX-License-Identifier: AGPL-3.0-or-later
#
# # Placeholder for a future implementation of a "fast" function
# function fast --description 'Placeholder for future fast utility'
# # Defining Catppuccin Mocha colors
# set -l flamingo F2CDCD
# set -l blue 89B4FA
# set -l mauve cba6f7
# set -l mantle 181825
#
# echo -e ""
# echo -n (set_color $flamingo)" 󰊠 "(set_color --bold)"The '"
# echo -n (set_color $mauve)"fast"
# echo -n (set_color $flamingo)"' command is not currently available."
# echo -e ""
# echo -n (set_color $blue)" Did you mean: "
# echo -n (set_color --bold $mauve)"fast-cli"
# echo -n (set_color --italics $blue)"?"(set_color normal)
# echo -e "\n"
# end
# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# Placeholder for a future implementation of a "fast" function
function fast --description 'Placeholder for future fast utility'
# ANSI Escape Codes (Standard 16-color palette)
set -l bold "\e[1m"
set -l italic "\e[3m"
set -l red "\e[31m"
set -l blue "\e[34m"
set -l yellow "\e[33m"
set -l magenta "\e[35m"
set -l reset "\e[0m"
# Using printf for reliable ANSI rendering
printf " %b %bThe command: %b%bfast%b%b is currently unavailable.%b\n" "$yellow" "$bold" "$reset" "$magenta" "$reset" "$yellow" "$reset"
printf " %bDid you mean: %b%bfast-cli%b%b?%b\n" "$blue" "$reset" "$bold$magenta" "$reset" "$italic$blue" "$reset"
printf "\n"
end
+1
View File
@@ -1,6 +1,7 @@
# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# Run lazydocker on the current Docker context
function ld --description 'Run lazydocker on the current Docker context'
# Fetch the host endpoint of the currently active Docker context
set -l current_host (docker context inspect --format '{{.Endpoints.docker.Host}}')
+46 -4
View File
@@ -66,12 +66,54 @@ function rm --description 'Ultimate rm: trash, list, empty, and secure-erase'
set -a trash_paths $arg
end
end
if type -q trash; and set -q trash_paths[1]
trash put $trash_paths
# Refresh Dolphin view
set -l trash_output (trash put $trash_paths 2>&1)
set -l exit_status $status
if test $exit_status -ne 0
# 1. Extract the core message (e.g., "No such file or directory")
set -l raw_msg (string replace -r '.*Message: (.+?) \(os error.*' '$1' -- "$trash_output")
# 2. Find which paths are actually missing
set -l culprits
for p in $trash_paths
if not test -e "$p"
set -a culprits "$p"
end
end
# 3. Display Logic
set_color red --bold
echo -n "error: "
set_color normal
echo $raw_msg
if set -q culprits[1]
# If we found missing files, show the user's source paths
for c in $culprits
set_color blue
echo -n " ↳ Source: "
set_color normal
echo $c
end
else
# 1. Strip ANSI escape codes (color) so regex works correctly
# 2. Remove the 'error: ' prefix
# 3. Unescape quotes and trim whitespace
set -l clean_detail (string replace -ra '\e\[[^m]*m' '' -- "$trash_output" \
| string replace -r '^error: ' '' \
| string unescape \
| string trim)
set_color yellow
echo -n " ↳ Technical detail: "
set_color normal
echo $clean_detail
end
end
dbus-send --type=signal /OrgKdeKDirNotify org.kde.KDirNotify.FilesChanged stringArray:"trash:/" >/dev/null 2>&1 &
return
return $exit_status
end
end