bulletmark / edir Goto Github PK
View Code? Open in Web Editor NEWProgram to rename, remove, and copy files and directories using your editor
Program to rename, remove, and copy files and directories using your editor
While this is not the most important issue, it would drastically improve readability (especially when modifying a large amount of files) if the output would be columnized so that the actuall file names involved are more clearly visible.
For example this is the current output:
Removed Night and Mare
Copied My Journey to the Center of the Hound Hill to Johnny runs away
Renamed My uncle an I go fishing to My aunt an you went fishing
It is very hard to see where the original file name ends and the new file name begins. While this may be a bit easier if the files have common short file extensions, it still hard to skim for filenames with varying lengths and filenames containing spaces.
Therefore I propose formatting the output in the following way:
Deleted "Night and Mare"
Copied "My Journey to the Center of the Hound Hill" to "Johnny runs away"
Renamed "My uncle an I go fishing" to "My aunt an you went fishing"
The following changes are made to the original output format:
Each single one of those changes improves readability, but I think the best readability can be achieved by doing all of them.
Another possibility is using a more formalized output format (similar to the format proposed in #13) that uses special characters instead of plain english for everything that is not part of the file name. Here is an example:
Deleted "Night and Mare"
Copied "My Journey to the Center of the Hound Hill" → "Johnny runs away"
Renamed "My uncle an I go fishing" → "My aunt an you went fishing"
Even the operation in the first column could be replaced by some special character, but it’s a bit harder to find characters whose meaning would be obvious. Single chars "r", "c", "d" (like used in the proposal in #13) would not provide that much benefit over the english terms (at least if the columnization is applied).
Whether this output format should be the only one or should be selectable by a specific commandline option is left to your judgement.
Perhaps edir was never designed to work on Windows, but I've used vidir with vim successfully in many Windows command shells and thought it would be great to upgrade to edir instead when I learned of it. So I installed pipx, then used that to install edir, but when I run it I get the following error:
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in run_code
File "C:\users\john.local\bin\edir.exe_main.py", line 7, in
File "C:\Users\John.local\pipx\venvs\edir\Lib\site-packages\edir.py", line 578, in main
paths = Fpath.get_path_changes()
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\John.local\pipx\venvs\edir\Lib\site-packages\edir.py", line 380, in get_path_changes
editfile(fpath)
File "C:\Users\John.local\pipx\venvs\edir\Lib\site-packages\edir.py", line 64, in editfile
with open('/dev/tty') as tty:
^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/dev/tty'
Any thoughts? Or is edir simply not intended for use on Windows?
Error messages are arguably the most important messages and therefore should receive the most prominent color. At the moment they are not colored at all and can therefore be easily overlooked.
Usually error messages are printed in "red". As red is already used for deletion of files that imposes a conflict.
The options I see are:
From those option the second one appeals most to me, but I think you should take the actual decision how to handle this.
A (not very unlikely) error can be, for example, missing write permissions.
A second issue with error messages (which is related to this one; therefore I don't open a second issue for that one) is that only the original filename is visible, not the operation that should be applied nor the resulting filename (if applicable). For example the message
Create dir for some file ERROR: Can not write in documents
is printed when trying to rename the file "some file" in the directory "documents".
Therefore the error message should be improved (if possible) and the failed operation (with the involved file names) should be written out (in the same format as the successful output, but clearly differentiated so that it is clear that this is a failed operation).
A default .sh
suffix was added in f4600c6:
edir
creates the temporary editing file with a.sh
suffix so
your EDITOR may syntax highlight the entries. Optionally, you can
change this default suffix.
Unfortunately, this default doesn't give a good experience:
For any filename with special characters (and by "special" it can be digits, or anything with a special meaning in shell script), the syntax highlighting is bad. So bad it makes the UX incredibly worse for the user.
May I suggest a default being .edir
instead? And then you or someone could create a simple syntax file for this type. And I'd argue that an unrecognized filetype with no syntax highlighting is better than a broken highlighting like that one on the screenshots.
So we can just install by pip install edir
.
If you make a file with spaces in its name, i.e. touch "a test"
, then try to delete it with edir -t
, it tries to treat it as separate files "a" and "test" with the output:
Remove a test ERROR: trash-put error: trash-put: cannot trash non existent 'a'
trash-put: cannot trash non existent 'test'
When batch-editing file names I often rely on the "block visual" mode in vim. This is useful when I need to add/remove/edit common prefix to file names.
However, a problem with both vidir and edir is that line numbers can have different width, e.g.:
This causes filenames across lines to not left-aligned.
Here are some ideas that make them more aligned:
Hi!
I love edir, thank you so much for making it.
I was interested in an option that would allow one to edit where symlinks point to easily:
1 ./a
2 ./b -> /home/user/b
3 ./c
And then we can modify line 2 by changing where the symlink points to with /home/user/c
for instance.
Would there be interest in my making such a PR?
This isn't a bug, I was just curious as to why in 515f2e5 you switched from doing
with tempfile.NamedTemporaryFile('r+t', suffix=suffix) as fp:
Path.writefile(fp)
editfile(fp.name)
Path.readfile(fp)
to
with tempfile.TemporaryDirectory() as fdir:
fpath = pathlib.Path(f'{fdir}/{PROG}-{os.getpid()}{suffix}')
with fpath.open('w') as fp:
Path.writefile(fp)
editfile(fpath)
with fpath.open() as fp:
Path.readfile(fp)
The two seem basically equivalent to me, except for in the former you have to manually flush/seek in between the write/read. Was switching to the latter motivated just based on clarity, or is there an actual bug that motivated the changed?
I wonder if it could also be useful to be able to create empty files and directories. Let's say we have two dirs before we edit: "1" and "2". After editing we get:
1 ./1/
2 ./2/
new/file
new/dir/
"new file" functionality could be worked around by creating an empty file before starting edir, and then copying it though, but that's an extra step.
There's a bunch of "better than the old applications" out there, most are much faster and most are much worse; you succeed putting a fine polish over vidir, clear documentation with the differences and credit where credit is due, bravo.
I have just replaced vidir with edir in my home grown file manager, took a few minutes (because I already had an edir function, otherwise 5 seconds).
rename() { tcpreview ; printf "%s\n" "${selection[@]}" | edir && tags_clear && cdir '' "$f" ; }
Cheers, Nadim
Great program! I really like that it shows colourful messages on what it's doing when you exit your editor.
Is there a way to have it show me these messages on what it will do, but not actually do them until I confirm? i.e. With a confirmation prompt with y/n to continue or something?
I just get a little paranoid when I'm using these bulk renamer programs, especially considering this one can also delete files too.
I had a look through the existing args, but couldn't see something that sounded like this.
edir
currently supports trash-cli
whose syntax differs from rm
making it not an ideal 1:1 replacement/alias. trash-d can be used as a drop-in replacement for rm
. It would be great if edir
could support trash-d.
Thanks!
my usecase was to copy some of the files located in various subdirs into a single root subdir, e.g.
1 ./2/b.txt
2 ./1/a.txt
after editing
1 ./2/b.txt
2 ./1/a.txt
1 ./tmp/2/b.txt
2 ./tmp/1/a.txt
I get
Copy "2/b.txt" to "tmp/2/b.txt" ERROR: [Errno 2] No such file or directory: 'tmp/2/b.txt'
Copy "1/a.txt" to "tmp/1/a.txt" ERROR: [Errno 2] No such file or directory: 'tmp/1/a.txt'
Edir looks cool and I just installed it and got this:
$ VISUAL="gvim --nofork"
$ edir ./*.mobi
Traceback (most recent call last):
File "/usr/local/bin/edir", line 4, in <module>
exit(main())
File "/usr/local/lib/python3.6/dist-packages/edir.py", line 316, in main
editfile(fp.name)
File "/usr/local/lib/python3.6/dist-packages/edir.py", line 211, in editfile
res = subprocess.run(editcmd, stdin=tty)
File "/usr/lib/python3.6/subprocess.py", line 423, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'gvim --nofork': 'gvim --nofork'
Also it seems to ignore the $EDIR_EDITOR environment variable?
$ EDIR_EDITOR="/usr/local/bin/gvim"
$ edir ./*.mobi
Traceback (most recent call last):
File "/usr/local/bin/edir", line 4, in <module>
exit(main())
File "/usr/local/lib/python3.6/dist-packages/edir.py", line 316, in main
editfile(fp.name)
File "/usr/local/lib/python3.6/dist-packages/edir.py", line 211, in editfile
res = subprocess.run(editcmd, stdin=tty)
File "/usr/lib/python3.6/subprocess.py", line 423, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'gvim --nofork': 'gvim --nofork'
If I try to move a file from one mount point to another, I get this error message:
Traceback (most recent call last):
File "/usr/bin/edir", line 8, in <module>
sys.exit(main())
^^^^^^
File "/usr/lib/python3.11/site-packages/edir.py", line 481, in main
p.rename_temp()
File "/usr/lib/python3.11/site-packages/edir.py", line 180, in rename_temp
rename(self.path, self.temppath, self.is_git)
File "/usr/lib/python3.11/site-packages/edir.py", line 123, in rename
pathsrc.replace(pathdest)
File "/usr/lib/python3.11/pathlib.py", line 1188, in replace
os.replace(self, target)
OSError: [Errno 18] Invalid cross-device link: '/home/denilson/Downloads/FOOBAR' -> '.tmp-edir/FOOBAR'
Example real-world use-case:
~/Downloads/
. Or think about having a USB drive that is mounted.edir
or vidir
to move (and possible rename while moving) files from one location to either the hard drive or to an SMB-mounted network storage.
~/Downloads/IMG_20230102030405.JPG
to /mnt/nas/photos/Party-001.jpg
.This issue is also present in vidir
. (Although I haven't reported it there. Maybe I should — But where is the official vidir repository/project page?).
./dir1/
./a.txt
to
./dir2/
./dir2/a.txt
will cause dir1
to be renamed to dir1~
.
The thing that bugs me the most in vidir
is that changes that cannot be applied due to missing permissions are lost.
Missing permissions are common when trying to edit root-owned files, but forgetting to use sudo.
This is especially annoying if there were lots of manual changes that then have to be applied again.
I think there are two options to support a use case to handle these problems in a smarter way:
sudo
for applying the actual changes.edir
with the correct permissions (e.g. by calling sudo edir < the_special_file
).The advantages of the first option are (in my opinion):
edir
process must run with root privileges and therefore reducing security risks.The advantages of the second option are (in my opinion):
edir
non-interactively, but having all the benefits of edir
(like protection against accidental overwriting of files with the same name, renaming the file and its parent directories at once, etc.).Due to the advantages descibed above I think option 2 is the better option.
If option 2 should be implemented the format of the file must be defined. In my opinion it should a very easy human and machine readable format. Here is an example that just springs to mind as a rough idea:
r /some/file → /some/FiLe
d /some/file
c /some/file → /some/copy
The first being a rename, the second a delete and the third a copy operation.
Of course instead of the Unicode arrow an ASCII arrow (->
) can be used to allow easier creation/modification of such files by the user. But it must be assured that there is no confusion between the separator char (the arrow surrounded by (maybe a specific amount of) spaces) and such a char sequence inside a file name. But that should be easily solvable by checking that the sequence occurs only once per file.
When generating the file from edir
itself (due to an error when trying to apply the operation), a comment header could be added (like an interactive rebase in git) that describes the format:
# Each line must be of the following format:
# For "renaming":
# r <file> → <new name>
#
# For "deleting":
# d <file>
#
# For "copying":
# c <file> → <new file>
Also, in such a case, it must be prominently displayed to the user
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.