Files
fish-config/functions/_replace_command_token.fish
rootiest b62c2476da 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
2026-05-10 01:36:14 -04:00

36 lines
1.5 KiB
Fish

# 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 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)
# 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