diff --git a/default.nix b/default.nix index 6a9fa03..c9c2506 100644 --- a/default.nix +++ b/default.nix @@ -1,7 +1,10 @@ { pkgs , scdoc , xclip +, maim , stdenvNoCC +, nushell +, xdotool , ... }: stdenvNoCC.mkDerivation rec { @@ -10,6 +13,7 @@ stdenvNoCC.mkDerivation rec { src = ./src; nativeBuildInputs = with pkgs; [ scdoc + nushell ]; buildPhase = '' @@ -18,11 +22,24 @@ stdenvNoCC.mkDerivation rec { done ''; + preConfig = '' + patchShebangs ./bin/* + ''; + installPhase = '' mkdir -p $out/{share/man/man1,bin,share/zsh/site-functions} cp bin/* $out/bin/ cp completions/* $out/share/zsh/site-functions/ cp *.1 $out/share/man/man1/ + + runHook postInstall + ''; + + postInstall = '' + substituteInPlace $out/bin/* \ + --replace "xclip" "${xclip}/bin/xclip" \ + --replace "maim" "${maim}/bin/maim" \ + --replace "xdotool" "${xdotool}/bin/xdotool" ''; } diff --git a/src/bin/invyt b/src/bin/invyt new file mode 100755 index 0000000..53dcc22 --- /dev/null +++ b/src/bin/invyt @@ -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) +} diff --git a/src/bin/maim-utils b/src/bin/maim-utils new file mode 100755 index 0000000..ffdf687 --- /dev/null +++ b/src/bin/maim-utils @@ -0,0 +1,91 @@ +#!/bin/sh +# Copyright 2023 Marty Sluijtman +# 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 < + + 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 diff --git a/src/bin/port b/src/bin/port new file mode 100755 index 0000000..561d5ed --- /dev/null +++ b/src/bin/port @@ -0,0 +1,5 @@ +#!/usr/bin/env nu + +def main [] { + random int 0..65535 +} diff --git a/src/bin/rimg b/src/bin/rimg new file mode 100755 index 0000000..d29843a --- /dev/null +++ b/src/bin/rimg @@ -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 + } +} diff --git a/src/completions/_maim-utils b/src/completions/_maim-utils new file mode 100644 index 0000000..a659441 --- /dev/null +++ b/src/completions/_maim-utils @@ -0,0 +1,6 @@ +#compdef maim-utils _maim-utils + +_arguments -C \ + "1: :(focus fullscreen selection clip-selection clip-fullscreen clip-focus show fancy fancy-clip)" \ + "*::args:->args" +_arguments : $arguments diff --git a/src/manpages/invyt.1.scd b/src/manpages/invyt.1.scd new file mode 100644 index 0000000..35ce007 --- /dev/null +++ b/src/manpages/invyt.1.scd @@ -0,0 +1,16 @@ +invyt(1) + +# NAME + +*invyt* - takes a not-quite-YouTube URL and turns it into one. Optionally it can +also download the vidoe or playlist in question. + +# TODO + +The rest of this manpage: +- flags +- sub commands + +# SEE ALSO + +*yt-dlp(1)* diff --git a/src/manpages/maim-utils.1.scd b/src/manpages/maim-utils.1.scd new file mode 100644 index 0000000..f3e9220 --- /dev/null +++ b/src/manpages/maim-utils.1.scd @@ -0,0 +1,59 @@ +maim-utils(1) + +# NAME + +maim-utils - A few common screenshot options rolled into one script based on maim + +# SYNOPSIS + +*maim-utils* __ + +*maim-utils* __ + +# DESCRIPTION + +I wrote around six scripts to take screenshots in various different ways a few +years ago and at some point I got the idea to turn it into a single script. +*maim-utils* is the result of that. It only took me a few years to finally get +to it. + +# CONFIGURATION + +*maim-utils* saves it's screenshots to '*~/Pictures/Screenshots*' by default. +This can be changed by setting the *$SCROTDIR* environment variable. + +# COMMANDS + +*fullscreen* and *full* + Take a screenshot of the entire screen and save it to the screenshot + directory. + +*selection* and *sel* + Take a screenshot based on a rectangular selection and save it to the + screenshot directory. + +*focus* + Take a screenshot of the currently focussed window and save it to the + screenshot directory. + +*fancy* + Take a screenshot of a window and add a fancy looking dropshadow effect + using imagemagick. + +*clip-fullscreen*, *clip-full* and *full-clip* + Take a screenshot of the entire screen and write it to the clipboard. + +*clip-focus* and *focus-clip* + Take a screenshot of the currently focus window and write it to the + clipboard. + +*fancy-clip* + Take a screenshot of a window, add a fancy looking dropshadow effect + using imagemagick and write it to the clipboard. + +*clip-selection*, *clip-sel* and *sel-clip* + Take a screenshot based on a rectangular selection and write it to the + clipboard. + +*open*, *show* and *screenshots* + Open the directory containing screenshots. diff --git a/src/manpages/port.1.scd b/src/manpages/port.1.scd new file mode 100644 index 0000000..5c77193 --- /dev/null +++ b/src/manpages/port.1.scd @@ -0,0 +1,14 @@ +port(1) + +# NAME + +*port* - returns a valid port number. + +Here the entire sourcecode: +``` +def main [] { + random int 0..65535 +} +``` + +In fact, this manpage is longer than the script its about. diff --git a/src/manpages/rimg.1.scd b/src/manpages/rimg.1.scd new file mode 100644 index 0000000..21c5802 --- /dev/null +++ b/src/manpages/rimg.1.scd @@ -0,0 +1,22 @@ +rimg(1) + +# NAME & DESCRIPTION + +*rimg* - takes a Reddit IMaGe URL and either downloads its contents or opens it +using *kitty(1)*'s icat kitten. + +By default it takes the URL from the clipboard using *xclip(1)*. + +# OPTIONS + +*--help -h* + Print usage and exit + +*--url -u* + Feed it the URL as parameter rather than from the clipboard. + +*--download -d* + +# SEE ALSO + +*kitty(1)* *xclip(1)* *wget(1)*