unixorn/tumult.plugin.zsh

View on GitHub
bin/pbindent

Summary

Maintainability
Test Coverage
#!/bin/bash
#
# Source: https://github.com/rtomayko/dotfiles
#
# Usage: pbindent [-o]
# Indent pboard text four spaces and update pboard with result. With -o,
# write result to standard output instead of to the pboard.

set -o pipefail

if [[ "$(uname -s)" != 'Darwin' ]]; then
  echo 'Sorry, this script only works on macOS'
  exit 1
fi

writer='pbcopy'
# shellcheck disable=SC2086
while test $# -gt 0
do
    case "$1" in
    -o)     writer='cat'
            shift;;
    --help) grep '^# ' "$0" | cut -c3-
            exit 0;;
    *)      echo "$(basename $0): invalid argument: '$1'"
            exit 1;;
    esac
done

pbpaste | sed 's/^/    /' | $writer
exit $?