dotfiles

config files for my linux setup
git clone git://edryd.org/dotfiles
Log | Files | Refs

commit 9a0854be14bea8bbee056eeafc009d24cc492574
parent bf88b159e64c96344f627288f382ddcd3808a6ce
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Wed, 11 Apr 2018 00:12:26 -0700

bin: Add tg

Diffstat:
bin/tg | 25+++++++++++++++++++++++++
1 file changed, 25 insertions(+), 0 deletions(-)

diff --git a/bin/tg b/bin/tg @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# tg: quickly tag files +# +# Rename files based on the given tag. For example `tg old file.txt` changes +# `file.txt` to `file-old.txt`. If the file already contains the suppied tag, +# it is removed. + +if [[ $# != 2 ]]; then + echo "usage: tg TAG FILE" + exit 1 +fi + +if [ -z "${2##*.*}" ]; then + ext=".${2##*.}" +else + ext="" +fi +file="${2%.*}" + +if [[ $(echo "$file" | rev | cut -d '-' -f 1 | rev) != "$1" ]]; then + mv "$2" "${file}-$1$ext" +else + mv "$2" "$(echo "$file" | rev | cut -d '-' -f 2- | rev)$ext" +fi