]> git.r.bdr.sh - rbdr/dotfiles/blob - zsh/functions/ssh-key-helpers.zsh
Sign with SSH / add SSH helpers
[rbdr/dotfiles] / zsh / functions / ssh-key-helpers.zsh
1 #!/usr/bin/env zsh
2
3 set-git-signing-key() {
4 local key_path="$1"
5
6 if [[ -z "$key_path" ]]; then
7 echo "Error: Please provide a path to the private key to use to sign git commits." >&2
8 return 1
9 fi
10
11 # Check if key exists
12 if [[ ! -f "$key_path" ]]; then
13 echo "Error: Key file does not exist: $key_path" >&2
14 return 1
15 fi
16
17 local absolute_path=$(readlink -f "$key_path")
18
19 ln -sf "$absolute_path" ~/.ssh/git
20 ln -sf "${absolute_path}.pub" ~/.ssh/git.pub
21
22 if [[ $? -eq 0 ]]; then
23 echo "Successfully linked git signing key"
24 return 0
25 else
26 echo "Error: Failed to create symbolic link" >&2
27 return 1
28 fi
29 }
30
31 generate-ssh-key() {
32 local key_name="$1"
33 local key_description="$2"
34
35 if [[ -z "$key_name" ]]; then
36 echo "Error: Please provide a name for the key." >&2
37 return 1
38 fi
39
40 if [[ -z "$key_description" ]]; then
41 echo "Error: Please provide a description for the key." >&2
42 return 1
43 fi
44
45 ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_${key_name}_$(date +%Y-%m-%d) -C ${key_description}
46 }