dotfiles v.1

This commit is contained in:
2026-06-26 19:22:28 +00:00
parent 1fd286b859
commit 2f512fc5c0
4 changed files with 132 additions and 18 deletions

View File

@@ -374,14 +374,6 @@ function dotfiles_repo -d "Show or set the remote repository URL"
end
end
# Load persisted repo URL into the environment on shell start.
# This runs when the function file is sourced, so it's evaluated once per
# session (before the first `dotfiles` invocation).
set -l repo_file "$DOTFILES_BACKUP_DIR/.repo_url"
if test -f "$repo_file"
set -gx DOTFILES_REPO_URL (command cat "$repo_file")
end
# Ensure there's always a default branch and dotfiles directory, even if
# config.fish hasn't been reloaded after a framework update.
if not set -q DOTFILES_REPO_BRANCH
@@ -390,6 +382,20 @@ end
if not set -q DOTFILES_DIR
set -gx DOTFILES_DIR "$__fish_config_dir/dotfiles"
end
if not set -q DOTFILES_BACKUP_DIR
set -gx DOTFILES_BACKUP_DIR "$__fish_config_dir/backups"
end
if not set -q DOTFILES_REPO_URL
set -gx DOTFILES_REPO_URL "git@gitssh.toomuchtaco.net:taco/dots.git"
end
# Load persisted repo URL into the environment on shell start.
# This runs when the function file is sourced, so it's evaluated once per
# session (before the first `dotfiles` invocation).
set -l repo_file "$DOTFILES_BACKUP_DIR/.repo_url"
if test -f "$repo_file"
set -gx DOTFILES_REPO_URL (command cat "$repo_file")
end
# ══════════════════════════════════════════════════════════════════════════════

View File

@@ -0,0 +1,102 @@
function keyme -d "Generate (or regenerate) an ed25519 SSH key for Gitea and configure ~/.ssh/config"
set -l key_path "$HOME/.ssh/id_ed25519_gitea"
set -l pub_path "$key_path.pub"
set -l config_path "$HOME/.ssh/config"
set -l host "gitssh.toomuchtaco.net"
# ── Step 1: Handle existing key ─────────────────────────────────────────
if test -f "$key_path"
echo "An SSH key already exists at $key_path"
read -p 'echo "Overwrite it? [y/N] "' -l confirm
if test "$confirm" != "y" -a "$confirm" != "Y"
echo "Aborted."
return 1
end
echo ""
end
# ── Step 2: Generate the key ────────────────────────────────────────────
# -t ed25519: modern, secure, fast elliptic-curve key
# -f: output file
# -N "": empty passphrase (prompts to set one if desired)
ssh-keygen -t ed25519 -f "$key_path" -N ""
echo ""
# ── Step 3: Update ~/.ssh/config ────────────────────────────────────────
# If the host block already exists, update the IdentityFile line in place.
# Otherwise, append a new block at the end of the file.
if grep -q "^Host $host\$" "$config_path" 2>/dev/null
# Host block exists — update the IdentityFile line.
# If an IdentityFile line already exists under this Host, replace it;
# otherwise add one after the HostName line.
if grep -A5 "^Host $host\$" "$config_path" | grep -q "IdentityFile"
sed -i "/^Host $host\$/,/^Host /s|IdentityFile .*|IdentityFile $key_path|" "$config_path"
echo "Updated IdentityFile for Host $host in $config_path"
else
sed -i "/^Host $host\$/,/^Host /s|HostName .*|&\n\tIdentityFile $key_path|" "$config_path"
echo "Added IdentityFile for Host $host in $config_path"
end
else
# No Host block yet — append one.
# printf interprets \t as a literal tab (unlike echo in Fish).
printf "\n# Gitea\nHost %s\n\tHostName %s\n\tUser git\n\tIdentityFile %s\n" \
"$host" "$host" "$key_path" >>"$config_path"
echo "Appended Host block for $host to $config_path"
end
# ── Step 4: Set correct permissions ────────────────────────────────────
chmod 600 "$key_path"
chmod 644 "$pub_path"
chmod 600 "$config_path"
echo ""
# ── Step 5: Prompt for Git identity ────────────────────────────────────
set -l current_name (git config --global user.name 2>/dev/null)
set -l current_email (git config --global user.email 2>/dev/null)
if test -n "$current_name"
read -p 'echo "Git user name ($current_name): "' -l git_name
if test -z "$git_name"
set git_name "$current_name"
end
else
read -p 'echo "Git user name: "' -l git_name
end
if test -n "$current_email"
read -p 'echo "Git user email ($current_email): "' -l git_email
if test -z "$git_email"
set git_email "$current_email"
end
else
read -p 'echo "Git user email: "' -l git_email
end
git config --global user.name "$git_name"
git config --global user.email "$git_email"
echo " Git identity set to $git_name <$git_email>"
echo ""
# ── Step 6: Print the public key ────────────────────────────────────────
echo "=============================="
echo " Public key (add to Gitea): "
echo "=============================="
echo ""
cat "$pub_path"
echo ""
echo "=============================="
echo "Key copied to clipboard if pbcopy/xclip is available."
if command -v pbcopy &>/dev/null
cat "$pub_path" | pbcopy
echo "(copied to clipboard via pbcopy)"
else if command -v xclip &>/dev/null
cat "$pub_path" | xclip -selection clipboard
echo "(copied to clipboard via xclip)"
else if command -v wl-copy &>/dev/null
cat "$pub_path" | wl-copy
echo "(copied to clipboard via wl-copy)"
end
echo "=============================="
end

