monofetch (1676B)
1 #!/usr/bin/env bash 2 3 if [[ -n "$1" ]]; then 4 url="$1" 5 else 6 wl_focused_title="$(wlr-river-title)" 7 if [[ "$wl_focused_title" == *"Mozilla Firefox"* ]]; then 8 /usr/bin/wtype "yy" && sleep 0.5 9 url=$(wl-paste 2>/dev/null) 10 else 11 notify-send -u critical "Error" "Focused window is not a web browser ($wl_focused_title)" 12 exit 1 13 fi 14 fi 15 16 if [[ -z "$url" ]]; then 17 notify-send "No URL found" 18 exit 1 19 fi 20 21 if [[ ! "$url" =~ ^https?:// ]]; then 22 notify-send "Invalid URL format" "$url" 23 exit 1 24 fi 25 26 domain=$(echo "$url" | sed -e 's|^https\?://||' -e 's|/.*||' -e 's|^www\.||') 27 path_part=$(echo "$url" | sed -e 's|^https\?://||' -e 's|[?#].*||') 28 29 if [[ "$path_part" == */ ]] || [[ "$path_part" != */* ]]; then 30 if [[ "$path_part" != */* ]]; then 31 full_rel_path="$path_part/index.html" 32 else 33 full_rel_path="${path_part}index.html" 34 fi 35 else 36 full_rel_path="$path_part" 37 fi 38 39 full_rel_path="${full_rel_path//:/_}" 40 domain="${domain//:/_}" 41 42 target_file_path="$HOME/misc/www/$full_rel_path" 43 target_dir=$(dirname "$target_file_path") 44 45 md_slug=$(echo "$path_part" | tr ':/' '--' | sed 's/^-//;s/-$//') 46 if [[ -z "$md_slug" ]] || [[ "$md_slug" == "index.html" ]]; then 47 md_slug="index" 48 fi 49 50 md_filename="${domain}-${md_slug%.html}.md" 51 target_md_path="$HOME/misc/notes/www/$md_filename" 52 53 mkdir -p "$target_dir" || { 54 notify-send -u critical "Error" "Failed to create directory" 55 exit 1 56 } 57 if monolith -o "$target_file_path" "$url"; then 58 notify-send "Saved" "$url" 59 else 60 notify-send -u critical "Error" "Failed to download $url" 61 exit 1 62 fi 63 64 cat "$target_file_path" | html2markdown >"$target_md_path" 65 66 if [[ ! -s "$target_md_path" ]]; then 67 notify-send -u critical "Error" "Conversion failed" 68 fi