* Share the git URL check between theme-install and plugin-add Both commands clone a URL a stranger can choose, and each carried its own copy of the rule that refuses a git option or a `<helper>::<address>` transport helper before cloning. Two copies of a security check drift: the second one arrived four months after the first, and only because someone went looking for it. The rule now lives in omarchy-git-url-check and the callers ask it. Its absence refuses the URL rather than waving it through, since the callers read a non-zero status as a refusal and a missing command exits 127. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Co-Authored-By: Codex XHigh <noreply@openai.com> * Refuse a git URL naming a transport Omarchy does not clone from `<helper>::<address>` is only one of the two ways a URL reaches a remote helper. git also resolves git-remote-<scheme> for `<scheme>://<address>` whenever the scheme is not one it connects itself, so `ext::sh -c id` and `ext://sh -c id` arrive at the same helper while only the first was refused. That shape cannot be refused outright, because it is also how every legitimate URL arrives, so the scheme is checked against the transports git still connects itself. `git+ssh` and `ssh+git` are on that list: they are spelled like a helper and read as plain ssh, and leaving them off would refuse a URL that clones today. `ext` and `fd` are off it deliberately -- git ships a helper for each, and `ext` runs whatever command the URL carries. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Co-Authored-By: Codex XHigh <noreply@openai.com> --------- Co-authored-by: David Heinemeier Hansson <david@hey.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Codex XHigh <noreply@openai.com>
54 lines
1.9 KiB
Bash
Executable File
54 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# omarchy:summary=Install a theme from a git repository
|
|
# omarchy:args=[git-repo-url]
|
|
# omarchy:examples=omarchy theme install https://github.com/example/omarchy-example-theme.git
|
|
# omarchy:examples=omarchy theme install git@github.com:example/omarchy-example-theme.git
|
|
|
|
if [[ -z $1 ]]; then
|
|
echo -e "\e[32mSee https://omarchy.org/themes/\n\e[0m"
|
|
REPO_URL=$(gum input --placeholder="Git repo URL (https or git@host:org/repo.git)" --header="")
|
|
else
|
|
REPO_URL="$1"
|
|
fi
|
|
|
|
if [[ -z $REPO_URL ]]; then
|
|
exit 1
|
|
fi
|
|
|
|
# Refuse a URL that names a git option or a transport helper before cloning. The
|
|
# check is shared with omarchy-plugin-add and explains itself; a missing checker
|
|
# leaves this non-zero, which refuses the URL rather than cloning it.
|
|
omarchy-git-url-check "$REPO_URL" || exit 1
|
|
|
|
THEMES_DIR="$HOME/.config/omarchy/themes"
|
|
|
|
# Strip user@host: prefix from scp-style SSH URLs so basename sees just the path
|
|
REPO_PATH="$REPO_URL"
|
|
[[ $REPO_PATH != *"://"* && $REPO_PATH == *:*/* ]] && REPO_PATH="${REPO_PATH#*:}"
|
|
THEME_NAME=$(basename -- "$REPO_PATH" .git | sed -E 's/^omarchy-//; s/-theme$//' | tr '[:upper:]' '[:lower:]')
|
|
THEME_PATH="$THEMES_DIR/$THEME_NAME"
|
|
|
|
# The name comes from the URL and is joined into a path that is about to be
|
|
# removed, so a repo called `..` would take ~/.config/omarchy with it. A leading
|
|
# dot is refused with it: `host:-s/foo.git` leaves basename with `.git`.
|
|
if [[ -z $THEME_NAME || $THEME_NAME == .* || $THEME_NAME == */* ]]; then
|
|
echo "Error: '$REPO_URL' does not give a usable theme name."
|
|
exit 1
|
|
fi
|
|
|
|
# Remove existing theme if present
|
|
if [[ -d $THEME_PATH ]]; then
|
|
rm -rf "$THEME_PATH"
|
|
fi
|
|
|
|
# Clone the repo directly to ~/.config/omarchy/themes
|
|
if ! git clone -- "$REPO_URL" "$THEME_PATH"; then
|
|
echo "Error: Failed to clone theme repo."
|
|
exit 1
|
|
fi
|
|
|
|
# Apply the new theme with omarchy-theme-set, which stages only the files an
|
|
# extra theme is allowed to contribute and names anything it dropped.
|
|
omarchy-theme-set "$THEME_NAME"
|