Make Copy URL use native clipboard host

This commit is contained in:
David Heinemeier Hansson
2026-07-22 17:25:28 -07:00
parent 6a047462e8
commit 475211a5d4
12 changed files with 162 additions and 103 deletions
+50
View File
@@ -0,0 +1,50 @@
#!/bin/bash
# omarchy:summary=Native messaging host: copy a Chromium tab URL to the clipboard
# omarchy:hidden=true
set -euo pipefail
SCRIPT_PATH="${BASH_SOURCE[0]}"
export OMARCHY_PATH="${OMARCHY_PATH:-$(cd -- "$(dirname -- "$SCRIPT_PATH")/.." && pwd)}"
export PATH="$OMARCHY_PATH/bin:/usr/local/bin:/usr/bin:$PATH"
parse_url() {
jq -r '.url // empty' 2>/dev/null <<<"$1" || true
}
copy_url() {
local url="$1"
[[ -n $url ]] || return 1
printf '%s' "$url" | wl-copy --type text/plain
omarchy-notification-send -g 󰅍 "URL copied to clipboard"
}
reply_copied() {
if [[ $1 == "true" ]]; then
printf '\x0f\x00\x00\x00{"copied":true}'
else
printf '\x10\x00\x00\x00{"copied":false}'
fi
}
main() {
local length payload url
length=$(head -c4 | od -An -v -tu4 --endian=little | tr -d ' ')
[[ -n ${length:-} ]] && (( length > 0 )) || exit 0
payload=$(head -c "$length")
url=$(parse_url "$payload")
if copy_url "$url"; then
reply_copied true
else
reply_copied false
fi
}
if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
main "$@"
fi
+1
View File
@@ -17,6 +17,7 @@ announce_browser_installed() {
copy_chromium_flags() {
mkdir -p ~/.config
cp -f "$OMARCHY_PATH/config/chromium-flags.conf" "$1"
omarchy-install-chromium-copy-url
omarchy-install-chromium-ytdlp
}
+28
View File
@@ -0,0 +1,28 @@
#!/bin/bash
# omarchy:summary=Install the native messaging host for the Copy URL Chromium extension
set -euo pipefail
HOST_NAME="com.omarchy.copy_url"
HOST_PATH="$OMARCHY_PATH/bin/omarchy-chromium-copy-url-host"
TEMPLATE="$OMARCHY_PATH/default/chromium/native-messaging-hosts/$HOST_NAME.json"
browser_dirs=(
"$HOME/.config/chromium"
"$HOME/.config/google-chrome"
"$HOME/.config/google-chrome-beta"
"$HOME/.config/google-chrome-unstable"
"$HOME/.config/BraveSoftware/Brave-Browser"
"$HOME/.config/BraveSoftware/Brave-Browser-Beta"
"$HOME/.config/BraveSoftware/Brave-Browser-Nightly"
"$HOME/.config/microsoft-edge"
"$HOME/.config/microsoft-edge-dev"
)
manifest=$(sed "s|__HOST_PATH__|$HOST_PATH|g" "$TEMPLATE")
for dir in "${browser_dirs[@]}"; do
mkdir -p "$dir/NativeMessagingHosts"
printf '%s\n' "$manifest" >"$dir/NativeMessagingHosts/$HOST_NAME.json"
done
+2 -1
View File
@@ -15,7 +15,8 @@ fi
# Refresh the Chromium configuration
omarchy-refresh-config chromium-flags.conf
# Install/refresh the native messaging host used by the yt-dlp extension
# Install/refresh the native messaging hosts used by the bundled extensions
omarchy-install-chromium-copy-url
omarchy-install-chromium-ytdlp
# Re-install Google accounts if previously configured