Skip to content

seanbreckenridge/seanb-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scripts extracted from my dotfiles, see index

This includes:

  • Pure utility/wrangling scripts like lower, upper, chomp, rcut, tally, unique, average; which help process outputs of other commands, which are commonly used by other shellscripts I put up on other repositories -- hence the reason to make this repo so they're easily installable
  • Some helper/conversion scripts like to-png, to-jpeg, rotate-img, tq (jq for toml)
  • Cross-Platform scripts that provide interaction with clipboard/prompting user for input/sending notifications on Mac/Linux/Termux

Requires

This does not install these and requires you to have these available (on your $PATH) before installing this:

  • GNU coreutils (or some compatible set of utilities) - e.g., cut, uniq, tr
  • util-linux - e.g., shuf, rev, kill
  • find
  • grep
  • curl
  • wget
  • awk
  • sed
  • realpath

Optional/Recommended (some scripts here will fail if these aren't present)

  • jq - command line JSON parser
  • fzf - fuzzy finder
  • fd - user-friendly 'find' alternative

Needed for installing/building core utils used in other scripts here:

Install

To check for dependencies/path issues, run make

To install, run make install:

git clone https://github.com/seanbreckenridge/seanb-utils
cd ./seanb-utils
make  # check for dependencies
make install

Or use bpkg to automate the manual git clone/cd/make:

bpkg install -g seanbreckenridge/seanb-utils

To setup go to build packages, add something like this to your .zshrc/.bashrc:

# if not already set
export XDG_DATA_HOME="${HOME}/.local/share"

# Go (see 'go help install')
export GOPATH="${XDG_DATA_HOME}/go"
export GOBIN="${GOPATH}/bin"

# update $PATH
export PATH="\
${HOME}/.local/bin:\
${XDG_DATA_HOME}/go/bin:\
${PATH}"

On termux, you need to install the termux-api package (from F-Droid)

Contents

Requires python 3.8+/golang to install:

Script Index

make install installs:

  • a few go CLI tools - (See https://go.dev/doc/install for install instructions)
    • newest - print most recently modified file in directory
    • chomp - remove whitespace/empty lines from command output
    • on_machine - detect what operating system/machine you're currently on
  • The ./python-src package, which includes helper functions, see python-src/README.md. Also installs required python libraries for any python scripts here

... and shellscripts:

shellscripts

File/Utility Scripts
File Formats
  • json-compress - compresses JSON (removes extra spaces/newlines), only writes to the file if size of data was changed
  • tq - converts a TOML file to JSON, usually piped to jq. e.g.,: tq <data.toml | jq '.conf'
  • to-png/to-jpg - converts an image to a png/jpg
  • img-download - downloads an image from your clipboard to your tmpdir, moves it so that the extension is valid
  • shebang - creates a script with the given shebang. If a known language, adds a basic template
  • html-head: a script to generate <head> tags for generated HTML, I often use this like: pandoc README.md | html-head -a css-dark-mode -a css-pre-wrap | remsync-html-from-stdin to convert some local markdown file to a basic dark-mode webpage and publish it onto my website with remsync
Data Wrangling
  • lower/upper - converts all text from STDIN to lowercase/uppercase
  • prefix/suffix/surround - prepends/adds a string to the beginning/end of each line from STDIN
  • capitalize - 'capitalizes' (first letter of) input, e.g. WORD -> Word; word -> Word
  • average - finds the mean of numerical data piped from STDIN
  • rcut - cut, by indexing from the right instead
  • sort-by-last-col - sorts text by last column of text; columns can vary in length
  • unique - uniq, but doesn't require input to be sorted
  • unique-ignore-case - unique, but ignores uppercase/lowercase
  • tally - shorthand for 'sort | uniq -c | sort -n'
  • group-and-termgraph - takes lines of data and groups/graphs it using termgraph. Sort of like a fancy 'sort | uniq -c | sort -n'
  • epochdisplay - given one or more epoch timestamps (date +"%s") prints a readable date. If no args are given, reads from STDIN
  • epochguess - reads anything from STDIN. convert any epoch timestamps that looks like a datetime to local-readable timestamps
Cross Platform Helpers

These use on_machine to run different commands based on what operating system you're on

  • openurl/openurls - URL opener
  • clipcopy/clippaste - save to/read from clipboard
  • input-dialog - prompts the user to enter some text with an OS-dialog
  • notify - sends a OS notification (notify-send on linux/applescript on mac)
  • picker - prompts user to pick from lines received from STDIN
Git
Media
  • image-dimensions - prints the width/height for images passed as arguments
  • gifme - Creates a gif from a (section of a) video file. Lets you specify start/end times and an fps for the gif to run at
  • list-movies/list-music - lists any music/movies in the current directory recursively. any additional args are passed onto fd, e.g, with mlength
    • list-music -X mlength -o sum (find length of an album in current directory)
    • list-movies -X mlength -d path -o min (find shortest movie in current directory)
    • list-movies -X mlength -d all | sort -n (sort results by length)
Others:
  • ix - terminal pastebin replacement -- anything piped to STDIN gets uploaded to http://ix.io and a link is copied to your clipboard