first commit

This commit is contained in:
Till Dieminger
2025-08-30 21:32:46 +02:00
commit 54f93fd462
32 changed files with 9214 additions and 0 deletions

75
mystuff/st-linkhandler Executable file
View File

@@ -0,0 +1,75 @@
#!/bin/sh
# A script to automatically detect links and weechat-matrix files.
# Opens dmenuhandler for selected links,
# decrypts and rifles selected weechat-matrix files.
buffer="$(cat)"
#URLs:
urlregex="(((http|https|gopher|gemini|ftp|ftps|git)://|www\\.)[a-zA-Z0-9.]*[:]?[a-zA-Z0-9./@$&%?$\#=_~-]*)|((magnet:\\?xt=urn:btih:)[a-zA-Z0-9]*)"
urls="$(echo "$buffer" | sed 's/.*│//g' | tr -d '\n' | # First remove linebreaks and mutt sidebars:
grep -aEo "$urlregex" | # grep only urls as defined above.
awk '!seen[$0]++' | # Ignore duplicates but keep order of links
sed 's/^www./http:\/\/www\./g')" # xdg-open will not detect url without http://
#Weechat-matrix files:
all="$(echo "$buffer" | perl -pe 's/[^│]*([^│]*?)│/\1/' |
perl -pe 's/^.*?\| //' |
sed 's/ │.*//' |
head -n-2 | tr -d '\n'|
grep -aEo '(<[^]>]*>|\[[^ ]*\])' |
grep -Ev "<(Unable to|Message redacted)" )" #filter out <Unable to decrypt: and <Message redacted by: <user>...
[ -z "$all" ] && [ -z "$urls" ] && exit;
filenames="$( echo "$all" | grep -E '^<[^>]*>' | tr -d '<>')"
links="$( echo "$all" | grep -E '^\[' | tr -d [])"
echo "filenames:$filenames"
echo "links:$links"
if [ -n "$filenames" ]; then
selection="$( echo "$filenames" | tac)"
prompt="file"
if [ -n "$urls" ]; then
selection="$(printf "%s\n%s\n" "$selection" "$urls")"
prompt="file/link"
fi
elif [ -n "$urls" ]; then
selection="$urls"
prompt="link"
else
exit
fi
choice="$(echo "$selection" | dmenu -i -p "open which $prompt?" -l 10)"
[ -z "$choice" ] && exit
#TODO: check for robustness of multifile support
echo "$choice" | while read -r choiceline; do
#open dmenuhandler for URLs
if echo "$urls" | grep -qE "^$choiceline$"; then
dmenuhandler "$choiceline"
#decrypt and open weechat-matrix files
else
linenr="$(echo "$filenames" | awk "/$choiceline/ {print NR}")"
#TODO: fix this stupid implementation, what if both were selected?
if [ "$(echo "$linenr" | wc -l)" -gt 1 ]; then
notify-send "weechatdl" "Multiple files by that name, choose by URL"
link="$(echo "$links" | tac | dmenu -i -p 'open which file?' -l 10)"
else
link="$(echo "$links" | awk "NR==$linenr")"
fi
echo "link:$link"
if [ "$(echo "$link" | wc -l)" -eq 1 ]; then
if echo "$link" | grep -qE '^emxc'; then
echo Decrypting...
matrix_decrypt --plumber rifle "$link" #"/tmp/$choiceline"
else
echo Curling...
curl -L "$link" -o "/tmp/$choiceline"
rifle "/tmp/$choiceline"
fi
else
notify-send "weechatdls" "multi-link downloads not yet supported"
fi
fi
done

21
mystuff/st-urlhandler Executable file
View File

