dotfiles vCurrent version: v1.0.0 1.1.0
This commit is contained in:
143
.config/fish/config.fish
Normal file
143
.config/fish/config.fish
Normal file
@@ -0,0 +1,143 @@
|
||||
# =============================================================================
|
||||
# config.fish — Fish Shell Configuration & Dotfiles Manager
|
||||
# Version: 1.0.0
|
||||
# =============================================================================
|
||||
#
|
||||
# This file is the entry point for every Fish shell session. It handles:
|
||||
#
|
||||
# 1. BASIC SETUP — PATH, environment variables, editor
|
||||
# 2. VERSIONING — a single source-of-truth version number
|
||||
# 3. DOTFILES MANAGEMENT — create, update, and track ~/.tmux.conf and
|
||||
# other common config files through the `dotfiles` command
|
||||
# 4. SELF-UPDATE — pull the latest version of this very config from a
|
||||
# remote Git repository and re-apply all managed dotfiles
|
||||
# 5. EXTENSIBILITY — modular structure via conf.d/ and functions/ that
|
||||
# Fish auto-loads; no manual sourcing required
|
||||
#
|
||||
# The heavy lifting lives in ~/.config/fish/functions/dotfiles.fish, which
|
||||
# Fish loads automatically when you first run `dotfiles`. Templates for
|
||||
# managed dotfiles live in ~/.config/fish/dotfiles/.
|
||||
#
|
||||
# ── Quick start ────────────────────────────────────────────────────────────
|
||||
#
|
||||
# dotfiles help # Show all subcommands
|
||||
# dotfiles version # Show the current version of this framework
|
||||
# dotfiles status # Compare managed dotfiles against their templates
|
||||
# dotfiles init # Create ~/.tmux.conf, ~/.gitconfig, etc.
|
||||
# dotfiles sync # Git-pull updates and re-apply everything
|
||||
# dotfiles publish # Bump version, commit local changes, push to repo
|
||||
#
|
||||
# =============================================================================
|
||||
|
||||
|
||||
# ══════════════════════════════════════════════════════════════════════════════
|
||||
# SECTION 1 — Version & Core Constants
|
||||
# ══════════════════════════════════════════════════════════════════════════════
|
||||
#
|
||||
# These values form the single source of truth for the entire framework.
|
||||
# DOTFILES_DIR holds the template files; DOTFILES_BACKUP_DIR holds backups
|
||||
# and the last-update-check timestamp.
|
||||
|
||||
set -g DOTFILES_VERSION "Current version: v1.0.0 1.1.0"
|
||||
|
||||
# --- Remote repository (set this to enable auto-updates) --------------------
|
||||
# Example:
|
||||
# dotfiles repo https://github.com/yourname/dotfiles
|
||||
#
|
||||
# Until you set this, `dotfiles sync` will show a reminder but won't fail.
|
||||
set -gx DOTFILES_REPO_URL ""
|
||||
set -gx DOTFILES_REPO_BRANCH "main"
|
||||
|
||||
# --- Paths ------------------------------------------------------------------
|
||||
# __fish_config_dir is a built-in Fish variable that points to
|
||||
# ~/.config/fish — we use it instead of hard-coding the path.
|
||||
set -gx DOTFILES_DIR "$__fish_config_dir/dotfiles"
|
||||
set -gx DOTFILES_BACKUP_DIR "$__fish_config_dir/backups"
|
||||
|
||||
# --- Auto-update interval ---------------------------------------------------
|
||||
# How often (in days) to remind you that updates are available when a new
|
||||
# interactive shell starts. Set to 0 to disable the nag.
|
||||
set -g DOTFILES_AUTO_UPDATE_INTERVAL_DAYS 7
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────────
|
||||
# Version stamp embedded in the file itself for quick verification.
|
||||
# When you run `dotfiles version`, it reads this constant — no external file
|
||||
# to keep in sync.
|
||||
# ──────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
# ══════════════════════════════════════════════════════════════════════════════
|
||||
# SECTION 2 — PATH & Environment
|
||||
# ══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
# fish_add_path is idempotent — it won't add a directory that's already on PATH.
|
||||
fish_add_path "$HOME/.local/bin"
|
||||
fish_add_path "$HOME/bin"
|
||||
|
||||
# Preferred editor (used by `dotfiles edit` among other things).
|
||||
set -q EDITOR; or set -gx EDITOR "nano"
|
||||
|
||||
# Preferred file pager.
|
||||
set -q PAGER; or set -gx PAGER "less"
|
||||
|
||||
|
||||
# ══════════════════════════════════════════════════════════════════════════════
|
||||
# SECTION 3 — Dotfiles Infrastructure
|
||||
# ══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
# Create the required directories on every login so they are always present
|
||||
# even when the repo is cloned fresh.
|
||||
for dir in "$DOTFILES_DIR" "$DOTFILES_BACKUP_DIR"
|
||||
if not test -d "$dir"
|
||||
mkdir -p "$dir"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# ══════════════════════════════════════════════════════════════════════════════
|
||||
# SECTION 4 — Interactive Session: Prompt, Welcome, Auto-Update Nag
|
||||
# ══════════════════════════════════════════════════════════════════════════════
|
||||
#
|
||||
# Everything below this guard runs only in interactive (i.e. human-facing)
|
||||
# shells, never in scripts.
|
||||
|
||||
if status is-interactive
|
||||
|
||||
# ── 4a. Welcome message (shown once per login) ────────────────────────
|
||||
# Set DOTFILES_SUPPRESS_WELCOME=1 in your environment to silence this.
|
||||
if not set -q DOTFILES_SUPPRESS_WELCOME
|
||||
echo "fish: dotfiles v$DOTFILES_VERSION — run 'dotfiles help' for commands"
|
||||
end
|
||||
|
||||
# ── 4b. Periodic auto-update reminder ─────────────────────────────────
|
||||
# Once every DOTFILES_AUTO_UPDATE_INTERVAL_DAYS, print a one-line
|
||||
# reminder that updates may be available. The actual update is
|
||||
# performed via `dotfiles sync` (manual, so you control the timing).
|
||||
if test "$DOTFILES_AUTO_UPDATE_INTERVAL_DAYS" -gt 0
|
||||
set -l last_check_file "$DOTFILES_BACKUP_DIR/.last_update_check"
|
||||
|
||||
# Determine days since last check
|
||||
set -l days_ago 999
|
||||
if test -f "$last_check_file"
|
||||
set -l last_ts (command cat "$last_check_file")
|
||||
set -l now_ts (date +%s)
|
||||
# Use integer arithmetic: 86400 seconds in a day
|
||||
set -l elapsed (math "$now_ts - $last_ts")
|
||||
if test "$elapsed" -ge 0
|
||||
set days_ago (math "$elapsed / 86400")
|
||||
end
|
||||
end
|
||||
|
||||
if test "$days_ago" -ge "$DOTFILES_AUTO_UPDATE_INTERVAL_DAYS"
|
||||
echo "tip: run 'dotfiles sync' to check for dotfiles updates"
|
||||
command date +%s >"$last_check_file"
|
||||
end
|
||||
end
|
||||
|
||||
# ── 4c. Prompt ─────────────────────────────────────────────────────────
|
||||
# No custom fish_prompt defined here — Fish uses its built-in default
|
||||
# which shows user@host in color, the working directory, git status,
|
||||
# and pipestatus. To customise, define your own fish_prompt function
|
||||
# in ~/.config/fish/functions/fish_prompt.fish.
|
||||
|
||||
end # status is-interactive
|
||||
Reference in New Issue
Block a user