From 035bb70ce47ce7e5a643b80e130985b6d711e99f Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Wed, 2 Oct 2019 16:41:02 +0200 Subject: Add a number of shell utilities --- .local/bin/chomp | 8 ++++++++ .local/bin/chwp | 30 ++++++++++++++++++++++++++++++ .local/bin/kubecontext | 27 +++++++++++++++++++++++++++ .local/bin/mkbak | 4 ++++ .local/bin/mkpasswd | 10 ++++++++++ .local/bin/ta | 13 +++++++++++++ .local/bin/uncolor | 20 ++++++++++++++++++++ .local/bin/up | 12 ++++++++++++ 8 files changed, 124 insertions(+) create mode 100755 .local/bin/chomp create mode 100755 .local/bin/chwp create mode 100755 .local/bin/kubecontext create mode 100755 .local/bin/mkbak create mode 100755 .local/bin/mkpasswd create mode 100755 .local/bin/ta create mode 100755 .local/bin/uncolor create mode 100755 .local/bin/up (limited to '.local/bin') diff --git a/.local/bin/chomp b/.local/bin/chomp new file mode 100755 index 0000000..faeb0c3 --- /dev/null +++ b/.local/bin/chomp @@ -0,0 +1,8 @@ +#! /usr/bin/env sh + +main() +{ + awk '{$1=$1};1' < /dev/stdin +} + +main "$@" diff --git a/.local/bin/chwp b/.local/bin/chwp new file mode 100755 index 0000000..071bf3a --- /dev/null +++ b/.local/bin/chwp @@ -0,0 +1,30 @@ +#! /usr/bin/env sh + +if [ -f "$HOME/.local/etc/x/chwp" ] +then + . "$HOME/.local/etc/x/chwp" +fi + +directory=${CHWP_BASEDIR:-$HOME/pictures/wallpapers} +size=${CHWP_SIZE:-1920x1080} +timeout=${1:-0} +walldir=$directory/$size + +if [ ! -d "$walldir" ] +then + printf "%s\n" "No such directory: $walldir" >&2 +fi + +# If no timeout was set, just change it once +if [ "$timeout" -eq 0 ] +then + find "${walldir}" -type f -print0 | shuf -n1 -z | xargs -0 feh --bg-fill + exit 0 +fi + +# Otherwise, change it every so often +while : +do + find "${walldir}" -type f -print0 | shuf -n1 -z | xargs -0 feh --bg-fill + sleep "${timeout}" +done diff --git a/.local/bin/kubecontext b/.local/bin/kubecontext new file mode 100755 index 0000000..ac99869 --- /dev/null +++ b/.local/bin/kubecontext @@ -0,0 +1,27 @@ +#! /usr/bin/env perl6 + +#| Show all available contexts. +multi sub MAIN () +{ + run << kubectl config get-contexts >>; +} + +#| Switch to a given context. +multi sub MAIN ( + #| The name of the context to switch to. + Str:D $context, +) { + run << kubectl config use-context "$context" >>; +} + +#| Switch to a given namespace in a given context. +multi sub MAIN ( + #| The name of the context to switch to. + Str:D $context, + + #| The name of the namespace to switch to. + Str:D $namespace, +) { + samewith($context); + run << kubectl config set-context --current "--namespace=$namespace" >>; +} diff --git a/.local/bin/mkbak b/.local/bin/mkbak new file mode 100755 index 0000000..07a5d47 --- /dev/null +++ b/.local/bin/mkbak @@ -0,0 +1,4 @@ +#!/usr/bin/env sh + +cp -r "${1}" "${1}.bak-$(date +%Y%m%d%H%M%S)" + diff --git a/.local/bin/mkpasswd b/.local/bin/mkpasswd new file mode 100755 index 0000000..e354803 --- /dev/null +++ b/.local/bin/mkpasswd @@ -0,0 +1,10 @@ +#!/usr/bin/env sh + +length=60 + +if [ -n "$1" ]; then + length=$1 +fi + +cat /dev/urandom | tr -d -c "[:alnum:]" | fold -w${length} | head -1 + diff --git a/.local/bin/ta b/.local/bin/ta new file mode 100755 index 0000000..3d364fa --- /dev/null +++ b/.local/bin/ta @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +t="tmux -2 -f ${HOME}/.config/tmux/conf -u" + +if [ -z "$1" ] +then + session=$(hostname -s) +else + session=$(hostname -s)/$1 +fi + +${t} attach -t "${session}" || ${t} new-session -s "${session}" + diff --git a/.local/bin/uncolor b/.local/bin/uncolor new file mode 100755 index 0000000..68868b2 --- /dev/null +++ b/.local/bin/uncolor @@ -0,0 +1,20 @@ +#! /usr/bin/env sh + +readonly EXPRESSION='s/\x1b\[[0-9;]*m//g' + +main() +{ + if [ "${1:--}" = "-" ] + then + while read line + do + printf "%s\n" "$line" | sed "$EXPRESSION" + done < /dev/stdin + + return 0 + fi + + sed "$EXPRESSION" "$1" +} + +main "$@" diff --git a/.local/bin/up b/.local/bin/up new file mode 100755 index 0000000..f771781 --- /dev/null +++ b/.local/bin/up @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +uptime=$(