commit 1730b8cf3f868bec49a492fba4f9b6fc3e29eabf parent 3c9fcb000af9dc4f194c48faefb19297420d3160 Author: mtmn <miro@haravara.org> Date: Thu, 7 May 2026 15:48:40 +0200 dotfiles: add monofetch script Diffstat:
| A | modules/mixins/dotfiles/bin/monofetch | | | 65 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 65 insertions(+), 0 deletions(-)
diff --git a/modules/mixins/dotfiles/bin/monofetch b/modules/mixins/dotfiles/bin/monofetch @@ -0,0 +1,65 @@ +#!/usr/bin/env bash + +if [[ -n "$1" ]]; then + url="$1" +else + wl_focused_title="$(wlr-river-title)" + if [[ "$wl_focused_title" == *"Mozilla Firefox"* ]]; then + /usr/bin/wtype "yy" && sleep 0.5 + url=$(wl-paste 2>/dev/null) + else + notify-send -u critical "Error" "Focused window is not a web browser ($wl_focused_title)" + exit 1 + fi +fi + +if [[ -z "$url" ]]; then + notify-send "No URL found" + exit 1 +fi + +if [[ ! "$url" =~ ^https?:// ]]; then + notify-send "Invalid URL format" "$url" + exit 1 +fi + +domain=$(echo "$url" | sed -e 's|^https\?://||' -e 's|/.*||' -e 's|^www\.||') +path_part=$(echo "$url" | sed -e 's|^https\?://||' -e 's|[?#].*||') + +if [[ "$path_part" == */ ]] || [[ "$path_part" != */* ]]; then + if [[ "$path_part" != */* ]]; then + full_rel_path="$path_part/index.html" + else + full_rel_path="${path_part}index.html" + fi +else + full_rel_path="$path_part" +fi + +target_file_path="$HOME/misc/www/$full_rel_path" +target_dir=$(dirname "$target_file_path") + +md_slug=$(echo "$path_part" | tr '/' '-' | sed 's/^-//;s/-$//') +if [[ -z "$md_slug" ]] || [[ "$md_slug" == "index.html" ]]; then + md_slug="index" +fi + +md_filename="${domain}-${md_slug%.html}.md" +target_md_path="$HOME/misc/notes/www/$md_filename" + +mkdir -p "$target_dir" || { + notify-send -u critical "Error" "Failed to create directory" + exit 1 +} +if monolith -o "$target_file_path" "$url"; then + notify-send "Saved" "$url" +else + notify-send -u critical "Error" "Failed to download $url" + exit 1 +fi + +cat "$target_file_path" | html2markdown >"$target_md_path" + +if [[ ! -s "$target_md_path" ]]; then + notify-send -u critical "Error" "Conversion failed" +fi