|
@@ -1,15 +1,21 @@
|
|
|
-#!/bin/sh
|
|
|
+#!/usr/bin/env bash
|
|
|
+set -euo pipefail
|
|
|
+IFS=$'\n\t'
|
|
|
|
|
|
if [ $# -lt 1 ] ; then
|
|
|
- echo "Usage: $0 PDF-NAME"
|
|
|
+ echo "Usage: $(basename $0) PDF-NAME+"
|
|
|
exit 1
|
|
|
fi
|
|
|
|
|
|
-OLD_NAME=$1
|
|
|
-FILE_SLUG=$(pdfinfo $OLD_NAME | grep Title | cut -d: -f 2 | sed 's/ *$//g' | sed 's/^ *//g' | tr 'A-Z' 'a-z' | tr ' ' '-')
|
|
|
+while (( "$#" )) ; do
|
|
|
+ OLD_NAME="${1}"
|
|
|
+ FILE_SLUG=$(pdfinfo $OLD_NAME | grep Title | cut -d: -f 2 | sed 's/ *$//g' | sed 's/^ *//g' | tr 'A-Z' 'a-z' | tr ' ' '-')
|
|
|
|
|
|
-if [ ! -z $FILE_SLUG ] ; then
|
|
|
- mv $OLD_NAME ${FILE_SLUG}.pdf
|
|
|
-else
|
|
|
- echo Cannot detect title
|
|
|
-fi
|
|
|
+ if [ ! -z $FILE_SLUG ] ; then
|
|
|
+ mv "$OLD_NAME" "${FILE_SLUG}.pdf"
|
|
|
+ else
|
|
|
+ echo "Cannot detect title in ${OLD_NAME}"
|
|
|
+ fi
|
|
|
+
|
|
|
+ shift
|
|
|
+done
|