dotfiles v.1
This commit is contained in:
@@ -374,14 +374,6 @@ function dotfiles_repo -d "Show or set the remote repository URL"
|
|||||||
end
|
end
|
||||||
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
|
# Ensure there's always a default branch and dotfiles directory, even if
|
||||||
# config.fish hasn't been reloaded after a framework update.
|
# config.fish hasn't been reloaded after a framework update.
|
||||||
if not set -q DOTFILES_REPO_BRANCH
|
if not set -q DOTFILES_REPO_BRANCH
|
||||||
@@ -390,6 +382,20 @@ end
|
|||||||
if not set -q DOTFILES_DIR
|
if not set -q DOTFILES_DIR
|
||||||
set -gx DOTFILES_DIR "$__fish_config_dir/dotfiles"
|
set -gx DOTFILES_DIR "$__fish_config_dir/dotfiles"
|
||||||
end
|
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
|
||||||
|
|
||||||
|
|
||||||
# ══════════════════════════════════════════════════════════════════════════════
|
# ══════════════════════════════════════════════════════════════════════════════
|
||||||
|
|||||||
102
.config/fish/functions/keyme.fish
Normal file
102
.config/fish/functions/keyme.fish
Normal 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
|
||||||
@@ -53,7 +53,7 @@ dotfiles publish # Bump version, commit, push
|
|||||||
│ └── aliases.fish Example: Git abbreviations, helper functions
|
│ └── aliases.fish Example: Git abbreviations, helper functions
|
||||||
├── functions/
|
├── functions/
|
||||||
│ ├── dotfiles.fish The `dotfiles` command and all subcommands
|
│ ├── 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/
|
└── dotfiles/
|
||||||
├── tmux.conf Template → ~/.tmux.conf
|
├── tmux.conf Template → ~/.tmux.conf
|
||||||
├── gitconfig Template → ~/.gitconfig
|
├── gitconfig Template → ~/.gitconfig
|
||||||
|
|||||||
24
install.fish
24
install.fish
@@ -15,7 +15,7 @@
|
|||||||
# 3. Replaces or updates ~/.config/fish/ with the contents of the repo
|
# 3. Replaces or updates ~/.config/fish/ with the contents of the repo
|
||||||
# 4. Sources the new config and runs `dotfiles init` to install templates
|
# 4. Sources the new config and runs `dotfiles init` to install templates
|
||||||
# (~/.tmux.conf, ~/.gitconfig, ~/.config/starship.toml, etc.)
|
# (~/.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
|
# 6. Prints next steps
|
||||||
#
|
#
|
||||||
# You can pass a custom repo URL as the first argument:
|
# 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, ...) ..."
|
_step "4/5" "Initialising managed dotfiles (~/.tmux.conf, ~/.gitconfig, ...) ..."
|
||||||
|
|
||||||
# Source the newly installed config so the `dotfiles` function is available.
|
# Load the dotfiles function so its built-in defaults (DOTFILES_DIR,
|
||||||
source "$FISH_CONFIG_DIR/config.fish"
|
# DOTFILES_BACKUP_DIR, DOTFILES_REPO_URL) are available and the
|
||||||
|
# `dotfiles` command can run. Auto-load won't fire in a curl-piped
|
||||||
# Load the dotfiles function file explicitly (auto-load won't fire until
|
# non-interactive context, so we source it explicitly.
|
||||||
# the function is first called in a non-sourced context).
|
|
||||||
if test -f "$FISH_CONFIG_DIR/functions/dotfiles.fish"
|
if test -f "$FISH_CONFIG_DIR/functions/dotfiles.fish"
|
||||||
source "$FISH_CONFIG_DIR/functions/dotfiles.fish"
|
source "$FISH_CONFIG_DIR/functions/dotfiles.fish"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Persist the SSH repo URL so `dotfiles publish` and `dotfiles sync` work.
|
# Also source config.fish for the `gitme` helper and any local overrides.
|
||||||
if test -n "$SSH_REPO"
|
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
|
dotfiles repo "$SSH_REPO" 2>/dev/null
|
||||||
end
|
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 " 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 " Run this built-in helper to generate one and configure SSH:"
|
||||||
echo ""
|
echo ""
|
||||||
echo " $(set_color --bold)gitea_key$RST"
|
echo " $(set_color --bold)keyme$RST"
|
||||||
echo ""
|
echo ""
|
||||||
echo " It will create ~/.ssh/id_ed25519_gitea, update ~/.ssh/config,"
|
echo " It will create ~/.ssh/id_ed25519_gitea, update ~/.ssh/config,"
|
||||||
echo " and print the public key for you to add at:"
|
echo " and print the public key for you to add at:"
|
||||||
|
|||||||
Reference in New Issue
Block a user