dotfiles

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

tg (530B)


      1 #!/usr/bin/env bash
      2 
      3 # tg: quickly tag files
      4 #
      5 # Rename files based on the given tag. For example `tg old file.txt` changes
      6 # `file.txt` to `file-old.txt`. If the file already contains the suppied tag,
      7 # it is removed.
      8 
      9 if [[ $# != 2 ]]; then
     10   echo "usage: tg TAG FILE"
     11   exit 1
     12 fi
     13 
     14 if [ -z "${2##*.*}" ]; then
     15   ext=".${2##*.}"
     16 else
     17   ext=""
     18 fi
     19 file="${2%.*}"
     20 
     21 if [[ $(echo "$file" | rev | cut -d '-' -f 1 | rev) != "$1" ]]; then
     22   mv "$2" "${file}-$1$ext"
     23 else
     24   mv "$2" "$(echo "$file" | rev | cut -d '-' -f 2- | rev)$ext"
     25 fi