Created
July 15, 2026 03:41
-
-
Save teklynk/6c88b04ff4b51acad63365c9ac98fb0d to your computer and use it in GitHub Desktop.
Bash script that opens Twitch video player and chat pop-out using your default browser. No clutter. Just re-sizable pop-out windows.
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 | |
| if [[ $# -eq 0 ]]; then | |
| echo "Usage: twitch channel1 channel2 ..." | |
| exit 1 | |
| fi | |
| # --- Detect Default Browser --- | |
| detect_default_browser() { | |
| local default_browser="" | |
| # Try xdg-settings first (most common method) | |
| if command -v xdg-settings &>/dev/null; then | |
| default_browser=$(xdg-settings get default-web-browser 2>/dev/null | sed 's/.desktop$//') | |
| fi | |
| # If xdg-settings didn't work, try update-alternatives (Debian/Ubuntu) | |
| if [[ -z "$default_browser" ]] && command -v update-alternatives &>/dev/null; then | |
| default_browser=$(update-alternatives --display x-www-browser 2>/dev/null | grep -m1 '/usr/bin/' | awk '{print $1}') | |
| fi | |
| # Map browser names to paths | |
| case "$default_browser" in | |
| *brave*) | |
| echo "/usr/bin/brave-browser" 2>/dev/null || echo "/usr/bin/brave" | |
| ;; | |
| *chrome*|*chromium*) | |
| if [[ -x /usr/bin/google-chrome ]]; then | |
| echo "/usr/bin/google-chrome" | |
| elif [[ -x /usr/bin/chromium ]]; then | |
| echo "/usr/bin/chromium" | |
| else | |
| echo "/usr/bin/google-chrome-stable" | |
| fi | |
| ;; | |
| *firefox*) | |
| echo "/usr/bin/firefox" | |
| ;; | |
| *edge*|*microsoft*) | |
| if [[ -x /usr/bin/microsoft-edge ]]; then | |
| echo "/usr/bin/microsoft-edge" | |
| else | |
| echo "/usr/bin/edge" | |
| fi | |
| ;; | |
| *) | |
| # Fallback: try to find any executable browser | |
| for path in "/usr/bin/brave-browser" "/usr/bin/brave" "/usr/bin/google-chrome" \ | |
| "/usr/bin/chromium" "/usr/bin/firefox" "/usr/bin/microsoft-edge"; do | |
| if [[ -x "$path" ]]; then | |
| echo "$path" | |
| return | |
| fi | |
| done | |
| ;; | |
| esac | |
| } | |
| BROWSER_CMD=$(detect_default_browser) | |
| # Verify we found an executable browser | |
| if [[ -z "$BROWSER_CMD" ]] || ! [[ -x "$BROWSER_CMD" ]]; then | |
| echo "Error: Could not detect or find a supported browser." | |
| echo "Please install Brave, Chrome, Firefox, Chromium, or Edge." | |
| exit 1 | |
| fi | |
| echo "Using detected default browser: $(basename "$BROWSER_CMD")" | |
| # --- Open URLs for each channel --- | |
| for CHANNEL in "$@"; do | |
| STREAM_URL="https://player.twitch.tv/?channel=${CHANNEL}&parent=localhost" | |
| CHAT_URL="https://www.twitch.tv/popout/${CHANNEL}/chat" | |
| echo "Opening stream and chat for: ${CHANNEL}" | |
| # Open Stream | |
| "$BROWSER_CMD" --disable-gpu --no-first-run --app="${STREAM_URL}" & | |
| # Open Chat (small delay to ensure separate windows) | |
| sleep 0.5 | |
| "$BROWSER_CMD" --disable-gpu --no-first-run --app="${CHAT_URL}" & | |
| # Small delay between channels to avoid overwhelming the browser | |
| sleep 0.5 | |
| done | |
| echo "Done. All streams and chats opened." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment