diff --git a/README.md b/README.md index 6c93b64..e7e836f 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,12 @@ TODO: Add subcommands to list and delete ## update-gitignore Quickly and easily create or update `gitignore` files from predefined templates. +## tangled-quick-setup +Easily and quickly set up Git and Jujutsu for Tangled. Sets up the following: +- SSH Key +- Commit signing +- Change ID headers + ## ln-bin Quickly symlink executable files to `~/.local/bin/` diff --git a/meta/update-readme.nu b/meta/update-readme.nu index d4eddd4..ede1000 100755 --- a/meta/update-readme.nu +++ b/meta/update-readme.nu @@ -9,6 +9,7 @@ const featured_names = [ rawreplace atproto-app-passwords update-gitignore + tangled-quick-setup ln-bin auto-benchmark yt-rss diff --git a/scripts/tangled-quick-setup.nu b/scripts/tangled-quick-setup.nu new file mode 100755 index 0000000..0d74d21 --- /dev/null +++ b/scripts/tangled-quick-setup.nu @@ -0,0 +1,71 @@ +#!/usr/bin/env nu +# SPDX-License-Identifier: AGPL-3.0-only +# Copyright (c) 2026 MatrixFurry + +const key_path: path = "~/.ssh/id_tangled_quick_setup" | path expand +const pubkey_path: path = $key_path ++ ".pub" + +const config: path = "~/.ssh/config" | path expand + +# Easily and quickly set up Git and Jujutsu for Tangled. Sets up the following: +# - SSH Key +# - Commit signing +# - Change ID headers +export def main [] { + print "Setting up Jujutsu change ID headers" + let jj = (which jj | length) != 0 + + if $jj { + jj config set --user git.write-change-id-header true + } else { + print "Jujustu is not installed, skipping" + } + + print "Setting up SSH Key" + let email = input "Enter your email, handle, or DID (can be found at https://tangled.org/settings): " + ssh-keygen -t ed25519 -C $email -f $key_path + + touch ~/.ssh + chmod 700 ~/.ssh + touch $config + chmod 600 $config + + [ + "Host tangled.org knot1.tangled.sh" + " User git" + " IdentityFile ~/.ssh/id_ed25519" + " AddressFamily inet" + ] + | str join "\n" + | save -a $config + + print "Finished setting up SSH key" + + let pubkey = open --raw $pubkey_path + print $"IMPORTANT: Copy the key to your profile \(https://tangled.org/settings/keys\): `($pubkey)`" + + loop { + match (input "Would you like to set up commit signing for Git and Jujutsu? This will override any existing commit signing settings. [y/N]: ") { + "y" | "yes" => (break) + "n" | "no" | "" | null => (exit) + } + } + + if $jj { + jj config set --user signing.behavior "own" + jj config set --user signing.backend "ssh" + jj config set --user signing.key $key_path + jj config set --user signing.backends.ssh.allowed-signers ".allowed_signers" + jj config set --user signing.backends.ssh.revocation-list ".revoked_keys" + + print "Successfully set up commit signing for Jujutsu" + } else { + print "Jujustu is not installed, skipping" + } + + git config set --global user.signingKey $key_path + git config set --global gpg.format "ssh" + git config set --global commit.gpgSign true + + print "Successfully set up commit signing for Git" +}