From 6c078fab23e00a6388fda9cb05761228ddec173f Mon Sep 17 00:00:00 2001 From: Maxim Likhachev Date: Wed, 13 Nov 2019 22:06:35 +0300 Subject: [PATCH] renamepdfs: PDF rename script --- README.md | 1 + renamepdfs | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 renamepdfs diff --git a/README.md b/README.md index ce1b174..cff6059 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ will create the symbolic link for each script in the \ directory. - [fontsel](fontsel) shows the available console fonts. - [fsz](fsz) adjusts console font size. - [hr](hr) displays horizontal rule with current time. +- [renamepdfs](renamepdfs) renames PDF files using their metadata. - [vcat](vcat) displays file content with [syntax highlighting](https://www.gnu.org/software/src-highlite/) (see also [bat](https://github.com/sharkdp/bat)). - [viper](viper) is a simple alternative to viper from [moreutils](https://joeyh.name/code/moreutils/) package which can be used with custom vim parameters. diff --git a/renamepdfs b/renamepdfs new file mode 100755 index 0000000..8c6f4ae --- /dev/null +++ b/renamepdfs @@ -0,0 +1,39 @@ +#!/bin/bash + +# Интерактивное переименование PDF-файлов, используя информацию из метаданных + +filelist() { + for f in "$@"; do + echo "\"$f\"" + done +} + +DIR=$(pwd) + +FILES=() + +while [[ $# -gt 0 ]]; do + key="$1" + + case $key in + -d|--directory) + DIR="$2" + shift # past argument + shift # past value + ;; + *) + FILES+=("$1") # save it in an array for later + shift # past argument + ;; + esac +done + +set -- "${FILES[@]}" + +if [ "${#FILES[@]}" -gt 0 ]; then + filelist "${FILES[@]}" | viper +'set ft=rename' +"let b:rename_dir=\"$DIR\"" | sed "s/^/mv /" | sh +else + echo "USAGE: $(basename $0) [-d/--directory ] file1.pdf file2.pdf [...]" + exit 1 +fi +