Last active
September 25, 2025 10:10
-
-
Save mikaelhadler/53281f3bcea9182a94c909b9c504bb18 to your computer and use it in GitHub Desktop.
Copy the URL showed when used Netlify watch on CLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # ntl-clip.sh — Copy the first Netlify deploy URL from `netlify watch` to the clipboard. | |
| # Works on Ubuntu with X11 using xclip. | |
| # | |
| # Requirements: | |
| # sudo apt update && sudo apt install -y xclip | |
| # | |
| # Usage: | |
| # 1) Make sure Netlify CLI is linked to your project (`netlify init` or `netlify link`). | |
| # 2) Run: bash ./ntl-clip.sh | |
| # 3) Paste the copied URL (Ctrl+V) into your browser. | |
| set -euo pipefail | |
| # Ensure xclip is available | |
| if ! command -v xclip >/dev/null 2>&1; then | |
| echo "Error: xclip is not installed. Please install it with: sudo apt install -y xclip" >&2 | |
| exit 1 | |
| fi | |
| # Extract the first URL from netlify watch, strip ANSI codes and whitespace | |
| URL="$( | |
| netlify watch \ | |
| | grep --color=never -m1 "URL:" \ | |
| | sed -r 's/\x1B\[[0-9;]*[mK]//g' \ | |
| | awk -F': ' '{print $2}' \ | |
| | sed -E 's/^[[:space:]]+|[[:space:]]+$//g' \ | |
| || true | |
| )" | |
| if [ -z "${URL:-}" ]; then | |
| echo "Error: Could not extract a URL from 'netlify watch'." >&2 | |
| exit 2 | |
| fi | |
| # Copy to clipboard | |
| printf '%s' "$URL" | xclip -selection clipboard | |
| echo "Copied to clipboard:" | |
| echo " $URL" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment