Utility to rename and remove files/dirs using your editor
EDIR - Rename and Delete Files and Directories Using Your Editor
edir is a command line utility to
rename and remove filenames and directories using your text editor.
Run it in the current directory and
edir will open your editor on a
list of files and directories in that directory. Each item in the
directory will appear on its own numbered line. These numbers are how
edir keeps track of what items are changed. Delete lines to remove
files/directories, or edit lines to rename files/directories. You can
also switch pairs of numbers to swap files or directories.
Comparison to Vidir
vidirpresents file and directories equivalently but
ediradds a trailing slash
/to visually discriminate directories. E.g. if
bdirare directories, then
vidirpresents these in your editor as follows.
1 ./a 2 ./b 3 ./c 4 ./d
edirpresents these as:
1 ./a 2 ./b 3 ./c/ 4 ./d/
Note the trailing slash is only for presentation in your editor. You are not required to ensure it is present after editing. E.g. editing line 3 above to
./e(or even just to
e) would still rename the directory
Note also, that both
vidirshow the leading
./on each entry so that any leading spaces are clearly seen, and can be edited.
edirallows you to remove a file/directory by deleting the line, as
vidirdoes, but you can also remove it by pre-pending a
#to "comment it out" or by substituting an entirely blank line.
edirprints remove and rename messages whereas
vidirprints those only when the
-v/--verboseswitch is added. You can add
edirto suppress these messages.
vidiris run with the
-v/--verboseswitch then it reports the renaming of original to intermediate temporary to final files if files are swapped etc. That is rather an implementation detail so
edironly reports the original to final renames which is all the user really cares about.
To remove a large recursive tree you must pipe the directory tree to
vidirand then explicitly remove all children files and directories before deleting a parent directory. You can do this also in
edirof course (and arguably it is probably the safest approach) but there are times when you really want to let
edirremove recursively so
-r/--recurseswitch to allow this. BE CAREFUL USING THIS!
vidiralways shows all files and directories in a directory, including hidden files and directories (i.e. those starting with a
.). Usually a user does not want to be bothered with these so
edirby default does not show them. They can be included by adding the
edirdoes not require the user to specify the
-if something has been piped to standard input. E.g. you need only type
find | ediras opposed to
find | edir -. Note that
vidirrequires the second form.
ediradds options to only show files (
-f/--files), or to only show directories (
ediradds an option to ignore symbolic links (
edirshows a message "No files or directories" if there is nothing to edit, rather than opening an empty file to edit.
edirfilters out any duplicate paths you may inadvertently specify on it's command line.
ediralways invokes a consistent duplicate renaming scheme. E.g. if you rename
dall to the same pre-existing name
a~2. Depending on order of operations,
vidiris not always consistent about this, E.g. sometimes it creates a
a~(this may be a bug in
vidirthat nobody has ever bothered to report/address?).
edircreates the temporary editing file with a
.shextension so your EDITOR may syntax highlight the entries.
edirprovides an environment value to add custom options to the invocation of your editor, and/or to set default
edircommand arguments. See below.
Contrary to what it's name implies,
vidiractually respects your
$EDITORvariable and runs your preferred editor like
edirhas been given a generic name to make this more apparent.
ediris very strict about the format of the lines you edit and immediately exits with an error message (before changing anything) if you format one of the lines incorrectly. All lines in the edited list:
- Must start with a number, that number must be in range, and that number must be unique,
- Must have at least one white space/tab after the number,
- Must have a remaining valid path name.
- Can start with a
#or be completely blank to be considered the same as deleted.
Note the final edited order of lines does not matter, only the first number value is used to match the newly edited line to the original line so an easy way to swap two file names is just to swap their numbers.
ediralways removes and renames files consistently. The sequence of operations applied is:
Deleted files are removed and all renamed files and directories are renamed to temporaries. The temporaries are made on the same file-system as the target.
Empty deleted directories are removed.
Renamed temporary files and directories are renamed to their target name.
Remaining deleted directories are removed.
In simple terms, remember that files are processed before directories so you can rename files into a different directory and then delete the original directory, all in one edit.
Arch users can install edir from the AUR.
Python 3.5 or later is required. Note edir is on
PyPI so you can
sudo pip3 install edir
$ git clone http://github.com/bulletmark/edir $ sudo pip3 install ./edir
Optionally, if you are using an odd system and/or want to install this
manually then all you need to do is rename
edir and make
it executable somewhere in your path.
Edir runs on pure Python. No 3rd party packages are required.
edir selects your editor from the first environment value found of:
$EDITOR, then falls back to "vi" if
none of these are set.
You can set
EDIR_EDIT_COMMAND explicitly to an editor + arguments
string if you want
edir to call your editor with specific arguments.
This allow you to set default starting arguments to
edir -h to see the arguments supported. E.g. export
edir not print rename and remove actions.
Rename and/or delete any files and directories in the current directory:
Rename and/or delete any jpeg files in current dir:
Rename and/or delete any files under current directory and subdirectories:
find | edir -f
Command Line Options
usage: edir [-h] [-a] [-r] [-q] [-f | -d] [-l] [args [args ...]] Program to rename and remove files and directories using your editor. positional arguments: args file|dir, or "-" for stdin optional arguments: -h, --help show this help message and exit -a, --all include/show all (including hidden) files -r, --recurse recursively remove any files and directories in removed directories that are non-empty -q, --quiet do not print rename/remove actions -f, --files only show files -d, --dirs only show directories -l, --nolinks ignore all symlinks
Embed in Ranger File Manager
In many ways
vidir) are better than the
command (which does not handle name clashes etc). To add
edir as a
command within ranger, add or create the following in
from ranger.api.commands import Command class edir(Command): ''' :edir [file|dir] Run edir on the selected file or dir. Default argument is current dir. ''' def execute(self): self.fm.run('edir -q ' + self.rest(1)) def tab(self, tabnum): return self._tab_directory_content()
Copyright (C) 2019 Mark Blakeney. This program is distributed under the terms of the GNU General Public License. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License at http://www.gnu.org/licenses/ for more details.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size edir-1.5.tar.gz (9.1 kB)||File type Source||Python version None||Upload date||Hashes View hashes|