mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
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
This commit is contained in:
parent
f602cbee07
commit
b0aa1fe379
|
@ -1,12 +1,11 @@
|
||||||
#!/usr/bin/env sh
|
#!/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.
|
# to be more shell-friendly.
|
||||||
# This script replaces any non A-Za-z0-9._- char
|
# This script replaces any non A-Za-z0-9._- char
|
||||||
# with underscore (_).
|
# with underscore (_).
|
||||||
#
|
#
|
||||||
# Although the name is 'cleanfilename', but it should work
|
# LIMITATION: Won't work with filename that contains newline
|
||||||
# on directories too.
|
|
||||||
#
|
#
|
||||||
# Dependencies: sed
|
# Dependencies: sed
|
||||||
#
|
#
|
||||||
|
@ -51,6 +50,10 @@ fi
|
||||||
|
|
||||||
for i in $targets; do
|
for i in $targets; do
|
||||||
if [ "$i" != "$(cleanup "$i")" ]; then
|
if [ "$i" != "$(cleanup "$i")" ]; then
|
||||||
mv "$i" "$(cleanup "$i")";
|
tmp=''
|
||||||
|
if [ -e "$(cleanup "$i")" ]; then
|
||||||
|
tmp='_'
|
||||||
|
fi
|
||||||
|
mv "$i" "$tmp$(cleanup "$i")";
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue