music-scripts: 1117e514c939ee510d77c6b8c30c4cb0e5a7f519

     1: #!/usr/bin/env bash
     2: 
     3: # Look for dodgy whitespace in filenames, which is either ugly or may lead
     4: # to dupes. Includes 'double  spaces', ' initial spaces' and
     5: # 'spaces before .extensions'
     6: 
     7: if [[ "$#" -eq 0 ]]
     8: then
     9:     DIR="Music"
    10: else
    11:     DIR="$1"
    12: fi
    13: 
    14: while read -r NAME
    15: do
    16:     DIR=$(dirname "$NAME")
    17:     FILE=$(basename "$NAME")
    18: 
    19:     # shellcheck disable=SC2001
    20:     NORMAL=$(echo "$FILE" | sed -e 's/   */ /g')
    21: 
    22:     SRC="$DIR/$FILE"
    23:     DST="$DIR/$NORMAL"
    24:     if [[ -e "$DST" ]]
    25:     then
    26:         echo "'$SRC' has dodgy whitespace, but '$DST' exists"
    27:     else
    28:         move_command "$SRC" "$DST"
    29:     fi
    30: done < <(find "$DIR" -name '*  *')
    31: while read -r NAME
    32: do
    33:     DIR=$(dirname "$NAME")
    34:     FILE=$(basename "$NAME")
    35: 
    36:     # shellcheck disable=SC2001
    37:     NORMAL=$(echo "$FILE" | sed -e 's/^  *//g')
    38: 
    39:     SRC="$DIR/$FILE"
    40:     DST="$DIR/$NORMAL"
    41:     if [[ -e "$DIR/$NORMAL" ]]
    42:     then
    43:         echo "'$SRC' has dodgy whitespace, but '$DST' exists"
    44:     else
    45:         move_command "$SRC" "$DST"
    46:     fi
    47: done < <(find "$DIR" -name ' *')
    48: while read -r NAME
    49: do
    50:     DIR=$(dirname "$NAME")
    51:     FILE=$(basename "$NAME")
    52: 
    53:     # shellcheck disable=SC2001
    54:     NORMAL=$(echo "$FILE" | sed -e 's/  *\.\([^\.]*\)$/\.\1/g')
    55: 
    56:     SRC="$DIR/$FILE"
    57:     DST="$DIR/$NORMAL"
    58:     [[ "$FILE" = "$NORMAL" ]] && continue
    59:     if [[ -e "$DST" ]]
    60:     then
    61:         echo "'$SRC' has dodgy whitespace, but '$DST' exists"
    62:     else
    63:         move_command "$SRC" "$DST"
    64:     fi
    65: done < <(find "$DIR" -name '* .*')

Generated by git2html.