Files
fish-config/conf.d/tricks.fish
T
rootiest aef686af86 feat(docs): add CLASSIFICATION function-header field, rename history shadow
Rename the C1 history() shadow to pretty-history so it never collides
with the fish builtin -- every function expecting stock history
semantics (search, --max, merge, ...) would otherwise silently break.
hist.fish, which relied on the shadow's timestamp formatting, now
requests it explicitly via builtin history --show-time.

Add a CLASSIFICATION doc-header label so a function can declare its
interaction with C1-shadowed commands (uses-shadow/bypasses-shadow)
and general hazards (destructive, network, blocking-prompt) for
anyone deciding to disable an opinionated category or call the
function from automation. Wired into the manual/site build pipeline
(manualtools.py, build-manual.py) and the C1 shadow doc gets a new
"For function authors" bypass-mechanism reference table
(command/builtin/__original_help, and which shadows have no real
bypass target at all).
2026-09-21 21:26:40 -04:00

190 lines
6.4 KiB
Fish

# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# ────── Borrowed and modified from CachyOS config ─────────
# ╭──────────────────────────────────────────────────────────╮
# │ Provides PATH additions, bang-bang helpers, │
# │ system aliases, and history/backup utilities │
# ╰──────────────────────────────────────────────────────────╯
# COMPONENT
# site aliases-tricks: aliases/filesystem
# site tricks-manpager: overrides/environment
# site tricks-bang: overrides/key-bindings
## Environment setup
# Apply .profile: use this to put fish compatible .profile stuff in
if test -f ~/.fish_profile
source ~/.fish_profile
end
# This file is sourced twice per shell on CachyOS (once by the conf.d
# autoload, once forced by config.fish to re-win over the distro's own
# tricks.fish). The PATH/MANPAGER setup below doesn't need to repeat on
# the second pass -- only the functions/aliases further down do, since
# those are what re-assert over the distro config. Gate the expensive
# calls (fish_add_path, type -q bat) behind a once-per-session guard.
# ponytail: per-session guard, not per-value; if this file grows more
# expensive one-time setup, extend the same guard rather than adding more.
if not set -q __fish_config_tricks_env_applied
set -g __fish_config_tricks_env_applied 1
# Append unique directories to $PATH (fish_add_path handles duplicates automatically)
fish_add_path ~/.local/bin
fish_add_path ~/Applications/depot_tools
# Expose user-local man pages
if not contains ~/.local/share/man $MANPATH
set -gx MANPATH ~/.local/share/man $MANPATH
end
# Format man pages using bat (only if bat is installed)
# Overriding $MANPAGER is opinionated (C3 overrides)
if type -q bat; and __fish_config_op_enabled (status basename) tricks-manpager
set -gx MANROFFOPT -c
set -gx MANPAGER "sh -c 'col -bx | bat -l man -p'"
end
end
# Set settings for https://github.com/franciscolourenco/done
set -gx __done_min_cmd_duration 10000
set -gx __done_notification_urgency_level low
## Functions
# Functions needed for !! and !$ https://github.com/oh-my-fish/plugin-bang-bang
# The bang-bang system is opinionated (C3 overrides) and is gated atomically
# here, in conf.d/abbr.fish, conf.d/puffer.fish, and functions/expand_*.fish.
if __fish_config_op_enabled (status basename) tricks-bang
function __history_previous_command
switch (commandline -t)
case "!"
commandline -t $history[1]
commandline -f repaint
case "*"
commandline -i !
end
end
function __history_previous_command_arguments
switch (commandline -t)
case "!"
commandline -t ""
commandline -f history-token-search-backward
case "*"
commandline -i '$'
end
end
# Apply bang-bang key bindings based on current key binding mode
if [ "$fish_key_bindings" = fish_vi_key_bindings ]
# @category History Expansion
# @name !!
# @desc Expand to the previous command
bind -Minsert ! __history_previous_command
# @category History Expansion
# @name !$
# @desc Expand to the last argument of the previous command
bind -Minsert '$' __history_previous_command_arguments
else
# @category History Expansion
# @name !!
# @desc Expand to the previous command
bind ! __history_previous_command
# @category History Expansion
# @name !$
# @desc Expand to the last argument of the previous command
bind '$' __history_previous_command_arguments
end
end
# Timestamped history view. Named pretty-history (not history) so it never
# shadows the fish builtin -- every function in this config that expects
# stock `history` semantics (search, --max, merge, ...) would otherwise
# silently break, which has happened more than once. Opinionated (C1
# aliasing); when disabled, the function is never defined.
if __fish_config_op_enabled (status basename) aliases-tricks
function pretty-history --description 'History with timestamps prepended to every entry'
builtin history --show-time='%F %T '
end
end
# Quick file backup utility
function backup --argument filename
cp $filename $filename.bak
end
# Memory monitoring helpers
function psmem
ps auxf | sort -nr -k 4
end
function psmem10
ps auxf | sort -nr -k 4 | head -10
end
## Useful aliases
# Navigation short-cuts
# @category Shell Aliases
# @desc cd ..
alias ..='cd ..'
# @category Shell Aliases
# @desc cd ../..
alias ...='cd ../..'
# @category Shell Aliases
# @desc cd ../../..
alias ....='cd ../../..'
# @category Shell Aliases
# @desc cd ../../../..
alias .....='cd ../../../..'
# @category Shell Aliases
# @desc cd ../../../../..
alias ......='cd ../../../../..'
# Silent flag injection into POSIX tools is opinionated (C1 aliasing)
if __fish_config_op_enabled (status basename) aliases-tricks
# Tools & Core command color overrides
# @category Shell Aliases
# @desc dir --color=auto
alias dir='dir --color=auto'
# @category Shell Aliases
# @desc vdir --color=auto
alias vdir='vdir --color=auto'
# @category Shell Aliases
# @desc grep --color=auto
alias grep='grep --color=auto'
# @category Shell Aliases
# @desc fgrep --color=auto
alias fgrep='fgrep --color=auto'
# @category Shell Aliases
# @desc egrep --color=auto
alias egrep='egrep --color=auto'
# Safety aliases (Confirmation before overwriting/deleting)
# @category Shell Aliases
# @desc cp -i
alias cp="cp -i"
# @category Shell Aliases
# @desc mv -i
alias mv="mv -i"
# Force wget to resume partial downloads
alias wget='wget -c '
end
# Archives and networking short-hands
# @category Shell Aliases
# @desc tar -acf
alias tarnow='tar -acf '
# @category Shell Aliases
# @desc tar -zxvf
alias untar='tar -zxvf '
# @category Shell Aliases
# @desc nc termbin.com 9999
alias tb='nc termbin.com 9999'
# System Logs
# @category Shell Aliases
# @desc journalctl -p 3 -xb
alias jctl="journalctl -p 3 -xb"