feat(guards): add in-function opinionated guards and CachyOS cleanup
C1 shadows (rm, cat, ls, less, du, bash, top, ping, ssh, rg, mkdir, help) fall back to the bare command when __fish_config_op_aliases is falsy; rm falls back to exact 'command rm' with no wrapper. C2 gates the auto-venv PWD hook. C3 gates smart_exit (composing with Task #4 logging), fish_right_prompt, and all six expand_bang_*/expand_typo_sub functions atomically with the bang-bang system. C4 integration commands (spwin, tab, split, hist, logs, upgrade) refuse with a colored stderr error when disabled. config.fish now also strips the CachyOS distro config's own bang-bang bindings, history override, and alias opinions per category, restoring fish stock functions where they exist.
This commit is contained in:
+25
@@ -32,6 +32,31 @@ if test -f /usr/share/cachyos-fish-config/cachyos-config.fish
|
||||
source "$__fish_config_dir/functions/$_fname.fish"
|
||||
end
|
||||
end
|
||||
|
||||
# The distro config ships opinionated pieces of its own (it is the origin
|
||||
# of tricks.fish); strip them when the matching category is disabled so
|
||||
# the guards hold on CachyOS systems too.
|
||||
if not __fish_config_op_enabled __fish_config_op_aliases
|
||||
for _fname in grep fgrep egrep dir vdir wget
|
||||
functions -q $_fname; and functions --erase $_fname
|
||||
end
|
||||
# Restore fish's stock versions where they exist (erasing alone would
|
||||
# also block autoloading the stock function).
|
||||
for _fname in history ls
|
||||
functions -q $_fname; and functions --erase $_fname
|
||||
test -f $__fish_data_dir/functions/$_fname.fish
|
||||
and source $__fish_data_dir/functions/$_fname.fish
|
||||
end
|
||||
end
|
||||
if not __fish_config_op_enabled __fish_config_op_overrides
|
||||
for _fname in __history_previous_command __history_previous_command_arguments
|
||||
functions -q $_fname; and functions --erase $_fname
|
||||
end
|
||||
bind --erase ! 2>/dev/null
|
||||
bind --erase '$' 2>/dev/null
|
||||
bind -M insert --erase ! 2>/dev/null
|
||||
bind -M insert --erase '$' 2>/dev/null
|
||||
end
|
||||
end
|
||||
set --erase _fname
|
||||
|
||||
|
||||
@@ -14,7 +14,10 @@
|
||||
# cd ~/myproject # activates .venv if present
|
||||
function __auto_source_fallback_venv --on-variable PWD
|
||||
status --is-command-substitution; and return
|
||||
|
||||
|
||||
# Opinionated guard (C2): no automatic venv activation when disabled.
|
||||
__fish_config_op_enabled __fish_config_op_autoexec; or return
|
||||
|
||||
# 1. Skip if direnv is already managing this directory
|
||||
if set -q DIRENV_DIR; or test -e ".envrc"
|
||||
return
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
# EXAMPLE
|
||||
# bash
|
||||
function bash --wraps='bash' --description 'bash switches to bash shell'
|
||||
# Opinionated guard (C1): fall back to bare command bash when disabled.
|
||||
if not __fish_config_op_enabled __fish_config_op_aliases
|
||||
command bash $argv
|
||||
return $status
|
||||
end
|
||||
|
||||
set SHELL $(which bash) # Set shell to bash
|
||||
command bash --rcfile "$XDG_CONFIG_HOME/bash/bashrc" $argv # Run bash
|
||||
set SHELL $(which fish) # Reset shell
|
||||
|
||||
+7
-1
@@ -15,7 +15,13 @@
|
||||
# EXAMPLE
|
||||
# cat README.md
|
||||
function cat --wraps='bat' --description 'Use bat for files, ls for directories, and raw cat for ANSI logs'
|
||||
# If no arguments are provided, cat usually waits for stdin.
|
||||
# Opinionated guard (C1): fall back to bare command cat when disabled.
|
||||
if not __fish_config_op_enabled __fish_config_op_aliases
|
||||
command cat $argv
|
||||
return $status
|
||||
end
|
||||
|
||||
# If no arguments are provided, cat usually waits for stdin.
|
||||
# We'll maintain that behavior by skipping the directory check if $argv is empty.
|
||||
if set -q argv[1]
|
||||
if test -d $argv[1]
|
||||
|
||||
@@ -18,6 +18,12 @@
|
||||
# EXAMPLE
|
||||
# du ~/Downloads
|
||||
function du --description 'Execute du'
|
||||
# Opinionated guard (C1): fall back to bare command du when disabled.
|
||||
if not __fish_config_op_enabled __fish_config_op_aliases
|
||||
command du $argv
|
||||
return $status
|
||||
end
|
||||
|
||||
set cmd ""
|
||||
set args
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
# Execute expand_bang_all
|
||||
function expand_bang_all --description 'Execute expand_bang_all'
|
||||
# Opinionated guard (C3): no expansion when overrides are disabled.
|
||||
__fish_config_op_enabled __fish_config_op_overrides; or return 1
|
||||
|
||||
set -l token $argv[1]
|
||||
if test -z "$token"; set token (commandline -t); end
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
# Execute expand_bang_caret
|
||||
function expand_bang_caret --description 'Execute expand_bang_caret'
|
||||
# Opinionated guard (C3): no expansion when overrides are disabled.
|
||||
__fish_config_op_enabled __fish_config_op_overrides; or return 1
|
||||
|
||||
# Split the last history item into a list
|
||||
set -l tokens (string split -n ' ' -- $history[1])
|
||||
# tokens[1] is the command, tokens[2] is the first argument
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
# Execute expand_bang_minus_n
|
||||
function expand_bang_minus_n --description 'Execute expand_bang_minus_n'
|
||||
# Opinionated guard (C3): no expansion when overrides are disabled.
|
||||
__fish_config_op_enabled __fish_config_op_overrides; or return 1
|
||||
|
||||
set -l token $argv[1]
|
||||
if test -z "$token"; set token (commandline -t); end
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
# Execute expand_bang_search
|
||||
function expand_bang_search --description 'Execute expand_bang_search'
|
||||
# Opinionated guard (C3): no expansion when overrides are disabled.
|
||||
__fish_config_op_enabled __fish_config_op_overrides; or return 1
|
||||
|
||||
set -l token $argv[1]
|
||||
if test -z "$token"
|
||||
set token (commandline -t)
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
# Execute expand_bang_string
|
||||
function expand_bang_string --description 'Execute expand_bang_string'
|
||||
# Opinionated guard (C3): no expansion when overrides are disabled.
|
||||
__fish_config_op_enabled __fish_config_op_overrides; or return 1
|
||||
|
||||
# Fish 4.x passes the matched token as argv[1]
|
||||
set -l token $argv[1]
|
||||
if test -z "$token"
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
# Execute expand_typo_sub
|
||||
function expand_typo_sub --description 'Execute expand_typo_sub'
|
||||
# In newer Fish, the matched token is often passed as $argv[1]
|
||||
# Opinionated guard (C3): no expansion when overrides are disabled.
|
||||
__fish_config_op_enabled __fish_config_op_overrides; or return 1
|
||||
|
||||
# In newer Fish, the matched token is often passed as $argv[1]
|
||||
# if the abbr is set up correctly. We'll fallback to commandline just in case.
|
||||
set -l last_cmd $history[1]
|
||||
set -l current_token $argv[1]
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
# EXAMPLE
|
||||
# # Rendered automatically by Fish shell; not called directly.
|
||||
function fish_right_prompt --description 'Execute fish_right_prompt'
|
||||
# Opinionated guard (C3): no right prompt when overrides are disabled.
|
||||
__fish_config_op_enabled __fish_config_op_overrides; or return
|
||||
|
||||
# 1. Docker Context in Blue
|
||||
set -l docker_ctx (docker context show 2>/dev/null)
|
||||
if test -n "$docker_ctx"; and test "$docker_ctx" != default
|
||||
|
||||
@@ -66,6 +66,12 @@ end
|
||||
|
||||
# --- Wrapper Definition ---
|
||||
function help --wraps help --description "Custom wrapper to intercept 'help config'"
|
||||
# Opinionated guard (C1): fall back to the native fish help when disabled.
|
||||
if not __fish_config_op_enabled __fish_config_op_aliases
|
||||
__original_help $argv
|
||||
return $status
|
||||
end
|
||||
|
||||
if test "$argv[1]" = config
|
||||
# All arguments after 'config' — including flags (-w/--html, -m/--man,
|
||||
# -h/--help) and section keywords — are forwarded to config-help.
|
||||
|
||||
@@ -11,6 +11,14 @@
|
||||
# EXAMPLE
|
||||
# hist
|
||||
function hist --description 'Search fish history and put it in the prompt'
|
||||
# Opinionated guard (C4): integrations disabled
|
||||
if not __fish_config_op_enabled __fish_config_op_integrations
|
||||
set -l c_err (set_color red)
|
||||
set -l c_reset (set_color normal)
|
||||
echo "$c_err"'hist: disabled by __fish_config_op_integrations'"$c_reset" >&2
|
||||
return 1
|
||||
end
|
||||
|
||||
set -l selected (history | fzf --reverse --height 40% --with-nth 3..)
|
||||
|
||||
if test -n "$selected"
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
# EXAMPLE
|
||||
# less /var/log/syslog
|
||||
function less --wraps='ov' --description 'Pager wrapper: $PAGER → ov → less → more → cat'
|
||||
# Opinionated guard (C1): fall back to bare command less when disabled.
|
||||
if not __fish_config_op_enabled __fish_config_op_aliases
|
||||
command less $argv
|
||||
return $status
|
||||
end
|
||||
|
||||
if set -q PAGER; and command -q $PAGER
|
||||
command $PAGER $argv
|
||||
else if command -q ov
|
||||
|
||||
@@ -19,6 +19,14 @@
|
||||
# EXAMPLE
|
||||
# logs -c paru
|
||||
function logs --description 'Browse terminal log files interactively with fzf'
|
||||
# Opinionated guard (C4): integrations disabled
|
||||
if not __fish_config_op_enabled __fish_config_op_integrations
|
||||
set -l c_err (set_color red)
|
||||
set -l c_reset (set_color normal)
|
||||
echo "$c_err"'logs: disabled by __fish_config_op_integrations'"$c_reset" >&2
|
||||
return 1
|
||||
end
|
||||
|
||||
set -l options h/help c/category=
|
||||
argparse $options -- $argv
|
||||
or return 1
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
# EXAMPLE
|
||||
# ls ~/projects
|
||||
function ls --description 'List all files'
|
||||
# Opinionated guard (C1): fall back to bare command ls when disabled.
|
||||
if not __fish_config_op_enabled __fish_config_op_aliases
|
||||
command ls $argv
|
||||
return $status
|
||||
end
|
||||
|
||||
if which eza >/dev/null 2>&1
|
||||
eza -l -a --icons --color=auto --hyperlink $argv
|
||||
|
||||
|
||||
@@ -16,6 +16,12 @@
|
||||
# EXAMPLE
|
||||
# mkdir ~/projects/myapp/src
|
||||
function mkdir --description 'Execute mkdir'
|
||||
# Opinionated guard (C1): fall back to bare command mkdir when disabled.
|
||||
if not __fish_config_op_enabled __fish_config_op_aliases
|
||||
command mkdir $argv
|
||||
return $status
|
||||
end
|
||||
|
||||
if status is-interactive
|
||||
# Fall back to command mkdir -p when flags are present (e.g. -m 755)
|
||||
for _arg in $argv
|
||||
|
||||
@@ -17,6 +17,12 @@
|
||||
# ping google.com
|
||||
# ping --legend google.com
|
||||
function ping --description 'prettyping with default nolegend'
|
||||
# Opinionated guard (C1): fall back to bare command ping when disabled.
|
||||
if not __fish_config_op_enabled __fish_config_op_aliases
|
||||
command ping $argv
|
||||
return $status
|
||||
end
|
||||
|
||||
if command -q prettyping
|
||||
# Check if the user specifically asked for the legend
|
||||
if contains -- --legend $argv
|
||||
|
||||
@@ -15,6 +15,12 @@
|
||||
# EXAMPLE
|
||||
# rg "TODO" src/
|
||||
function rg --description 'alias rg=rg --hyperlink-format=kitty'
|
||||
# Opinionated guard (C1): fall back to bare command rg when disabled.
|
||||
if not __fish_config_op_enabled __fish_config_op_aliases
|
||||
command rg $argv
|
||||
return $status
|
||||
end
|
||||
|
||||
if test "$TERM" = xterm-kitty
|
||||
command rg --hyperlink-format=kitty $argv
|
||||
else
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
# deletes via rm -rf and triggers fstrim. Plain paths and -r/-R are sent
|
||||
# to trash put; any other flags fall back to system rm.
|
||||
#
|
||||
# Opinionated component (C1): when disabled via __fish_config_op_aliases
|
||||
# (or the __fish_config_opinionated master), behaves exactly like bare
|
||||
# command rm — no wrapper, no trash, no trapping.
|
||||
#
|
||||
# ARGUMENTS
|
||||
# (none) List current trash contents
|
||||
# -e, --empty [opts] Empty the trash; opts forwarded to trash empty
|
||||
@@ -27,6 +31,12 @@
|
||||
# rm -e
|
||||
# rm -S sensitive_key.pem
|
||||
function rm --description 'Ultimate rm: trash, list, empty, and secure-erase'
|
||||
# Opinionated guard (C1): fall back to bare command rm when disabled.
|
||||
if not __fish_config_op_enabled __fish_config_op_aliases
|
||||
command rm $argv
|
||||
return $status
|
||||
end
|
||||
|
||||
# 1. No arguments: Show the Trash contents (Quick view)
|
||||
if not set -q argv[1]
|
||||
if type -q trash
|
||||
|
||||
@@ -20,6 +20,13 @@
|
||||
# EXAMPLE
|
||||
# smart_exit --no-log
|
||||
function smart_exit --description 'Capture colorized scrollback before exiting, with pruning and safe overrides'
|
||||
# Opinionated guard (C3): exit plainly when overrides are disabled.
|
||||
# This composes with Task #4's __fish_config_enable_logging, which will
|
||||
# gate only the scrollback capture while leaving the exit wrapper active.
|
||||
if not __fish_config_op_enabled __fish_config_op_overrides
|
||||
builtin exit $argv
|
||||
end
|
||||
|
||||
set -l options h/help n/no-log
|
||||
argparse $options -- $argv
|
||||
or return 1
|
||||
|
||||
@@ -23,6 +23,14 @@
|
||||
# split
|
||||
# split -v nvim README.md
|
||||
function split --description 'Run a command in a new terminal split'
|
||||
# Opinionated guard (C4): integrations disabled
|
||||
if not __fish_config_op_enabled __fish_config_op_integrations
|
||||
set -l c_err (set_color red)
|
||||
set -l c_reset (set_color normal)
|
||||
echo "$c_err"'split: disabled by __fish_config_op_integrations'"$c_reset" >&2
|
||||
return 1
|
||||
end
|
||||
|
||||
set -l is_kitty 0
|
||||
set -l is_wezterm 0
|
||||
|
||||
|
||||
@@ -18,6 +18,14 @@
|
||||
# EXAMPLE
|
||||
# spwin
|
||||
function spwin --wraps='~/.config/kitty/spawn-window.sh' --description 'spawn window in kitty or wezterm'
|
||||
# Opinionated guard (C4): integrations disabled
|
||||
if not __fish_config_op_enabled __fish_config_op_integrations
|
||||
set -l c_err (set_color red)
|
||||
set -l c_reset (set_color normal)
|
||||
echo "$c_err"'spwin: disabled by __fish_config_op_integrations'"$c_reset" >&2
|
||||
return 1
|
||||
end
|
||||
|
||||
if test "$TERM" = xterm-kitty
|
||||
if test -x ~/.config/kitty/spawn-window.sh
|
||||
~/.config/kitty/spawn-window.sh $argv
|
||||
|
||||
@@ -15,6 +15,12 @@
|
||||
# EXAMPLE
|
||||
# ssh user@host
|
||||
function ssh --description 'Alias ssh to kitten ssh when using Kitty terminal'
|
||||
# Opinionated guard (C1): fall back to bare command ssh when disabled.
|
||||
if not __fish_config_op_enabled __fish_config_op_aliases
|
||||
command ssh $argv
|
||||
return $status
|
||||
end
|
||||
|
||||
if test "$TERM" = xterm-kitty
|
||||
kitten ssh $argv
|
||||
else
|
||||
|
||||
@@ -19,6 +19,14 @@
|
||||
# EXAMPLE
|
||||
# tab
|
||||
function tab --description 'Spawn a new tab in the current terminal'
|
||||
# Opinionated guard (C4): integrations disabled
|
||||
if not __fish_config_op_enabled __fish_config_op_integrations
|
||||
set -l c_err (set_color red)
|
||||
set -l c_reset (set_color normal)
|
||||
echo "$c_err"'tab: disabled by __fish_config_op_integrations'"$c_reset" >&2
|
||||
return 1
|
||||
end
|
||||
|
||||
set -l dir "$cdto"
|
||||
if test -z "$dir"
|
||||
set dir "$PWD"
|
||||
|
||||
@@ -14,6 +14,12 @@
|
||||
# EXAMPLE
|
||||
# top
|
||||
function top --wraps='btop' --description 'Use btop as a modern replacement for top'
|
||||
# Opinionated guard (C1): fall back to bare command top when disabled.
|
||||
if not __fish_config_op_enabled __fish_config_op_aliases
|
||||
command top $argv
|
||||
return $status
|
||||
end
|
||||
|
||||
# 1. Check if btop is actually installed
|
||||
if type -q btop
|
||||
# 2. Launch btop with any arguments passed
|
||||
|
||||
@@ -15,6 +15,14 @@
|
||||
# EXAMPLE
|
||||
# upgrade
|
||||
function upgrade --description 'Full system upgrade via paru or yay'
|
||||
# Opinionated guard (C4): integrations disabled
|
||||
if not __fish_config_op_enabled __fish_config_op_integrations
|
||||
set -l c_err (set_color red)
|
||||
set -l c_reset (set_color normal)
|
||||
echo "$c_err"'upgrade: disabled by __fish_config_op_integrations'"$c_reset" >&2
|
||||
return 1
|
||||
end
|
||||
|
||||
set -l aur ""
|
||||
if type -q paru
|
||||
set aur paru
|
||||
|
||||
Reference in New Issue
Block a user