Created
May 25, 2014 17:07
-
-
Save ahti/f5415e491bee270a22f4 to your computer and use it in GitHub Desktop.
sedmv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sedmv | |
set ls_flags "-1" | |
set perform_changes yes | |
# the last arg is the pattern. save it, remove it, process flags | |
set pattern $argv[-1] | |
set -e argv[-1] | |
if test $pattern = "" | |
set_color red | |
echo "Pattern must not be empty!" | |
return 127 | |
end | |
if begin | |
contains -- -a $argv | |
or contains -- --all-files $argv | |
end | |
set ls_flags {$ls_flags}A | |
end | |
if begin | |
contains -- -n $argv | |
or contains -- --noop $argv | |
end | |
set perform_changes no | |
end | |
for f in (ls $ls_flags) | |
set mvto (echo $f | gsed -r $pattern) | |
if test "$mvto" = "$f" | |
set_color red | |
printf "[✗] " | |
set_color normal | |
echo $f | |
else | |
set_color green | |
printf "[✓] " | |
set_color normal | |
echo $f | |
set_color green | |
printf " -> " | |
set_color normal | |
echo $mvto | |
if test "$perform_changes" = yes | |
mv $f $mvto | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment