qmv (1247B)
1 #!/bin/sh 2 # 3 # qmv 4 # Created by Hayden Hamilton 5 # 6 # hayden@haydenvh.com 7 # Copyright (c) 2020 Hayden Hamilton 8 9 [ "$(echo "$1" | grep "help")" != "" ] && printf " 10 qmv [mode] [modeinfo] [files] 11 12 $(tput bold)MODES & MODEINFO$(tput sgr0) 13 number [start number].[file extension] 14 0number [0-padded start number].[file extension]\n" && exit 15 16 mode="$1" 17 modeinfo="$2" 18 all=$(echo "$@" | sed "s/^[[:space:]]*$mode//;s/^[[:space:]]*$modeinfo//") 19 20 _number(){ 21 number=$(echo "$@" | grep -o "^[0-9]*") 22 fileext=$(echo "$@" | grep -o "\.[A-Za-z0-9]*" | sed 's/^\.//g') 23 24 for file in $all 25 do 26 [ "$fileext" = "" ] && { 27 mv $file $number 28 } || { 29 mv $file $number.$fileext 30 }; number=$(($number+1)) 31 done 32 } 33 34 _number0(){ 35 number=$(echo "$@" | grep -o "^[0-9]*") 36 fileext=$(echo "$@" | grep -o "\.[A-Za-z0-9]*" | sed 's/^\.//g') 37 pad=$(echo "$number" | grep -o "^0*") 38 padc=$(echo "$pad" | wc -m) 39 40 for file in $all 41 do 42 [ "$fileext" = "" ] && { 43 mv $file $(printf "0${padc}d" "$number") 44 } || { 45 mv $file $(printf "0${padc}d" "$number").$fileext 46 }; number=$(($number+1)) 47 done 48 } 49 50 case "$mode" in 51 number|numbered|num|n) _number "$modeinfo" ;; 52 0number|number0|0num|num0) _number0 "$modeinfo" ;; 53 *) echo "$mode: not a supported mode."; exit ;; 54 esac