Files
fish-config/config.fish
T
rootiest d8bd2b32ab feat(config): refactor config.fish, add XDG compliance, new functions, and keybindings
Restructure and expand the Fish shell configuration for better XDG compliance,
interactive-session gating, modularity, and ergonomics.

config.fish:
- Add full XDG Base Directory variable block (XDG_CONFIG_HOME, XDG_CACHE_HOME,
  XDG_DATA_HOME, XDG_STATE_HOME) and redirect tool caches/configs accordingly
  (cargo, rustup, go, bun, npm, gnupg, wakatime, wget, nvidia, codeium, etc.)
- Add editor setup with `type -q nvim` guard and NVIM_APPNAME
- Add CDPATH block (., ~/projects, ~) with explanatory comments
- Gate all interactive-only setup (key bindings, FZF, direnv, starship, secrets,
  local overrides, CLAUDE_CODE_NO_FLICKER) behind `status is-interactive`
- Guard FZF integration source behind a file-existence check
- Move secrets.fish and local.fish sourcing into the interactive block as overrides
- Remove obsolete universal `cdp` variable and duplicate PATH/editor blocks
- Update PATH entries to use XDG-resolved $CARGO_HOME and $BUN_INSTALL

conf.d/theme.fish:
- Move FZF_DEFAULT_OPTS (Catppuccin Mocha palette) from config.fish into theme.fish
  so all theming lives in one place
- Add section header for FZF colors; condense file header comment

conf.d/abbr.fish:
- Add `/exit` abbreviation as a vim-style alias for the `exit` builtin

conf.d/key_bindings.fish:
- Bind Ctrl+Alt+= to new `qalc_eval` function (inline Qalculate! evaluation)
- Add binding in both normal and all Vi modes
- Add descriptive comment block explaining the keybinding purpose

functions/bash.fish:
- Pass `--rcfile "$XDG_CONFIG_HOME/bash/bashrc"` so bash respects XDG config location

functions/cat.fish:
- Extend cat wrapper: detect directory arguments and delegate to `ls` instead of bat
- Preserve stdin-passthrough behavior when no arguments are provided

functions/__auto_source_fallback_venv.fish (new):
- Extract auto-venv PWD watcher from config.fish into its own autoloaded function file
- Skips activation when direnv manages the directory (.envrc present or DIRENV_DIR set)
- Deactivates venv when leaving its project tree

functions/ld.fish (new):
- Wrapper for lazydocker that injects the active Docker context's DOCKER_HOST,
  enabling correct context-aware operation

functions/joplin.fish (new):
- Joplin CLI wrapper function

functions/qalc_eval.fish (new):
- Inline Qalculate! evaluator: reads the current commandline buffer, passes it to
  `qalc`, prints the result, and clears the buffer for rapid-fire math in the shell

README.md:
- Remove stale `cdp` variable example from the local.fish documentation section

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-08 00:45:02 -04:00

166 lines
10 KiB
Fish

# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# ╭──────────────────────────────────────────────────────────╮
# │ Fish Configuration │
# ╰──────────────────────────────────────────────────────────╯
# ──────────────────────── Source CachyOS configs ────────────────────────
if test -f /usr/share/cachyos-fish-config/cachyos-config.fish
source /usr/share/cachyos-fish-config/cachyos-config.fish
# CachyOS defines aliases for ls/lt/cleanup that shadow our function files.
# Erase them and immediately source our versions.
for _fname in ls lt cleanup
functions --erase $_fname
source $__fish_config_dir/functions/$_fname.fish
end
end
set --erase _fname
# ───────────────────────────── XDG variables ────────────────────────────
# XDG Base Directory variables (standard practice)
set -gx XDG_CONFIG_HOME $HOME/.config # Sets default config dir to ~/.config
set -gx XDG_CACHE_HOME $HOME/.cache # Sets default cache dir to ~/.cache
set -gx XDG_DATA_HOME $HOME/.local/share # Sets default data dir to ~/.local/share
set -gx XDG_STATE_HOME $HOME/.local/state # Sets default state dir to ~/.local/state
# Attempt to keep various config/cache files out of the home directory root
set -gx RANDFILE "$XDG_STATE_HOME/rnd"
set -gx WGETRC "$XDG_CONFIG_HOME/wget/wgetrc"
set -gx WGET_HSTS_FILE "$XDG_CACHE_HOME/wget-hsts"
set -gx NPM_CONFIG_PREFIX "$XDG_DATA_HOME/npm-global"
set -gx NPM_CONFIG_USERCONFIG "$XDG_CONFIG_HOME/npm/npmrc"
set -gx ANDROID_USER_HOME "$XDG_DATA_HOME/android"
set -gx CARGO_HOME "$XDG_DATA_HOME/cargo"
set -gx RUSTUP_HOME "$XDG_DATA_HOME/rustup"
set -gx GOPATH "$XDG_DATA_HOME/go"
set -gx BUN_INSTALL "$XDG_DATA_HOME/bun"
set -gx GNUPGHOME "$XDG_CONFIG_HOME/gnupg"
set -gx WAKATIME_HOME "$XDG_CONFIG_HOME/wakatime"
set -gx HISTFILE "$XDG_STATE_HOME/bash_history"
set -gx EXINIT "set viminfofile=$XDG_STATE_HOME/vim/viminfo | source $MYVIMRC"
set -gx NVIDIA_SETTINGS_RW_CONFIG_FILE "$XDG_CONFIG_HOME/nvidia/settings"
set -gx CODEIUM_HOME "$XDG_CONFIG_HOME/codeium"
set -gx WORDLIST "$XDG_CONFIG_HOME/hunspell_en_US"
# ─────────────────────────── Editor variables ───────────────────────────
# Set Editor variables with fallback to vi if nvim isn't available. This ensures that
# tools that rely on these variables (like git commit messages) will work out of the box,
# while still preferring nvim if it's installed.
if type -q nvim
set -gx NVIM_APPNAME nvim
set -gx EDITOR (command -s nvim)
else
set -gx EDITOR (command -s vi)
end
set -gx VISUAL $EDITOR
set -gx SUDO_EDITOR $EDITOR
# ──────────────────────────── GPG variables ─────────────────────────────
# Helps ensure that GPG can prompt for passphrases correctly when invoked from the terminal.
set -gx GPG_TTY (tty)
# ──────────────────────────── PATH variables ────────────────────────────
# Adds common user bin directories to the PATH. The -mg --move option for cargo ensures that
# the cargo bin directory is moved to the end of the PATH, which can help avoid conflicts
# with system-installed Rust tools while still allowing user-installed cargo binaries to be found.
fish_add_path $HOME/.local/bin
fish_add_path $HOME/Applications
fish_add_path $HOME/scripts
fish_add_path -mg --move $CARGO_HOME/bin
fish_add_path $BUN_INSTALL/bin
fish_add_path $XDG_DATA_HOME/npm-global/bin
fish_add_path $HOME/.lmstudio/bin
# ───────────────────────── CDPATH projects dir ──────────────────────────
# Allows cd-ing to directories within $HOME/projects or $HOME without needing to specify the full path.
# For example, if you have a project at $HOME/projects/myproject,
# you can simply run 'cd myproject' from anywhere and it will take you there.
# 'cd' command prioritizes directories in CDPATH, so if you have a directory with
# the same name in both $HOME/projects and $HOME, it will take you to the one in $HOME/projects first.
# Additionally, directories inside the CWD will still take precedence over CDPATH,
# so if you have a directory named 'myproject' in the current directory,
# running 'cd myproject' will take you there instead of $HOME/projects/myproject.
set -gx CDPATH . $HOME/projects $HOME
# ──────────────────────────── Bootstrap Fisher ──────────────────────────
if not type -q fisher
echo "Fisher plugin manager not found."
read -l -P "Install Fisher and plugins now? [Y/n] " _fisher_reply
if test -z "$_fisher_reply" -o "$_fisher_reply" = Y -o "$_fisher_reply" = y
echo "Installing Fisher..."
curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source
fisher update
fish_config theme choose "Catppuccin Mocha"
else
echo "Skipping Fisher install. Some features may be unavailable."
end
set --erase _fisher_reply
end
# ─────────────────────── visual/interactive setup ───────────────────────
# Run only if we're in an interactive session (not a script or non-interactive shell)
if status is-interactive
# ────────────────────────────── Key bindings ────────────────────────────
# Helps ensure that key bindings are consistent with the Vi editing mode set below.
# This is optional but can improve the user experience for those who prefer Vi-style key bindings.
set -g fish_key_bindings fish_vi_key_bindings
# ──────────────────────── Source FZF integration ────────────────────────
# Sources the FZF integration script, which provides enhanced command history
# searching and file finding capabilities.
if test -f $HOME/.config/fish/integrations/fzf.fish
source $HOME/.config/fish/integrations/fzf.fish
end
# ──────────────────────────────── DirENV ────────────────────────────────
# Tool to handle automatic environment loading in directories and their children
# Use when children need to load venv as well.
#
# The Auto-Venv script above will ignore directories with a
# .envrc file (direnv configuration) to prevent conflicts.
if type -q direnv
direnv hook fish | source
end
# Helps ensure that Claude Code's terminal output is clean and doesn't have flickering issues.
set -gx CLAUDE_CODE_NO_FLICKER 1
# ─────────────────────────── Starship prompt ────────────────────────────
# Initializes the Starship prompt, which provides a highly customizable and informative command prompt.
# This is wrapped in a check to ensure that it only runs if Starship is installed,
# preventing errors if it's not available.
if type -q starship
# STARSHIP_START
starship init fish | source
# STARSHIP_END
end
# ╭────────────────────────────── OVERRIDES ─────────────────────────────╮
# | Run these last so they can override any previous settings. |
# | This is useful for machine-specific behavior or configurations. |
# ╰────────────────────────────── OVERRIDES ─────────────────────────────╯
# ───────────────────────── Source user secrets ──────────────────────────
# Sources a secrets.fish file if it exists, which can be used to store
# sensitive environment variables and configurations that shouldn't be
# committed to version control.
# This allows you to keep things like API keys, database credentials,
# and other secrets out of your main config files and safely ignored by git.
if test -f $HOME/.config/.user-dots/fish/secrets.fish
source $HOME/.config/.user-dots/fish/secrets.fish
end
# ─────────────────────── Source machine-local config ────────────────────
# Sources a local.fish file if it exists, which can be used for machine-specific
# variables and configurations that shouldn't be shared across machines.
# This allows you to have different settings on different machines without affecting
# your main config or secrets files. For example, you might want different PATH additions,
# aliases, or environment variables on your work laptop vs. your home desktop.
if test -f $HOME/.config/.user-dots/fish/local.fish
source $HOME/.config/.user-dots/fish/local.fish
end
# ╭──────────────────────────── END OVERRIDES ──────────────────────────╮
# | End of override section. |
# ╰──────────────────────────── END OVERRIDES ──────────────────────────╯
end