-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathread_article.sh
More file actions
executable file
·60 lines (54 loc) · 1.55 KB
/
Copy pathread_article.sh
File metadata and controls
executable file
·60 lines (54 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
#
# read_article.sh - Quick article reader from clipboard
#
# Usage:
# 1. Copy article URL to clipboard
# 2. Run: ./read_article.sh
# 3. Article opens in bat pager with Markdown syntax highlighting
#
# Requirements:
# - bat (https://github.com/sharkdp/bat)
# - macOS: pbpaste (built-in)
# - Linux: xsel or xclip
#
# Installation:
# macOS: brew install bat
# Linux: apt install bat xsel # or xclip
set -euo pipefail
# Check if bat is installed
if ! command -v bat &> /dev/null; then
echo "Error: bat is not installed. Install with:"
echo " macOS: brew install bat"
echo " Linux: apt install bat"
exit 1
fi
# Get URL from clipboard based on OS
if [[ $(uname) == "Darwin" ]]; then
# macOS: use pbpaste
url=$(pbpaste)
elif [[ $(uname) == "Linux" ]]; then
# Linux: try xsel first, fallback to xclip
if command -v xsel &> /dev/null; then
url=$(xsel -ob) # clipboard selection (-op for primary/middle-click)
elif command -v xclip &> /dev/null; then
url=$(xclip -selection clipboard -o)
else
echo "Error: Neither xsel nor xclip found. Install one:"
echo " apt install xsel"
echo " apt install xclip"
exit 1
fi
else
echo "Error: Unsupported OS: $(uname)"
exit 1
fi
# Validate URL
if [[ ! $url =~ ^https?:// ]]; then
echo "Error: Clipboard does not contain a valid URL"
echo "Clipboard content: $url"
exit 1
fi
echo "Reading article from: $url"
# Run kiosque with verbose logging and pipe to bat
uv run kiosque -v "$url" - | bat - -l md