Package: edir
EDIR - Rename, Remove, and Copy Files and Directories Using Your Editorediris a command line utility to
rename, remove, and copy filenames and directories using your text
editor. Run it in the current directory andedirwill 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 howedirkeeps track of what items are changed. Delete lines to remove
files/directories, edit lines to rename files/directories, or duplicate
line numbers to copy files/directories. You can also switch pairs of
numbers to swap files or directories. If run from within aGitrepository,edirwilluse
Gitto rename or remove
tracked files/directories. You can use atrash programto remove files.The latest version and documentation is available athttps://github.com/bulletmark/edir.Advantages Compared to Vidiredirunashamedly mimics the
functionality of thevidirutility
frommoreutilsbut aims to improve it in
the following ways:edirautomatically usesgit mvinstead ofmvandgit rminstead ofrmfor tracked files when invoked within aGitrepository. There is also a-G/--no-gitoption to suppress this default action. See the description in the
section below aboutgit options.vidirpresents file and directories equivalently butediradds a
trailing slash/to visually discriminate directories. E.g. ifafileandbfileare files,adirandbdirare directories, thenvidirpresents these in your editor as follows.1	./a
2	./b
3	./c
4	./dButedirpresents 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 toe) would still rename the
directoryctoe.Note also, that bothedirandvidirshow the leading./on each
entry so that any leading spaces are clearly seen, and can be edited.ediradds the ability to copy files or directories one or more
times when you duplicate a numbered line.vidirdoes not have copy
functionality.edirallows you to remove a file/directory by deleting the line, asvidirdoes, but you can also remove it by pre-pending a#to
"comment it out" or by substituting an entirely blank line.By default,edirprints remove, rename, and copy messages whereasvidirprints messages only when the-v/--verboseswitch is added.
You can add-q/--quiettoedirto suppress these messages.ediroutputs messages in color. Remove messages are red, rename
messages are yellow, and copy messages are green. You can choose to
disable colored output.Whenvidiris 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 soedironly 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 tovidirand then explicitly remove all children files and directories
before deleting a parent directory. You can do this also inedirof
course (and arguably it is probably the safest approach) but there
are times when you really want to letedirremove recursively soediradds a-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 soedirby default does not show them. They can be included by adding
the-a/--allswitch.edirdoes not require the user to specify the-if something has
been piped to standard input. E.g. you need only typefind | ediras opposed tofind | edir -. Note thatvidirrequires the second
form.ediradds a-i/--interactiveoptionto
show pending changes and prompt the user before actioning them. You
can also choose to re-edit the changes.ediradds a-F/--filesoption to only show files, or-D/--dirsto only show directories.ediradds a-L/--nolinksoption to ignore symbolic links.ediradds a-d/--dirnamesoption to edit specified directory
names directly, not their contents. I.e. this is likels -d mydircompared tols mydir.ediradds a-t/--trashoptionto remove to yourTrash.
By default this option invokestrash-putfrom thetrash-clipackage to
do deletions but you can specify any alternative trash program, seesection below.ediradds-N/--sort-name, -M/--sort-time, -S/--sort-sizeoptions
to sort the paths when listed in your editor. There is also a-E/--sort-reverseoption to reverse the order.ediradds-X/--group-dirs-firstand-Y/--group-dirs-lastoptions to display directories grouped together, either first or
last. These can be combined with the above sorting options.edirshows a message "No files or directories" if there is nothing
to edit, rather than opening an empty file asvidirdoes.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 renameb,c,dall to the same pre-existing nameathenedirwill renamebtoa~,ctoa~1,dtoa~2.
Depending on order of operations,vidiris not always consistent
about this, E.g. sometimes it creates aa~1with noa~(this may
be a bug invidirthat nobody has ever bothered to
report/address?).edircreates the temporary editing file with a.shsuffix so
your EDITOR may syntax highlight the entries. Optionally, you can
change this default suffix.edirprovides an optional environment value to add custom options
to the invocation of your editor. Seesection
below.edirprovides an optional configuration file to set defaultedircommand line options. Seesection below.Contrary to what it's name implies,vidiractually respects your$EDITORvariable and runs your preferred editor likeedirdoes
butedirhas been given a generic name to make this more apparent.
If$EDITORis not set thenediruses a default editor
appropriate to your system.vidirreturns status code 0 if all files successful, or 1 if any
error.edirreturns 0 if all files successful, 1 if some had
error, or 2 if all had error.vidirreturns an error when attempting to rename across different
file systems, whichedirallows.ediralways ensures editor line numbers have the same width (e.g.1to6for 6 files, or01to12for 12 files, etc) so that
file names always line up justified. This facilitates block editing
of file names, e.g. using vim'svisual block
mode.vidirdoesn't
do this so file names can be jagged wrt each other which makes block
editing awkward.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 and that number must be in range.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 actions 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. Any required copies are created.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. However in
practice it is farless confusing and less riskyif you perform
complicated renames and moves in distinct steps.Renames and Deletes in a GIT RepositoryWhen working within aGitrepository, you nearly
always want to usegit mvinstead ofmvandgit rminstead ofrmfor files and directories soedirrecognises this and does it
automatically. Note that only tracked files/dirs are moved or renamed
using Git. Untracked files/dirs within the repository are removed or
renamed in the normal way.If for some reason you don't want automatic git action then you can use
the-G/--no-gitoption temporarily, or set it a default option. See
the section below on how to setdefault
options. If you set--no-gitas the
default, then you can use-g/-giton the command line to turn that
default option off temporarily and re-enable git functionality.Using TrashGiven how easyedirfacilitates deleting files, some users may prefer
to remove them to systemTrashfrom where they can be later listed and/or recovered. Specifying-t/--trashdoes this by executing thetrash-putcommand, from thetrash-clipackage, to
remove files rather than removing them natively.You may want to set-t/--trashas a default option. If you do so then
you can use-Ton the command line to turn that default option off
temporarily.You can specify an alternative trash program, e.g.trash-dorgio trash, by setting the--trash-programoption. Most likely you want to set this as adefault
option.Previewing ChangesMany users would like to see a preview of changes after they finish
editing but before they are actioned byedir, i.e. to confirm exactly
which files/dirs will be deleted, renamed, or copied. Add the-i/--interactiveoption and edir will present a list of changes and
prompt you to continue, or allow you to re-edit the path list etc.
Consider setting--interactiveas adefault
optionso you are always prompted.After a preview of pending changes is shown a prompt is presented for
the user to enter a single key:(P)roceed/(Y)es, (E)dit, (R)estart, (Q)uit[default]: [p|y|e|r|q]?where:OptionKeyActionProceed/YesporyProceed with the path changes.EditeEdit the path list again, as it is was last edited.RestartrRestart editing the path list again, as it originally began.QuitqQuit immediately without making any changes. This is the default if no key is entered.Installation or UpgradeArch users can installedir from the AUR.Python 3.6 or later is required. Noteedir is on
PyPIso just ensure thatpipxis installed then type the
following:$ pipx install edirTo upgrade:$ pipx upgrade edirGitmust be installed if you want to use the git
options. A trash program such astrash-clipackage is
required if you want-t/--trashfunctionality.EDIR_EDITOR Environment Variableedirselects your editor from the first environment value found of:$EDIR_EDITORor$EDITOR, then guesses a fallback default editor
appropriate to your system if neither of these are set.You can also setEDIR_EDITORexplicitly to an editor + arguments
string if you wantedirto call your editor with specific arguments.Command Default OptionsYou can add default options to a personal configuration file~/.config/edir-flags.conf. If that file exists then each line of
options will be concatenated and automatically prepended to youredircommand line arguments. Comments in the file (i.e. starting with a#)
are ignored. Typeedir -hto see allsupported
options.The options--interactive,--all,--recurse,--quiet,--no-git,--trash,--suffix,--no-color,--no-invert-color,--group-dirs-first/last,--trash-programare sensible candidates to
consider setting as default. If you set these then "on-the-fly" negation
options-I,-A,-R,-Q,-g,-T,-Zare also provided to
temporarily override and disable default options on the command line.ExamplesRename and/or remove any files and directories in the current directory:$ edirRename and/or remove any jpeg files in current dir:$ edir *.jpgRename and/or remove any files under current directory and subdirectories:$ find | edir -FUsefdto view andgit mv/rmrepository files only, in the current directory only:$ fd -d1 -tf | edir -gCommand Line OptionsTypeedir -hto view the usage summary:usage: edir [-h] [-i] [-I] [-a] [-A] [-r] [-R] [-q] [-Q] [-G] [-g] [-t]
               [-T] [--trash-program TRASH_PROGRAM] [-c] [-C] [-d] [-F | -D]
               [-L] [-N] [-M] [-S] [-E] [-X] [-Y] [-Z] [--suffix SUFFIX] [-V]
               [args ...]

Program to rename, remove, or copy files and directories using your editor.
Will use git to action the rename and remove if run within a git repository.

positional arguments:
  args                  file|dir, or "-" for stdin

options:
  -h, --help            show this help message and exit
  -i, --interactive     prompt with summary of changes and allow re-edit
                        before proceeding
  -I, --no-interactive  negate the -i/--interactive option
  -a, --all             include all (including hidden) files
  -A, --no-all          negate the -a/--all option
  -r, --recurse         recursively remove any files and directories in
                        removed directories
  -R, --no-recurse      negate the -r/--recurse option
  -q, --quiet           do not print successful rename/remove/copy actions
  -Q, --no-quiet        negate the -q/--quiet option
  -G, --no-git          do not use git if invoked within a git repository
  -g, --git             negate the --no-git option and DO use automatic git
  -t, --trash           use trash program to do deletions
  -T, --no-trash        negate the -t/--trash option
  --trash-program TRASH_PROGRAM
                        trash program to use, default="trash-put"
  -c, --no-color        do not color rename/remove/copy messages
  -C, --no-invert-color
                        do not invert the color to highlight error messages
  -d, --dirnames        edit given directory names directly, not their
                        contents
  -F, --files           only show/edit files
  -D, --dirs            only show/edit directories
  -L, --nolinks         ignore all symlinks
  -N, --sort-name       sort paths in file by name, alphabetically
  -M, --sort-time       sort paths in file by time, oldest first
  -S, --sort-size       sort paths in file by size, smallest first
  -E, --sort-reverse    sort paths (by name/time/size) in reverse
  -X, --group-dirs-first
                        group directories first (including when sorted)
  -Y, --group-dirs-last
                        group directories last (including when sorted)
  -Z, --no-group-dirs   negate the options to group directories
  --suffix SUFFIX       specify suffix for temp editor file, default=".sh"
  -V, --version         show edir version

Note you can set default starting options in $HOME/.config/edir-
flags.conf. The negation options (i.e. the --no-* options and their
shortforms) allow you to temporarily override your defaults.Embed in Ranger File ManagerIn many waysedir(andvidir) is better than therangerbulkrenamecommand which does not handle name swaps and clashes etc. To addediras a command withinranger, add or create
the following in~/.config/ranger/commands.py. Then run it from withinrangerby typing:edir.fromranger.api.commandsimportCommandclassedir(Command):''':edir [file|dir]Run edir on the selected file or dir.Default argument is current dir.'''defexecute(self):self.fm.run('edir -q '+self.rest(1))deftab(self,tabnum):returnself._tab_directory_content()LicenseCopyright (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 athttp://www.gnu.org/licenses/for more details.