podcast-files/Drew/rofi-notes.sh

65 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
# Configuration
REPO_API_BASE="https://git.thelinuxcast.org/api/v1/repos/tlc/notes"
SHORT_URL_BASE="https://git.thelinuxcast.org/notes"
# Function to convert full URL to short URL
convert_to_short_url() {
local file_path="$1"
echo "$SHORT_URL_BASE/$file_path"
}
# Get list of files recursively from git API
get_file_list() {
# Get the tree recursively from main branch
curl -s "$REPO_API_BASE/git/trees/main?recursive=true" | \
jq -r '.tree[] | select(.path | endswith(".md")) | select(.path | test("README.md") | not) | .path' | \
sort
}
# Detect clipboard tool and set copy function
setup_clipboard() {
if command -v wl-copy >/dev/null 2>&1; then
CLIPBOARD_CMD="wl-copy"
elif command -v xclip >/dev/null 2>&1; then
CLIPBOARD_CMD="xclip -selection clipboard"
else
echo "No clipboard tool found. Install wl-clipboard (Wayland) or xclip (X11)."
exit 1
fi
}
# Check if required tools are available
check_dependencies() {
local missing_deps=()
command -v curl >/dev/null 2>&1 || missing_deps+=("curl")
command -v jq >/dev/null 2>&1 || missing_deps+=("jq")
command -v rofi >/dev/null 2>&1 || missing_deps+=("rofi")
if [ ${#missing_deps[@]} -ne 0 ]; then
echo "Missing dependencies: ${missing_deps[*]}"
echo "Please install them first."
exit 1
fi
}
# Main script
check_dependencies
setup_clipboard
selected_file=$(get_file_list | rofi -dmenu -p "Select note file:" -i)
if [ -n "$selected_file" ]; then
# Convert to short URL
short_url=$(convert_to_short_url "$selected_file")
# Copy to clipboard
echo "$short_url" | $CLIPBOARD_CMD
# Optional: show notification
notify-send "URL Copied" "$short_url"
echo "Copied to clipboard: $short_url"
fi