Giter Site home page Giter Site logo

edir's People

Contributors

bulletmark avatar guyonvarch avatar kr1ss-xd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

edir's Issues

Provide columnized output for better readability

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:

  • There are (up to) 4 columns:
    1. The operation
    2. The original file name
    3. The word "to"
    4. The new file name
  • The filenames are surrounded by quotes
  • The columns are separated by two (instead of only one) space character
  • The term "Removed" is replaced by "Deleted" to visually differentiate it clearer from the term "Renamed" (this is even more important if the output is not colorized)

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.

Fails on Windows with an error about no such file or directory '/dev/tty'

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 not colored at all

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:

  • Use a different color than red for errors (e.g. magenta)
  • Use a different color for deletions and use red for errors
  • Use bold red for errors

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".

  • The error message itself is a bit misleading (as it states "Create dir for").
  • It is not clear whether the file should have been renamed, deleted or copied.
  • The target file name (for renaming or copying) is not visible.
  • The file names are not separated enough from the error messages, this is especially true for file names containing spaces (this is related to #14).

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).

Suggestion: change the default `.sh` suffix for the temporary file

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:

Screenshot 1 of vim/edir, renaming some music files

Screenshot 2 of vim/edir, renaming some music files

Screenshot 3 of vim/edir, renaming some music files

Screenshot 4 of vim/edir, renaming some music files

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.

Add to pip

So we can just install by pip install edir.

Can't delete files with spaces in their names using trash-put

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'

Feature: make filenames more aligned for block-visual mode

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.:

2023-06-29_08-20

This causes filenames across lines to not left-aligned.

Here are some ideas that make them more aligned:

  • Add an option (or maybe even default) to pad the line numbers (by space or zeros) such that all numbers have the same number of characters, therefore all filenames are left-aligned.
  • Add an option to choose whether to left-align or right-align the filenames. (right-align can be useful if I need to add/remove/edit common suffix). Alignment can be implemented by space paddings.

Option for editing symlinks

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?

[Question] Motivation for changing temp file write/read in 515f2e5

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?

creating new empty files and directories

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.

Great work.

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

Sort directories before files

I've tried my hands on fixing this myself but to no avail. :)

Can we get an option that lets us sort directories before files?
Just like how ls --group-directories-first work, and how vidir does it.

edir:
edir

default vidir, no sort but directories still first:
vidir

vidir with -s flag (sort):
vidir

Option to preview + confirm changes before they're actually executed?

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.

[Enhancement] Add support for trash-d

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!

when copying, subdirectories are not created

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'

Editor argument throws error

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'

Allow cross-device (cross-filesystem) moving

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:

  1. Download a bunch of files to ~/Downloads/. Or think about having a USB drive that is mounted.
  2. Use 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.
    • By "rename while moving" I mean changing from ~/Downloads/IMG_20230102030405.JPG to /mnt/nas/photos/Party-001.jpg.
  3. It fails. :(

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?).

Handle missing permissions in a smart way

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:

  1. Check for permissions to rename/delete/copy and if there are insufficient permissions, call sudo for applying the actual changes.
  2. Write the failed operations to a file that can later be fed to edir with the correct permissions (e.g. by calling sudo edir < the_special_file).

The advantages of the first option are (in my opinion):

  • Best "user experience" by supporting exactly that use case and doing the most convenient thing by (from the point of view of the user) asking for the password to get permissions to apply the changes.
  • Not the whole edir process must run with root privileges and therefore reducing security risks.

The advantages of the second option are (in my opinion):

  • Should be easier to implement as the other approach seems to involve lots of additional code for just one specific use case (but I might be wrong here).
  • Can be used for other errors than just permission problems (e.g. copy failed due to insuffient disk space). It supports therefore a more general use case than the very specific use case in option 1.
  • Can even be used "manually" by creating the above mentioned file (either by writing it by hand or generating it some other way). This would be using 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.).
  • Allows additional changes to the files in question (like reducing the length of the resulting file name, removing certain characters that are not allowed for the current filesystem, 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

  • that there were errors applying the changes
  • that a file with those erroneous operations was written and the full path to that file
  • how to feed that file to edir to reexecute the operations when the cause of the errors was resolved

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.