~mdkcore/dotbins

dotbins/renamer -rwxr-xr-x 1.7 KiB
2559c86bRodrigo Oliveira [power] Use loginctl instead of pm-* 1 year, 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
################################################################
# This script was created by: MDK - mdk@thecoreme.org          #
# http://projects.thecoreme.org/                               #
# Feb 21 2013                                                  #
# Last update on Nov 06 2015                                   #
#                                                              #
# Simple script to replace white space on files name           #
################################################################

function print_usage(){
    echo "Usage: renamer [options]"
    echo "Where options can be:"
    echo "-l | --lower  Rename changing all characters to lower case"
    echo "-u | --upper  Rename changing all characters to upper case"
    echo "-h | --help   This screen :)"
    echo
}

lower=0
upper=0

while [ $# -gt 0  ]
do
    case $1 in
        -l | --lower)
            lower=1
            shift 1
            ;;
        -u | --upper)
            upper=1
            shift 1
            ;;
        -h | --help)
            print_usage
            shift 1
            exit 0
            ;;
        *)
            echo "Invalid argument $1"
            print_usage
            shift 1
            exit 1
            ;;
    esac
done

for each in *
do
    # substitute a white space for '_'
    # substitute '(' for '--'
    # remove ')'
    new=$(echo $each | sed s/" "/"."/g | sed s/"("/""/g | sed s/")"/""/g)

    if [ $lower = 1 ]
    then
        new_name=$(echo $new | tr "[:upper:]" "[:lower:]")
    elif [ $upper = 1 ]
    then
        new_name=$(echo $new | tr "[:lower:]" "[:upper:]")
    else
        new_name=$new
    fi

    mv -n -T "$each" $new_name &> /dev/null
done

echo "Renaming done, your result:"
ls --color