config/ranger/rename.sh

   1 #!/bin/bash
   2 
   3 du -h "$@" |
   4 while read size file; do
   5     res=$(identify -format '%wx%h' "$file")
   6     hex=$(
   7         convert "$file" -resize 25% -colors 1 -unique-colors txt:- |
   8         tail -n 1 | cut -d ' ' -f 4 | cut -b 2-7
   9     )
  10     col=$(
  11         w3m -dump -cols 100 https://encycolorpedia.com/$hex |
  12         grep -io "$hex is a [^.]*" | sed 's/\w*/\u&/g' | awk '{ print $NF }'
  13     )
  14     new="$col-${res:-0x0}-${size}.${file##*.}"
  15 
  16     echo "'$file' -> '${new/ () / }'"
  17     mv -n "$file" "${new/ () / }"
  18 done