View File

@@ -53,7 +53,7 @@ dotfiles publish # Bump version, commit, push
│ └── aliases.fish Example: Git abbreviations, helper functions
├── functions/
│ ├── dotfiles.fish The `dotfiles` command and all subcommands
│ └── gitea_key.fish Helper: generate SSH key for Gitea
│ └── keyme.fish Helper: generate SSH key for Gitea
└── dotfiles/
├── tmux.conf Template → ~/.tmux.conf
├── gitconfig Template → ~/.gitconfig

View File

@@ -15,7 +15,7 @@
# 3. Replaces or updates ~/.config/fish/ with the contents of the repo
# 4. Sources the new config and runs `dotfiles init` to install templates
# (~/.tmux.conf, ~/.gitconfig, ~/.config/starship.toml, etc.)
# 5. Warns if SSH key is needed and points to the gitea_key helper
# 5. Warns if SSH key is needed and points to the keyme helper
# 6. Prints next steps
#
# You can pass a custom repo URL as the first argument:
@@ -171,17 +171,23 @@ echo "$GRN ✓$RST Files installed."
_step "4/5" "Initialising managed dotfiles (~/.tmux.conf, ~/.gitconfig, ...) ..."
# Source the newly installed config so the `dotfiles` function is available.
source "$FISH_CONFIG_DIR/config.fish"
# Load the dotfiles function file explicitly (auto-load won't fire until
# the function is first called in a non-sourced context).
# Load the dotfiles function so its built-in defaults (DOTFILES_DIR,
# DOTFILES_BACKUP_DIR, DOTFILES_REPO_URL) are available and the
# `dotfiles` command can run. Auto-load won't fire in a curl-piped
# non-interactive context, so we source it explicitly.
if test -f "$FISH_CONFIG_DIR/functions/dotfiles.fish"
source "$FISH_CONFIG_DIR/functions/dotfiles.fish"
end
# Persist the SSH repo URL so `dotfiles publish` and `dotfiles sync` work.
if test -n "$SSH_REPO"
# Also source config.fish for the `gitme` helper and any local overrides.
if test -f "$FISH_CONFIG_DIR/config.fish"
source "$FISH_CONFIG_DIR/config.fish"
end
# If a custom SSH_REPO was provided via argv[1], persist it so
# `dotfiles publish` and `dotfiles sync` use the right remote.
# (Otherwise the default in dotfiles.fish applies automatically.)
if set -q argv[1]
dotfiles repo "$SSH_REPO" 2>/dev/null
end
@@ -226,7 +232,7 @@ if test "$CLONED_SSH" -eq 0
echo " To push changes, you need an SSH key set up for Gitea."
echo " Run this built-in helper to generate one and configure SSH:"
echo ""
echo " $(set_color --bold)gitea_key$RST"
echo " $(set_color --bold)keyme$RST"
echo ""
echo " It will create ~/.ssh/id_ed25519_gitea, update ~/.ssh/config,"
echo " and print the public key for you to add at:"