aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore30
-rwxr-xr-x.local/bin/chomp8
-rwxr-xr-x.local/bin/chwp30
-rwxr-xr-x.local/bin/kubecontext27
-rwxr-xr-x.local/bin/mkbak4
-rwxr-xr-x.local/bin/mkpasswd10
-rwxr-xr-x.local/bin/ta13
-rwxr-xr-x.local/bin/uncolor20
-rwxr-xr-x.local/bin/up12
9 files changed, 147 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index 6f5aa19..25d8824 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,6 +20,29 @@
/.config/shell/vendor
#
+# Custom shell utilities
+#
+
+!/.local/bin
+/.local/bin/*
+
+# gittab
+!/.local/bin/gittab
+!/.local/etc
+/.local/etc/*
+!/.local/etc/gittab
+
+# misc
+!/.local/bin/chomp
+!/.local/bin/chwp
+!/.local/bin/kubecontext
+!/.local/bin/mkbak
+!/.local/bin/mkpasswd
+!/.local/bin/ta
+!/.local/bin/uncolor
+!/.local/bin/up
+
+#
# Application specific dotfiles
#
@@ -44,10 +67,3 @@
# x11-wm/awesome
!/.config/awesome/
/.config/awesome/calendar
-
-!/.local/bin
-/.local/bin/*
-!/.local/bin/gittab
-!/.local/etc
-/.local/etc/*
-!/.local/etc/gittab
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=$(</proc/uptime)
+uptime=${uptime%%.*}
+
+seconds=$(( uptime%60 ))
+minutes=$(( uptime/60%60 ))
+hours=$(( uptime/60/60%24 ))
+days=$(( uptime/60/60/24 ))
+
+echo "${days}d ${hours}h ${minutes}m ${seconds}s"
+