~duncan-bayne/setups

b6ce195c0f4cb3f47a9488fdf28066820cad4fe0 — Duncan Bayne 2 days ago 1f4cc12 master
Fix whitespace
M utility-scripts/utils/,cc => utility-scripts/utils/,cc +5 -5
@@ 4,11 4,11 @@ set -euo pipefail
shellcheck "$0"

if [ "$#" -ne 0 ] || [ "${1-}" = "--help" ]; then
    {
	echo "Usage: ,cc"
	echo "Shortcut for X clipboard copy"
    } 1>&2
    exit 1;
  {
    echo "Usage: ,cc"
    echo "Shortcut for X clipboard copy"
  } 1>&2
  exit 1;
fi

xclip -selection c

M utility-scripts/utils/,ec => utility-scripts/utils/,ec +7 -7
@@ 4,13 4,13 @@ set -euo pipefail
shellcheck "$0"

if [ "$#" -gt 0 ] || [ "${1-}" = "--help" ]; then
    {
	echo "Usage: ,ec"
	echo
	echo "Runs 'git status' to determine all modified or untracked files in the"
	echo "current repo, then opens each with emacsclient in the background."
    } 1>&2
    exit 1;
  {
    echo "Usage: ,ec"
    echo
    echo "Runs 'git status' to determine all modified or untracked files in the"
    echo "current repo, then opens each with emacsclient in the background."
  } 1>&2
  exit 1;
fi

git status --porcelain | grep -v '^ D' | sed 's/^...//g' | cut -d' ' -f1 | xargs emacsclient &

M utility-scripts/utils/,fc => utility-scripts/utils/,fc +6 -7
@@ 4,13 4,12 @@ set -euo pipefail
shellcheck "$0"

if [ "$#" -ne 1 ] || [ "${1-}" = "--help" ]; then
    {
	echo "Usage: ,fc DIR"
	echo "Prints a list of all immediate subdirectories of DIR, and for each"
	echo "subdirectory, the recursive count of files in that subdirectory."
    } 1>&2
    exit 1;
  {
    echo "Usage: ,fc DIR"
    echo "Prints a list of all immediate subdirectories of DIR, and for each"
    echo "subdirectory, the recursive count of files in that subdirectory."
  } 1>&2
  exit 1;
fi

find "$1" -maxdepth 1 -type d | sort | while read -r dir; do n=$(find "$dir" -type f | wc -l); printf "%4d : %s\n" "$n" "$dir"; done


M utility-scripts/utils/,fw => utility-scripts/utils/,fw +6 -6
@@ 4,16 4,16 @@ set -euo pipefail
shellcheck "$0"

if [ "$#" -ne 0 ] || [ "${1-}" = "--help" ]; then
    {
	echo "Usage: ,fw"
	echo "Fetches and pulls every branch of the current Git repository."
    } 1>&2
    exit 1;
  {
    echo "Usage: ,fw"
    echo "Fetches and pulls every branch of the current Git repository."
  } 1>&2
  exit 1;
fi

git branch -r | grep -v '\->' | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | while read -r remote
do
    git branch --track "${remote#origin/}" "$remote" || echo "Already tracking $remote"
  git branch --track "${remote#origin/}" "$remote" || echo "Already tracking $remote"
done

git fetch --all

M utility-scripts/utils/,go => utility-scripts/utils/,go +16 -18
@@ 4,29 4,27 @@ set -euo pipefail
shellcheck "$0"

if [ "$#" -lt 1 ] || [ "${1-}" = "--help" ]; then
    {
  echo "Usage: ,go [ISSUENUM, ...]"
  echo
  echo "Opens the specified issue(s) for this repo in a browser."
  echo
  echo "If one ISSUENUM is passed, it opens just that one. If more than one"
  echo "ISSUENUM is passed, it opens them all."
  echo
  echo
  echo "Assumes the cwd is within the Git repo of interest."
    } 1>&2
    exit 1;
  {
    echo "Usage: ,go [ISSUENUM, ...]"
    echo
    echo "Opens the specified issue(s) for this repo in a browser."
    echo
    echo "If one ISSUENUM is passed, it opens just that one. If more than one"
    echo "ISSUENUM is passed, it opens them all."
    echo
    echo
    echo "Assumes the cwd is within the Git repo of interest."
  } 1>&2
  exit 1;
