]> git.r.bdr.sh - rbdr/dotfiles/commitdiff
Sign with SSH / add SSH helpers
authorRuben Beltran del Rio <redacted>
Wed, 5 Feb 2025 22:31:38 +0000 (23:31 +0100)
committerRuben Beltran del Rio <redacted>
Wed, 5 Feb 2025 22:31:38 +0000 (23:31 +0100)
gitconfig
runcoms/zshrc
zsh/functions/ssh-key-helpers.zsh [new file with mode: 0644]

index 08ed718ca6686e415876e067eb3f08f4f4e54cee..4c9ba6840abc69a40c327ded120564c0aae2bf7a 100644 (file)
--- a/gitconfig
+++ b/gitconfig
@@ -1,7 +1,7 @@
 [user]
   name = Ruben Beltran del Rio
   email = git@r.bdr.sh
-  signingkey = 85D81B97D96211C7
+  signingkey = ~/.ssh/git.pub
 [sendemail]
   smtpserver = smtp.fastmail.com
   smtpuser = r@bdr.sh
@@ -19,6 +19,8 @@
   rebase = false
 [commit]
   gpgsign = true
+[gpg]
+  format = ssh
 [init]
   defaultBranch = main
 [diff]
index ebf6bf12bf9b1ee665ca2006d2f81035698f2dff..c598da7d4fc5f91b3def55eb4e57e51cc1da0a95 100644 (file)
@@ -9,6 +9,7 @@ source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/functions/prettify-json.zsh"
 source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/functions/status.zsh"
 source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/functions/sync-repos.zsh"
 source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/functions/check-repos.zsh"
+source "${ZDOTDIR:-$HOME}/.dotfiles/zsh/functions/ssh-key-helpers.zsh"
 
 ################################################################################
 # Load Modules
diff --git a/zsh/functions/ssh-key-helpers.zsh b/zsh/functions/ssh-key-helpers.zsh
new file mode 100644 (file)
index 0000000..e9b7900
--- /dev/null
@@ -0,0 +1,46 @@
+#!/usr/bin/env zsh
+
+set-git-signing-key() {
+  local key_path="$1"
+
+  if [[ -z "$key_path" ]]; then
+    echo "Error: Please provide a path to the private key to use to sign git commits." >&2
+    return 1
+  fi
+
+  # Check if key exists
+  if [[ ! -f "$key_path" ]]; then
+    echo "Error: Key file does not exist: $key_path" >&2
+    return 1
+  fi
+
+  local absolute_path=$(readlink -f "$key_path")
+
+  ln -sf "$absolute_path" ~/.ssh/git
+  ln -sf "${absolute_path}.pub" ~/.ssh/git.pub
+
+  if [[ $? -eq 0 ]]; then
+    echo "Successfully linked git signing key"
+    return 0
+  else
+    echo "Error: Failed to create symbolic link" >&2
+    return 1
+  fi
+}
+
+generate-ssh-key() {
+  local key_name="$1"
+  local key_description="$2"
+
+  if [[ -z "$key_name" ]]; then
+    echo "Error: Please provide a name for the key." >&2
+    return 1
+  fi
+
+  if [[ -z "$key_description" ]]; then
+    echo "Error: Please provide a description for the key." >&2
+    return 1
+  fi
+
+  ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_${key_name}_$(date +%Y-%m-%d) -C ${key_description}
+}