From 600eb74830e7778450229f6ef3a40a86292f7673 Mon Sep 17 00:00:00 2001 From: Luis Guilherme Coelho Date: Sat, 23 Mar 2024 03:11:36 -0300 Subject: [PATCH] radio: files: .local/bin --- .../radio/files/.local/bin/lf/preview | 116 ++++++++++++++++++ home-environments/radio/files/.local/bin/xkcd | 13 ++ home-environments/radio/files/.local/cam | 3 + .../radio/files/.local/colorpanes | 24 ++++ .../radio/files/.local/screenshot | 21 ++++ home-environments/radio/files/.local/sx | 19 +++ 6 files changed, 196 insertions(+) create mode 100755 home-environments/radio/files/.local/bin/lf/preview create mode 100755 home-environments/radio/files/.local/bin/xkcd create mode 100755 home-environments/radio/files/.local/cam create mode 100755 home-environments/radio/files/.local/colorpanes create mode 100755 home-environments/radio/files/.local/screenshot create mode 100755 home-environments/radio/files/.local/sx diff --git a/home-environments/radio/files/.local/bin/lf/preview b/home-environments/radio/files/.local/bin/lf/preview new file mode 100755 index 0000000..2d7b482 --- /dev/null +++ b/home-environments/radio/files/.local/bin/lf/preview @@ -0,0 +1,116 @@ +#!/bin/sh + +set -exu + +WIDTH=$2 +HEIGHT=$3 +image() { + chafa -f sixel \ + -s "$((${WIDTH}-2))x$((${HEIGHT}-2))" \ + --polite on \ + --animate on "$1" +} + +batorcat() { + shift + if command -v bat > /dev/null 2>&1; then + bat --color=always --style=plain --pager=never "$1" + else + cat "$1" + fi +} + +FILE=$(readlink -f "$1") +CACHE="$HOME/.cache/lf/thumbnail.$(stat --printf '%n\0%i\0%F\0%s\0%W\0%Y' -- "$FILE" | sha256sum | awk '{print $1}')" + +case "${FILE}" in + *.bmp|*.jpg|*.jpeg|*.png|*.xpm|*.webp|*.gif|*.jfif) + image "${FILE}" + exit 1 + ;; + *.pdf) + [ ! -f "${CACHE}.jpg" ] && pdftoppm -jpeg -f 1 -singlefile "${FILE}" "${CACHE}" + image "${CACHE}.jpg" + exit 1 + ;; + *.svg) + [ ! -f "${CACHE}.jpg" ] && convert "${FILE}" "${CACHE}.jpg" + image "${CACHE}.jpg" + exit 1 + ;; + *.avi|*.mp4|*.wmv|*.dat|*.3gp|*.ogv|*.mkv|*.mpg|*.mpeg|*.vob|*.fl[icv]|*.m2v|*.mov|*.webm|*.ts|*.mts|*.m4v|*.r[am]|*.qt|*.divx) + [ ! -f "${CACHE}.jpg" ] && ffmpegthumbnailer -i "${FILE}" -o "${CACHE}.jpg" -s 0 -q 5 + image "${CACHE}.jpg" + exit 1 + ;; + *.wav|*.mp3|*.flac|*.m4a|*.wma|*.ape|*.ac3|*.og[agx]|*.spx|*.opus|*.as[fx]|*.mka) + exiftool "${FILE}" + ;; + *.epub) + [ ! -f "${CACHE}" ] && epub-thumbnailer "${FILE}" "${CACHE}" 1024 + image "${CACHE}" + ;; + *.cbz|*.cbr|*.cbt) + [ ! -f "${CACHE}" ] && comicthumb "${FILE}" "${CACHE}" 1024 + image "${CACHE}" + ;; + *.tgz|*.tar.gz) + tar tzf "${FILE}" + ;; + *.tar.bz2|*.tbz2) + tar tjf "${FILE}" + ;; + *.tar.txz|*.txz) + xz --list "${FILE}" + ;; + *.tar) + tar tf "${FILE}" + ;; + *.zip|*.jar|*.war|*.ear|*.oxt) + unzip -l "${FILE}" + ;; + *.rar) + unrar l "${FILE}" + ;; + *.md) + glow -s dark "${FILE}" + ;; + *.7z) + 7z l "${FILE}" + ;; + *.[1-8]) + man "${FILE}" | col -b + ;; + *.o) + nm "${FILE}" + ;; + *.torrent) + transmission-show "${FILE}" + ;; + *.iso) + iso-info --no-header -l "${FILE}" + ;; + *.odt|*.ods|*.odp|*.sxw) + odt2txt "${FILE}" + ;; + *.doc) + catdoc "${FILE}" + ;; + *.docx) + docx2txt "${FILE}" - + ;; + *.xml|*.html) + w3m -dump "${FILE}" + ;; + *.xls|*.xlsx) + ssconvert --export-type=Gnumeric_stf:stf_csv "${FILE}" "fd://1" | batorcat --language=csv + ;; + *.ino) + batorcat --language=cpp "${FILE}" + ;; + *) + cat "${FILE}" + ;; +esac + +exit 0 diff --git a/home-environments/radio/files/.local/bin/xkcd b/home-environments/radio/files/.local/bin/xkcd new file mode 100755 index 0000000..d8ec0b0 --- /dev/null +++ b/home-environments/radio/files/.local/bin/xkcd @@ -0,0 +1,13 @@ +#!/bin/sh + +if [ $# -gt 0 ] && [ $1 = "-r" ]; then + URL=https://c.xkcd.com/random/comic +else + URL=https://xkcd.com/ +fi +URL=$(curl -s -L $URL \ + | grep 'href= "https://imgs.xkcd.com/comics.*' \ + | cut -d'>' -f2 \ + | cut -d'<' -f1) +curl $URL --output /tmp/xkcd 2>/dev/null +chafa /tmp/xkcd diff --git a/home-environments/radio/files/.local/cam b/home-environments/radio/files/.local/cam new file mode 100755 index 0000000..dcb6c9c --- /dev/null +++ b/home-environments/radio/files/.local/cam @@ -0,0 +1,3 @@ +#!/bin/sh + +setsid -f mpv av://v4l2:/dev/video0 --profile=low-latency --vf=hflip --untimed diff --git a/home-environments/radio/files/.local/colorpanes b/home-environments/radio/files/.local/colorpanes new file mode 100755 index 0000000..1fb1d40 --- /dev/null +++ b/home-environments/radio/files/.local/colorpanes @@ -0,0 +1,24 @@ +#!/usr/bin/env -S guix shell bash -- bash + +# Author: GekkoP +# Source: http://linuxbbq.org/bbs/viewtopic.php?f=4&t=1656#p33189 + +f=3 b=4 +for j in f b; do + for i in {0..7}; do + printf -v $j$i %b "\e[${!j}${i}m" + done +done +d=$'\e[1m' +t=$'\e[0m' +v=$'\e[7m' + + +cat << EOF + + $f0████$d▄$t $f1████$d▄$t $f2████$d▄$t $f3████$d▄$t $f4████$d▄$t $f5████$d▄$t $f6████$d▄$t $f7████$d▄$t + $f0████$d█$t $f1████$d█$t $f2████$d█$t $f3████$d█$t $f4████$d█$t $f5████$d█$t $f6████$d█$t $f7████$d█$t + $f0████$d█$t $f1████$d█$t $f2████$d█$t $f3████$d█$t $f4████$d█$t $f5████$d█$t $f6████$d█$t $f7████$d█$t + $d$f0 ▀▀▀▀ $d$f1 ▀▀▀▀ $f2▀▀▀▀ $f3▀▀▀▀ $f4▀▀▀▀ $f5▀▀▀▀ $f6▀▀▀▀ $f7▀▀▀▀$t + +EOF diff --git a/home-environments/radio/files/.local/screenshot b/home-environments/radio/files/.local/screenshot new file mode 100755 index 0000000..c12f6b9 --- /dev/null +++ b/home-environments/radio/files/.local/screenshot @@ -0,0 +1,21 @@ +#!/bin/sh + +case "$1" in + "activewindow") + # Get active window geometry + eval $(xdotool getactivewindow getwindowgeometry --shell) + REGION="$((${WIDTH} + 10))x$((${HEIGHT}+10))+$((${X}-5))+$((${Y}-5))" + maim -Bg "${REGION}" | xclip -selection clipboard -t image/png;; + "selectwindow") + # Let the user select a window and get its geometry + eval $(xdotool selectwindow getwindowgeometry --shell) + REGION="$((${WIDTH} + 10))x$((${HEIGHT}+10))+$((${X}-5))+$((${Y}-5))" + maim -Bg "${REGION}" | xclip -selection clipboard -t image/png;; + "selectregion") + maim -s | xclip -selection clipboard -t image/png;; + *) + # Get current screen + SCREEN=$(xdotool get_desktop) + REGION="$(hostname):${SCREEN}.1" + maim -u | xclip -selection clipboard -t image/png;; +esac diff --git a/home-environments/radio/files/.local/sx b/home-environments/radio/files/.local/sx new file mode 100755 index 0000000..555530b --- /dev/null +++ b/home-environments/radio/files/.local/sx @@ -0,0 +1,19 @@ +#!/bin/sh +set -exu + +tty=$(tty) +tty=${tty#/dev/tty} + +dir=$(which Xorg) +dir=${dir%/bin/Xorg} + +display=0 +while [ -e "/tmp/.X$display-lock" ] || [ -S "/tmp/.X11-unix/X$display" ]; do + : "$((display += 1))" +done +display=:$display + +"$dir/bin/xinit" -- "$dir/bin/Xorg" "$display" "vt$tty" \ + -keeptty \ + -configdir "$dir/share/X11/xorg.conf.d" \ + -modulepath "$dir/lib/xorg/modules"