fi

url_for() {
    ISSUENUM=$1
    JSON=$(gh issue view "$ISSUENUM" --json "url")
    URL=$(echo "$JSON" | jq .url | sed 's/"//g')
    echo -n "$URL"
  ISSUENUM=$1
  JSON=$(gh issue view "$ISSUENUM" --json "url")
  URL=$(echo "$JSON" | jq .url | sed 's/"//g')
  echo -n "$URL"
}

for issue_num in "$@"; do
  xdg-open "$(url_for $issue_num)" &
done



M utility-scripts/utils/,rs => utility-scripts/utils/,rs +7 -7
@@ 4,13 4,13 @@ set -euo pipefail
shellcheck "$0"

if [ "$#" -gt 0 ] || [ "${1-}" = "--help" ]; then
    {
	echo "Usage: ,rs"
	echo
	echo "Runs 'git status' to determine all modified specs in the current repo,"
	echo "then runs them with bin/rspec."
    } 1>&2
    exit 1;
  {
    echo "Usage: ,rs"
    echo
    echo "Runs 'git status' to determine all modified specs in the current repo,"
    echo "then runs them with bin/rspec."
  } 1>&2
  exit 1;
fi

git status --porcelain | grep '^ M spec/' | cut -d" " -f3 | xargs bin/rspec

M utility-scripts/utils/,rsb => utility-scripts/utils/,rsb +7 -7
@@ 4,13 4,13 @@ set -euo pipefail
shellcheck "$0"

if [ "$#" -ne 1 ] || [ "${1-}" = "--help" ]; then
    {
	echo "Usage: ,rsb BRANCH"
	echo
	echo "Runs 'git diff' to determine all modified or added specs in the"
	echo "current branch (relative to BRANCH), then runs them with bin/rspec."
    } 1>&2
    exit 1;
  {
    echo "Usage: ,rsb BRANCH"
    echo
    echo "Runs 'git diff' to determine all modified or added specs in the"
    echo "current branch (relative to BRANCH), then runs them with bin/rspec."
  } 1>&2
  exit 1;
fi

git diff --diff-filter=MA --name-only "$1"... | grep "_spec.rb" | xargs rspec --format documentation

M utility-scripts/utils/,sc => utility-scripts/utils/,sc +5 -5
@@ 4,11 4,11 @@ set -euo pipefail
shellcheck "$0"

if [ "$#" -ne 0 ] || [ "${1-}" = "--help" ]; then
    {
	echo "Usage: ,sc"
	echo "Swap Caps Lock for a Control key."
    } 1>&2
    exit 1;
  {
    echo "Usage: ,sc"
    echo "Swap Caps Lock for a Control key."
  } 1>&2
  exit 1;
fi

setxkbmap -option "ctrl:nocaps"

M utility-scripts/utils/,ss => utility-scripts/utils/,ss +11 -11
@@ 4,19 4,19 @@ set -euo pipefail
shellcheck "$0"

if [ "$#" -lt 1 ] || [ "$#" -gt 3 ] || [ "${1-}" = "--help" ]; then
    {
	echo "Usage: ,ss FILENAME [SECONDS] [RESIZE]"
	echo
	echo "Prompts the user to select an area for a screenshot, which is saved to"
	echo "\$HOME/FILENAME.png.  If SECONDS is supplied, sleeps for SECONDS first."
	echo "If RESIZE is supplied, resize the image to RESIZE% of the original"
	echo "size."
    } 1>&2
    exit 1;
  {
    echo "Usage: ,ss FILENAME [SECONDS] [RESIZE]"
    echo
    echo "Prompts the user to select an area for a screenshot, which is saved to"
    echo "\$HOME/FILENAME.png.  If SECONDS is supplied, sleeps for SECONDS first."
    echo "If RESIZE is supplied, resize the image to RESIZE% of the original"
    echo "size."
  } 1>&2
  exit 1;
fi

if [[ -n "${2-}" ]]; then
   sleep "$2"
  sleep "$2"
fi

filename="$HOME/tmp/$1.png"


@@ 24,5 24,5 @@ filename="$HOME/tmp/$1.png"
import "$filename"

if [[ -n "${3-}" ]]; then
    convert "$filename" -resize "$3%" "$filename"
  convert "$filename" -resize "$3%" "$filename"
fi

