diff --git a/config.fish b/config.fish index 07acc3c..89a8051 100644 --- a/config.fish +++ b/config.fish @@ -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 diff --git a/functions/__auto_source_fallback_venv.fish b/functions/__auto_source_fallback_venv.fish index 0cc180c..ab17f05 100644 --- a/functions/__auto_source_fallback_venv.fish +++ b/functions/__auto_source_fallback_venv.fish @@ -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 diff --git a/functions/bash.fish b/functions/bash.fish index 1ccaa48..5a46f63 100644 --- a/functions/bash.fish +++ b/functions/bash.fish @@ -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 diff --git a/functions/cat.fish b/functions/cat.fish index e0d8682..fb993fb 100644 --- a/functions/cat.fish +++ b/functions/cat.fish @@ -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] diff --git a/functions/du.fish b/functions/du.fish index 4f291e7..903cd3b 100644 --- a/functions/du.fish +++ b/functions/du.fish @@ -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 diff --git a/functions/expand_bang_all.fish b/functions/expand_bang_all.fish index 44c6158..bd3940f 100644 --- a/functions/expand_bang_all.fish +++ b/functions/expand_bang_all.fish @@ -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 diff --git a/functions/expand_bang_caret.fish b/functions/expand_bang_caret.fish index 99a4539..e1f62a5 100644 --- a/functions/expand_bang_caret.fish +++ b/functions/expand_bang_caret.fish @@ -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 diff --git a/functions/expand_bang_minus_n.fish b/functions/expand_bang_minus_n.fish index b74810a..0a65176 100644 --- a/functions/expand_bang_minus_n.fish +++ b/functions/expand_bang_minus_n.fish @@ -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 diff --git a/functions/expand_bang_search.fish b/functions/expand_bang_search.fish index 481f360..de32dd4 100644 --- a/functions/expand_bang_search.fish +++ b/functions/expand_bang_search.fish @@ -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) diff --git a/functions/expand_bang_string.fish b/functions/expand_bang_string.fish index 6ed3608..a3a497e 100644 --- a/functions/expand_bang_string.fish +++ b/functions/expand_bang_string.fish @@ -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" diff --git a/functions/expand_typo_sub.fish b/functions/expand_typo_sub.fish index 0ceddf6..d20049a 100644 --- a/functions/expand_typo_sub.fish +++ b/functions/expand_typo_sub.fish @@ -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] diff --git a/functions/fish_right_prompt.fish b/functions/fish_right_prompt.fish index 7f1642a..df61ec3 100644 --- a/functions/fish_right_prompt.fish +++ b/functions/fish_right_prompt.fish @@ -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 diff --git a/functions/help.fish b/functions/help.fish index 9cbe5d9..2111ee7 100644 --- a/functions/help.fish +++ b/functions/help.fish @@ -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. diff --git a/functions/hist.fish b/functions/hist.fish index 364723f..39902e4 100644 --- a/functions/hist.fish +++ b/functions/hist.fish @@ -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" diff --git a/functions/less.fish b/functions/less.fish index 96553e4..aab3caa 100644 --- a/functions/less.fish +++ b/functions/less.fish @@ -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 diff --git a/functions/logs.fish b/functions/logs.fish index e45bebe..56800d0 100644 --- a/functions/logs.fish +++ b/functions/logs.fish @@ -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 diff --git a/functions/ls.fish b/functions/ls.fish index d4b1590..89c34bf 100644 --- a/functions/ls.fish +++ b/functions/ls.fish @@ -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 diff --git a/functions/mkdir.fish b/functions/mkdir.fish index 43d6925..6e747f2 100644 --- a/functions/mkdir.fish +++ b/functions/mkdir.fish @@ -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 diff --git a/functions/ping.fish b/functions/ping.fish index d07cbcb..7f2e6eb 100644 --- a/functions/ping.fish +++ b/functions/ping.fish @@ -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 diff --git a/functions/rg.fish b/functions/rg.fish index e09b08d..65101de 100644 --- a/functions/rg.fish +++ b/functions/rg.fish @@ -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 diff --git a/functions/rm.fish b/functions/rm.fish index 9b1fb02..1b9cca2 100644 --- a/functions/rm.fish +++ b/functions/rm.fish @@ -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 diff --git a/functions/smart_exit.fish b/functions/smart_exit.fish index 3033c0f..eef2fff 100644 --- a/functions/smart_exit.fish +++ b/functions/smart_exit.fish @@ -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 diff --git a/functions/split.fish b/functions/split.fish index 5671d74..d87ed3d 100644 --- a/functions/split.fish +++ b/functions/split.fish @@ -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 diff --git a/functions/spwin.fish b/functions/spwin.fish index 985f484..3ab983d 100644 --- a/functions/spwin.fish +++ b/functions/spwin.fish @@ -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 diff --git a/functions/ssh.fish b/functions/ssh.fish index 4313730..394bf00 100644 --- a/functions/ssh.fish +++ b/functions/ssh.fish @@ -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 diff --git a/functions/tab.fish b/functions/tab.fish index 1710c6e..c217aa3 100644 --- a/functions/tab.fish +++ b/functions/tab.fish @@ -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" diff --git a/functions/top.fish b/functions/top.fish index c89cc80..c5c471d 100644 --- a/functions/top.fish +++ b/functions/top.fish @@ -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 diff --git a/functions/upgrade.fish b/functions/upgrade.fish index d3a768c..e5e6ffb 100644 --- a/functions/upgrade.fish +++ b/functions/upgrade.fish @@ -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