From b0aa1fe379bb07e590ccbd84c19e018b4218acb9 Mon Sep 17 00:00:00 2001 From: Benawi Adha <43810055+wustho@users.noreply.github.com> Date: Fri, 26 Mar 2021 02:36:25 +0700 Subject: [PATCH] plugins: cleanfilename: fixed to not overwrite existing file (#916) * plugins: cleanfilename: fixed to not overwrite existing file * plugins: cleanfilename: fixed to not overwrite existing file --- plugins/cleanfilename | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/cleanfilename b/plugins/cleanfilename index 924d5d04..b7f2ba06 100755 --- a/plugins/cleanfilename +++ b/plugins/cleanfilename @@ -1,12 +1,11 @@ #!/usr/bin/env sh -# Description: Clean filename (either hovered or selections) +# Description: Clean filename or dirname (either hovered or selections) # to be more shell-friendly. # This script replaces any non A-Za-z0-9._- char # with underscore (_). # -# Although the name is 'cleanfilename', but it should work -# on directories too. +# LIMITATION: Won't work with filename that contains newline # # Dependencies: sed # @@ -51,6 +50,10 @@ fi for i in $targets; do if [ "$i" != "$(cleanup "$i")" ]; then - mv "$i" "$(cleanup "$i")"; + tmp='' + if [ -e "$(cleanup "$i")" ]; then + tmp='_' + fi + mv "$i" "$tmp$(cleanup "$i")"; fi done