💾 Archived View for laniakea.rodoste.de › tui › shorts.gmi captured on 2024-05-12 at 15:17:37. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-12-28)

-=-=-=-=-=-=-

🏠 home

various short shell commands

2023-12-14

This one contains a list of one-liners or short shell scripts to get stuff done.

conversions

convert video to gif

This one works in several steps: first analyze the video and generate an image that acts as color palette, then create the gif using the video and palette as inputs:

    # create palette
    ffmpeg -i video.mp4 -filter_complex "[0:v] palettegen" palette.png
    # converting to gif
    ffmpeg -i video.mp4 -i palette.png -filter_complex "[0:v][1:v] paletteuse" video.gif

convert images to a standard size with ImageMagick

    magick mogrify -path output/folder/ -resize 1000x1000^ -gravity center -monitor *.jpg

convert WAV to Ogg Vorbis

    #!/usr/bin/env bash

    if [ $# -ne 1 ]; then
      echo "converts an audio file to Ogg vorbis"
      echo "Usage $0 path/to/audiofile.wav"
      exit 1
    fi

    filepath=$1
    dirname=$(dirname "$filepath")
    filename=$(basename "$filepath")
    extension="${filename##*.}"
    basename="${filename%.*}"

    targetpath="$dirname/$basename.ogg"

    ffmpeg -i $filepath -c:a libvorbis $targetpath

convert numbers to different bases

this converts from base 10 to base 16

   echo "obase=16;" 73 | bc

This converts from base 16 to binary (base 2)

    echo "ibase=16;obase=2;" F | bc

All wrapped up in a script

    #!/usr/bin/env bash

    if [ $# -ne 2 ]; then
      basename=$(basename $0)
      echo "Converts a decimal number into another base"
      echo "Usage: $basename target_base decimal_number"
      echo
      echo "Examples:"
      echo "  $basename 2 30     converts decimal 30 to binary 11110"
      echo "  $basename 16 73    converts decimal 73 to hexadecimal 4B"
      exit 1
    fi

    decimalNum=$2
    obase=$1
    prefix=""

    # convert bases
    if   [[ $obase == "h" || $obase == "hex" ]]; then obase=16
    elif [[ $obase == "o" || $obase == "oct" ]]; then obase=8
    elif [[ $obase == "b" || $obase == "bin" ]]; then obase=2
    fi

    # helpful prefixes
    if   [ $obase -eq 16 ]; then prefix="0x"
    fi

    targetNum=$(echo "obase=$obase;$decimalNum" | bc)
    echo "$decimalNum in base $obase is $prefix$targetNum"

monitoring

Raspberry Pi 4 system health

    #!/usr/bin/env zsh

    sep='\033[0;34m//\033[0m'
    mem=`free --mega | awk 'NR==2 {printf "%.1f/%.1f GB\n", $3/1024, $2/1024}'`
    tmp=`head -1 /sys/class/thermal/thermal_zone0/temp | awk '{printf "%.1f°C\n", $0/1000}'`
    dsk=`df -h / | awk 'NR==2 {print "hdd: "$3" ("$5") of "$2}'`

    echo "$mem $sep $tmp $sep $dsk"

recording

record video and audio (Wayland WM)

I need the --geometry parameter to record only one monitor in my dual monitor setup.

    #!/usr/bin/env bash

    if [ $# -ne 1 ]; then
      basename=$(basename $0)
      echo "records the left screen as 720p video with audio"
      echo "Usage: $basename path/to/output.mkv"
      exit 1
    fi

    outputFile=$1
    audioDevice="alsa_output.usb-Logitech_Logitech_USB_Headset_000000000000-00.analog-stereo.monitor"

    wf-recorder -g "0,0 1920x1080" -R 44100 -F "scale=-1:720" -a=$audioDevice -f "$outputFile"

web-related

download a single webpage as markdown

Instead of `commonmark_x` you can experiment with `commonmark`, `markdown_strict` or simply `markdown`

    #!/usr/bin/env zsh
    # Uses pandoc to download a file and convert it to a markdown file

    binPandoc=$(which pandoc)

    if [ $# -ne 2 ]; then
      echo "Usage: "
      echo "$0 URL filename"
      exit 1
    fi

    $binPandoc --from=html --to=commonmark_x --standalone --embed-resources=false --output=$2 $1

download all pages in a website directory, but nothing above it

This will convert relative links so they still work after downloading.

    wget --convert-links --page-requisites --recursive --no-parent "https://example.com/path/to/download"

...in a script that's a little flexible

    #!/usr/bin/env zsh

    # uses wget to download a website and all links / images / ... 
    # to use locally. inline links are converted

    binWget=$(which wget)

    if [[ $# -eq 0 || $# -gt 2 ]]; then
      echo "Usage:"
      echo "$0 [-d|--directory] URL"
      echo
      echo "-d\t--directory\twill recursively download the given directory, but nothing above it"
      exit 1;
    fi

    if [[ $1 == "-d" || $1 == "--directory" ]]; then
      dirOnly=1
      url=$2
    else
      dirOnly=0
      url=$1
    fi

    if [[ $dirOnly -eq 1 ]]; then
      $binWget --convert-links --page-requisites --recursive --no-parent "$url"
    else
      $binWget --convert-links --page-requisites "$url"
    fi

make a gemini certificate

    #!/usr/bin/env zsh

    basedir="/home/dominique/Documents/synced/personal/gemini/identities/"

    if [ $# -ne 2 ]; then
      echo "Usage $0 label hostname"
      exit 1
    else
      label=$1 
      hostname=$2
    fi

    openssl req -new -subj "/CN=$label" -x509 -newkey ec \
            -pkeyopt ec_paramgen_curve:prime256v1 -days 7300 -nodes \
            -out $basedir$hostname.crt \
            -keyout $basedir$hostname.key

---

see all articles on command-line tools