Skip to content

Instantly share code, notes, and snippets.

@ahti
Created May 25, 2014 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahti/f5415e491bee270a22f4 to your computer and use it in GitHub Desktop.
Save ahti/f5415e491bee270a22f4 to your computer and use it in GitHub Desktop.
sedmv
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