From 3443406c575228204bf73a9e578df9458e849f89 Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Sun, 27 Feb 2022 12:01:54 -0500 Subject: [PATCH] bin: Add `bak` to temporarily rename files This is helpful when troubleshooting things like module sourcing, etc. For example, both my last commits needed to test that the nvim and tmux configs worked both with and without local configs. This could be done like so: $ nvim # works $ bak ~/.config/nvim/local.lua # shift aside $ nvim # works $ bak ~/.config/nvim/local.lua # revert --- bin/bak | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 bin/bak diff --git a/bin/bak b/bin/bak new file mode 100755 index 0000000..a43cc09 --- /dev/null +++ b/bin/bak @@ -0,0 +1,22 @@ +#!/bin/sh +# bak -- move a file to file.bak (or back) +set -e +die() { + echo "$*" 1>&2 + exit 1 +} + +[ -z "$1" ] && die "usage: bak FILE" + +BAK="$1.bak" +if [ -e "$BAK" ] && [ -e "$1" ]; then + die "$1 and $BAK exist, unable to bak or unbak" +elif [ -e "$BAK" ]; then + mv "$BAK" "$1" + echo "$BAK -> $1" +elif [ -e "$1" ]; then + mv "$1" "$BAK" + echo "$1 -> $BAK" +else + die "Neither $1 nor $BAK exist, unable to bak or unbak" +fi -- libgit2 1.1.1