Few more scripts

This commit is contained in:
Nox Sluijtman 2024-05-14 15:40:21 +02:00
parent 13eedd1a1c
commit e17b945863
10 changed files with 305 additions and 0 deletions

43
src/bin/invyt Executable file
View file

@ -0,0 +1,43 @@
#!/usr/bin/env nu
def parse_url [url: string] {
let parsed_url = $url | url parse
let correct_string = ($parsed_url.path | grep -E "(playlist|watch)" | complete).exit_code
if ($correct_string == 0) {
if $parsed_url.host != "youtube.com" {
$url | str replace $parsed_url.host "youtube.com"
} else {
$url
}
} else {
error make {
msg: "Not a YouTube/Invidious/Piped URL"
label: {
text: "Expects a YouTube/Invidious/Piped URL"
span: (metadata $url).span
}
}
}
}
def main [ url: string
, --copy(-c)
] {
let $url = parse_url $url
match $copy {
true => { $url | xclip -sel clip }
false => $url
}
}
def "main download" [url: string] {
yt-dlp --embed-chapters --embed-metadata --embed-subs (parse_url $url)
}
def "main dl" [url: string] {
yt-dlp --embed-chapters --embed-metadata --embed-subs (parse_url $url)
}

91
src/bin/maim-utils Executable file
View file

@ -0,0 +1,91 @@
#!/bin/sh
# Copyright 2023 Marty Sluijtman <marty.wanderer@disroot.org>
# Distributed under the terms of the GPLv3 license
savedir="${SCROTDIR:-$HOME/Pictures/Screenshots}"
filename="$savedir/$(date -Iseconds)_maim.png"
# test whether the screenshot directory exists, if not, create it.
[ -d $savedir ] || mkdir -p $savedir
fullscreen(){
maim -ui root "$filename"
notify-send 'Maim utils' "Shot entire screen and saved output to:\n\n$filename"
}
selection(){
maim -su "$filename"
notify-send 'Maim utils' "Shot selection and saved output to:\n\n$filename\n\nBe aware that the selection process can be cancelled using any keypress and that this won't show up due to xclip eating the exit status."
}
focus(){
maim -ui "$(xdotool getactivewindow)" "$filename"
notify-send 'Maim utils' "Shot focussed window and saved output to:\n\n$filename"
}
clip_fullscreen(){
maim -ui root | xclip -sel clip -t image/png
notify-send 'Maim utils' "Shot entire screen and sent it to the clipboard."
}
clip_selection(){
maim -su | xclip -sel clip -t image/png
notify-send 'Maim utils' "Shot selection and sent it to the clipboard.\nBe aware that the selection process can be cancelled using any keypress and that this won't show up due to xclip eating the exit status."
}
clip_focus(){
maim -ui "$(xdotool getactivewindow)" | xclip -sel clip -t image/png
notify-send 'Maim utils' "Shot focussed window and sent it to the clipboard."
}
fancy_clip(){
# nicked straight from the maim README (https://github.com/naelstrof/maim#examples)
maim -st 9999999 | convert - \( +clone -background black -shadow 80x3+5+5 \) +swap -background none -layers merge +repage PNG:- | xclip -sel clip -t image/png
notify-send 'Maim utils' "Shot selection and sent it to the clipboard.\nBe aware that the selection process can be cancelled using any keypress and that this won't show up due to xclip eating the exit status."
}
fancy(){
# nicked straight from the maim README (https://github.com/naelstrof/maim#examples)
maim -st 9999999 | convert - \( +clone -background black -shadow 80x3+5+5 \) +swap -background none -layers merge +repage "$filename"
notify-send 'Maim utils' "Shot selection and sent it to the clipboard.\nBe aware that the selection process can be cancelled using any keypress and that this won't show up due to xclip eating the exit status."
}
usage(){
cat >&2 <<EOF
Usage: maim-utils <screenshot-type>
fullscreen|full: take screenshot of entire screen
selection|sel: take screenshot of rectangular selection
focus: take screenshot of focussed window
clip-fullscreen|clip-full|full-clip: take screenshot of entire screen and
output to clipboard
clip-selection|clip-sel|sel-clip: take screenshot of rectangular selection
and output to clipboard
clip-focus|focus-clip: take screenshot of focussed window and output to
clipboard
clip-selection|clip-sel|sel-clip: take screenshot of rectangular selection
and output to clipboard and give it a facy dropshadow
open|show|screenshots: open screenshot directory
EOF
}
case $1 in
sel|selection) selection;;
sel-clip|clip-sel|clip-selection) clip_selection;;
full|fullscreen) fullscreen;;
full-clip|clip-full|clip-fullscreen) clip_fullscreen;;
focus) focus;;
clip-focus|focus-clip) clip_focus;;
open|show|screenshots) xdg-open $savedir;;
fancy) fancy;;
fancy-clip) fancy_clip;;
*) usage;;
esac

5
src/bin/port Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env nu
def main [] {
random int 0..65535
}

32
src/bin/rimg Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env nu
# Takes a Reddit IMaGe URL and either downloads its contents or opens it using kitty's icat kitten.
def main [ --url(-u): string # Feed it the URL as parameter rather than from the clipboard
, --download(-d) # Downloads the image rather than opening it in icat
] {
let clipboard = xclip -o
let url = $url. | default $clipboard
match ($url | str contains "reddit.com") {
true => ($url | get_url)
false => ("URL is not a valid Reddit URL"; exit 1)
} | download_url $download
}
# Documentation for handle_url
def download_url [download: bool] {
let input = $in
match $download {
true => (wget $input)
false => (kitten icat $input)
}
}
def get_url [] {
let input = $in
let decoded = $input | url decode
match ($decoded | str contains "preview") {
true => ( ($decoded | parse "{reddit}={imageUrl}?{params}").imageUrl.0 | str replace "preview" "i" )
false => ($decoded | parse "{reddit}={imageUrl}").imageUrl.0
}
}