2022-10-05 04:45:20 +00:00
|
|
|
#!/bin/bash
|
2021-02-11 16:25:39 +00:00
|
|
|
|
|
|
|
# Lists the current directory's files in Vim, so you can edit it and save to rename them
|
|
|
|
# USAGE: vimv [file1 file2]
|
|
|
|
# https://github.com/thameera/vimv
|
|
|
|
|
2022-10-05 04:45:20 +00:00
|
|
|
declare -r FILENAMES_FILE="$(mktemp --tmpdir vimv.XXX)"
|
2021-02-11 16:25:39 +00:00
|
|
|
|
|
|
|
trap '{ rm -f "${FILENAMES_FILE}" ; }' EXIT
|
|
|
|
|
|
|
|
if [ $# -ne 0 ]; then
|
|
|
|
src=( "$@" )
|
|
|
|
else
|
2022-10-05 04:45:20 +00:00
|
|
|
IFS=$'\r\n' GLOBIGNORE='*' command eval 'src=($(ls))'
|
2021-02-11 16:25:39 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
for ((i=0;i<${#src[@]};++i)); do
|
|
|
|
echo "${src[i]}" >> "${FILENAMES_FILE}"
|
|
|
|
done
|
|
|
|
|
|
|
|
${EDITOR:-vi} "${FILENAMES_FILE}"
|
|
|
|
|
2022-10-05 04:45:20 +00:00
|
|
|
IFS=$'\r\n' GLOBIGNORE='*' command eval 'dest=($(cat "${FILENAMES_FILE}"))'
|
2021-02-11 16:25:39 +00:00
|
|
|
|
2022-10-05 04:45:20 +00:00
|
|
|
count=0
|
2021-02-11 16:25:39 +00:00
|
|
|
for ((i=0;i<${#src[@]};++i)); do
|
|
|
|
if [ "${src[i]}" != "${dest[i]}" ]; then
|
|
|
|
mkdir -p "`dirname "${dest[i]}"`"
|
|
|
|
if git ls-files --error-unmatch "${src[i]}" > /dev/null 2>&1; then
|
|
|
|
git mv "${src[i]}" "${dest[i]}"
|
|
|
|
else
|
|
|
|
mv "${src[i]}" "${dest[i]}"
|
|
|
|
fi
|
2022-10-05 04:45:20 +00:00
|
|
|
((count++))
|
2021-02-11 16:25:39 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "$count" files renamed.
|