From 865728068c965e066d0f8971c5b5ba26e12e7dce Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Thu, 24 Dec 2020 00:06:27 +0530 Subject: Adds scripts and links scripts and wallpapers --- scripts/bin/vimv | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 scripts/bin/vimv (limited to 'scripts/bin/vimv') diff --git a/scripts/bin/vimv b/scripts/bin/vimv new file mode 100755 index 0000000..3c78afb --- /dev/null +++ b/scripts/bin/vimv @@ -0,0 +1,38 @@ +#!/bin/bash + +# 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 + +declare -r FILENAMES_FILE="$(mktemp --tmpdir vimv.XXX)" + +trap '{ rm -f "${FILENAMES_FILE}" ; }' EXIT + +if [ $# -ne 0 ]; then + src=( "$@" ) +else + IFS=$'\r\n' GLOBIGNORE='*' command eval 'src=($(ls))' +fi + +for ((i=0;i<${#src[@]};++i)); do + echo "${src[i]}" >> "${FILENAMES_FILE}" +done + +${EDITOR:-vi} "${FILENAMES_FILE}" + +IFS=$'\r\n' GLOBIGNORE='*' command eval 'dest=($(cat "${FILENAMES_FILE}"))' + +count=0 +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 + ((count++)) + fi +done + +echo "$count" files renamed. -- cgit v1.3.1