@@ -0,0 +1,21 @@
#!/bin/sh
urlregex="(((http|https|gopher|gemini|ftp|ftps|git)://|www\\.)[a-zA-Z0-9.]*[:]?[a-zA-Z0-9./@$&%?$\#=_~-]*)|((magnet:\\?xt=urn:btih:)[a-zA-Z0-9]*)"
urls="$(sed 's/.*│//g' | tr -d '\n' | # First remove linebreaks and mutt sidebars:
grep -aEo "$urlregex" | # grep only urls as defined above.
awk '!seen[$0]++' | # Ignore duplicates but keep order of links
sed 's/^www./http:\/\/www\./g')" # xdg-open will not detect url without http://
[ -z "$urls" ] && exit 1
while getopts "hoc" o; do case "${o}" in
h) printf "Optional arguments for custom use:\\n -c: copy\\n -o: xdg-open\\n -h: Show this message\\n" && exit 1 ;;
o) chosen="$(echo "$urls" | dmenu -i -p 'Follow which url?' -l 10)"
qutebrowser "$chosen" ;;
# dmenuhandler "$chosen" ;;
#setsid xdg-open "$chosen" >/dev/null 2>&1 & ;;
c) echo "$urls" | dmenu -i -p 'Copy which url?' -l 10 | tr -d '\n' | xclip -selection clipboard ;;
*) printf "Invalid option: -%s\\n" "$OPTARG" && exit 1 ;;
esac done

78
mystuff/st-wee Executable file
View File

@@ -0,0 +1,78 @@
#!/bin/sh
# A script to automatically detect links and weechat-matrix files.
# Opens dmenuhandler for selected links,
# decrypts and rifles selected weechat-matrix files.
buffer="$(cat)"
#URLs:
urlregex="(((http|https|gopher|gemini|ftp|ftps|git)://|www\\.)[a-zA-Z0-9.]*[:]?[a-zA-Z0-9./@$&%?$\#=_~-]*)|((magnet:\\?xt=urn:btih:)[a-zA-Z0-9]*)"
urls="$(echo "$buffer" | sed 's/.*│//g' | tr -d '\n' | # First remove linebreaks and mutt sidebars:
grep -aEo "$urlregex" | # grep only urls as defined above.
awk '!seen[$0]++' | # Ignore duplicates but keep order of links
sed 's/^www./http:\/\/www\./g')" # xdg-open will not detect url without http://
#Weechat-matrix files:
all="$(echo "$buffer" | perl -pe 's/[^│]*([^│]*?)│/\1/' |
perl -pe 's/^.*?\| //' |
sed 's/ │.*//' |
head -n-2 | tr -d '\n'|
grep -aEo '(<[^]>]*>|\[[^ ]*\])' |
grep -Ev "<(Unable to|Message redacted)" )" #filter out <Unable to decrypt: and <Message redacted by: <user>...
[ -z "$all" ] && [ -z "$urls" ] && exit;
filenames="$( echo "$all" | sed -n '/\[*\]/{g;1!p};h' | tr -d '<>')"
links="$( echo "$all" | grep -E '^\[' | tr -d [])"
#Debugging:
#echo "filenames:$filenames"
#echo "links:$links"
#echo "urls:$urls"
if [ -n "$filenames" ]; then
selection="$( echo "$filenames" | tac)"
prompt="file"
if [ -n "$urls" ]; then
selection="$(printf "%s\n%s\n" "$selection" "$urls")"
prompt="file/link"
fi
elif [ -n "$urls" ]; then
selection="$urls"
prompt="link"
else
exit
fi
choice="$(echo "$selection" | dmenu -i -p "open which $prompt?" -l 10)"
[ -z "$choice" ] && exit
#TODO: check for robustness of multifile support
echo "$choice" | while read -r choiceline; do
#open dmenuhandler for URLs
if echo "$urls" | grep -q "^$choiceline$"; then
dmenuhandler "$choiceline"
#decrypt and open weechat-matrix files
else
linenr="$(echo "$filenames" | awk "/$choiceline/ {print NR}")"
#TODO: fix this stupid implementation, what if both were selected?
if [ "$(echo "$linenr" | wc -l)" -gt 1 ]; then
notify-send "weechatdl" "Multiple files by that name, choose by URL"
link="$(echo "$links" | tac | dmenu -i -p 'open which file?' -l 10)"
else
link="$(echo "$links" | awk "NR==$linenr")"
fi
echo "link:$link"
if [ "$(echo "$link" | wc -l)" -eq 1 ]; then
if echo "$link" | grep -qE '^emxc'; then
echo Decrypting...
matrix_decrypt --plumber rifle "$link" #"/tmp/$choiceline"
else
echo Curling...
curl -L "$link" -o "/tmp/$choiceline"
rifle "/tmp/$choiceline"
fi
else
notify-send "weechatdls" "multi-link downloads not yet supported"
fi
fi
done