Skip to content

Commit

Permalink
version 0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardpaulus committed May 7, 2012
0 parents commit e6da851
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
23 changes: 23 additions & 0 deletions LICENSE
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright 2012 Bernard Paulus. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 changes: 24 additions & 0 deletions README.md
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,24 @@
MVEDIT
======

Move/delete multiple files at once!

This opens an editor with one line per file of the current directory.

* Editing the filename on the line renames the file.
* Emptying the line deletes the file.

Happy directory editing!

Contribute
==========

Any help is welcomed, especially with the bugs :)

See Bugs below, or TODO 's in the file.

Bugs
======

Beware, special things like exchanging the names of two files or moving two
files to the same filename is still not handled.
75 changes: 75 additions & 0 deletions mvedit
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash
# TODO:
# - git/svn support
# - whitespace lines as delete?
# - two files exchange names
# - two target files have the same name
# - editor switch in options (use nano if no $EDITOR value
if [ "$1" == "-h" -o "$1" == "-help" -o "$1" == "--help" ]
then
echo "moves multiple files at once by letting you edit the directory listing"
echo "a listing of the current directory will be shown."
echo "You can edit that listing, so that"
echo "each file is moved to the new filename present on the line"
echo "empty line definitively deletes a file"
echo "THIS VERSION DOESN'T SUPPORT FILE INTERCHANGE"
echo "option -q, --quiet suppresses most of the output"
exit 0
fi

quiet="false"
if [ "$1" == "-q" -o "$1" == "--quiet" ]
then
quiet="true"
fi

if [ ! -x "$EDITOR" ]
then
echo "\$EDITOR should be set to your preferred editor"
echo "you can set it with"
echo "export EDITOR=YOUR_EDITOR"
exit -1
fi

# prints line of file $1 at line $2
function printlineat {
cat -n "$1" | awk "\$1 == $2 {print;}" | cut --complement --fields=1
}

tmpfile="/tmp/mveditsource$RANDOM.tmp"
editfilename="mvedit_edit$RANDOM.tmp"
editfile="/tmp/$editfilename"
backup_on_error="$editfilename.bak"
MV_COMMAND="mv"
RM_COMMAND="rm"
ls -1a | grep -v '^\.$' | grep -v '^\.\.$' > "$tmpfile"
cp "$tmpfile" "$editfile"
$EDITOR "$editfile"
nlinestmp=`wc -l "$tmpfile" | awk '{print $1}'`
nlinesedit=`wc -l "$editfile" | awk '{print $1}'`
if [ $nlinestmp -eq $nlinesedit ]
then
for i in `seq 1 $nlinesedit`
do
orig=`printlineat $tmpfile $i`
target=`printlineat $editfile $i`
if [ "$orig" != "$target" ]
then
if [ "$target" == "" ]
then
[ "$quiet" == "false" ] && echo "$i/$nlinesedit: RM $orig"
$RM_COMMAND "$orig"
else
[ "$quiet" == "false" ] && echo "$i/$nlinesedit: MV $orig $target"
$MV_COMMAND "$orig" "$target"
fi
fi
done
else
echo "Error: file lengths don't match! Empty line to delete a file."
cp "$editfile" "$backup_on_error"
echo "> Saved your version in $backup_on_error"
fi

rm $tmpfile $editfile

0 comments on commit e6da851

Please sign in to comment.