M utility-scripts/utils/,st => utility-scripts/utils/,st +7 -8
@@ 4,13 4,13 @@ set -euo pipefail
shellcheck "$0"

if [ "$#" -ne 3  ] || [ "${1-}" = "--help" ]; then
    {
	echo "Usage: ,st REMOTEPORT LOCALPORT HOSTNAME"
	echo
	echo "Establishes an SSH tunnel to HOSTNAME, from local port LOCALPORT to"
	echo "remote port REMOTEPORT."
    } 1>&2
    exit 1;
  {
    echo "Usage: ,st REMOTEPORT LOCALPORT HOSTNAME"
    echo
    echo "Establishes an SSH tunnel to HOSTNAME, from local port LOCALPORT to"
    echo "remote port REMOTEPORT."
  } 1>&2
  exit 1;
fi

LOCALPORT="$1"


@@ 18,4 18,3 @@ REMOTEPORT="$2"
HOSTNAME="$3"

ssh -N -L "$REMOTEPORT":localhost:"$LOCALPORT" "$HOSTNAME"


M utility-scripts/utils/,tm => utility-scripts/utils/,tm +5 -5
@@ 4,11 4,11 @@ set -euo pipefail
shellcheck "$0"

if [ "$#" -ne 0 ] || [ "${1-}" = "--help" ]; then
    {
	echo "Usage: ,tm"
	echo "Attaches to a tmux session if one exists, or creates one otherwise."
    } 1>&2
    exit 1;
  {
    echo "Usage: ,tm"
    echo "Attaches to a tmux session if one exists, or creates one otherwise."
  } 1>&2
  exit 1;
fi

tmux attach || tmux

M utility-scripts/utils/,vn => utility-scripts/utils/,vn +7 -7
@@ 4,13 4,13 @@ set -euo pipefail
shellcheck "$0"

if [ "$#" -ne 0 ] || [ "${1-}" = "--help" ]; then
    {
	echo "Usage: ,vn"
	echo "Kills any VNC server on display :1, then starts a new 1920x1080 VNC"
	echo "server on display :1."
    } 1>&2
    exit 1;
  {
    echo "Usage: ,vn"
    echo "Kills any VNC server on display :1, then starts a new 1920x1080 VNC"
    echo "server on display :1."
  } 1>&2
  exit 1;
fi

vncserver -kill :1 || echo "No running server"
vncserver -geometry 2560x1440 :1
vncserver -geometry 1200x800 :1

M utility-scripts/utils/,wc => utility-scripts/utils/,wc +7 -7
@@ 4,14 4,14 @@ set -euo pipefail
shellcheck "$0"

if [ "$#" -ne 0 ] || [ "${1-}" = "--help" ]; then
    {
  echo "Usage: ,wc"
  echo "Sets up my desk-mounted Logitech C920."
    } 1>&2
    exit 1;
  {
    echo "Usage: ,wc"
    echo "Sets up my desk-mounted Logitech C920."
  } 1>&2
  exit 1;
fi

v4l2-ctl -d /dev/video0 -c zoom_absolute=125
v4l2-ctl -d /dev/video0 -c zoom_absolute=180
v4l2-ctl -d /dev/video0 -c brightness=120
v4l2-ctl -d /dev/video0 -c focus_automatic_continuous=0
v4l2-ctl -d /dev/video0 -c focus_absolute=30
v4l2-ctl -d /dev/video0 -c brightness=225

M utility-scripts/utils/,ws => utility-scripts/utils/,ws +7 -8
@@ 5,17 5,16 @@ shellcheck "$0"

if [ "$#" -gt 2 ] || [ "${1-}" = "--help" ]
then
    {
	echo "Usage: ,ws [HOST] [PORT]"
	echo
	echo "Serve the current directory as a Web server on PORT and HOST.  PORT "
	echo "defaults to 8080, HOST to 0.0.0.0."
    } 1>&2
    exit 1;
  {
    echo "Usage: ,ws [HOST] [PORT]"
    echo
    echo "Serve the current directory as a Web server on PORT and HOST.  PORT "
    echo "defaults to 8080, HOST to 0.0.0.0."
  } 1>&2
  exit 1;
fi

HOST=${1:-0.0.0.0}
PORT=${2:-8080}

python3 -m http.server --bind "$HOST" "$PORT"