{"id":22060717,"url":"https://github.com/bulletmark/edir","last_synced_at":"2025-05-16T15:08:19.244Z","repository":{"id":42186889,"uuid":"195335032","full_name":"bulletmark/edir","owner":"bulletmark","description":"Program to rename, remove, and copy files and directories using your editor","archived":false,"fork":false,"pushed_at":"2025-04-17T22:32:39.000Z","size":287,"stargazers_count":155,"open_issues_count":1,"forks_count":8,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-13T03:51:17.291Z","etag":null,"topics":["bulkrename","git","moreutils","ranger","trash-cli","trash-put","vidir","vim","yazi"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bulletmark.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-07-05T03:49:18.000Z","updated_at":"2025-05-08T17:13:27.000Z","dependencies_parsed_at":"2023-11-17T01:09:49.168Z","dependency_job_id":"2c311c51-a515-4c67-a3f7-236ad117aca7","html_url":"https://github.com/bulletmark/edir","commit_stats":{"total_commits":124,"total_committers":3,"mean_commits":"41.333333333333336","dds":"0.016129032258064502","last_synced_commit":"ddbbb1c8b3f83462c42a82cdd2804fafb1bf58c8"},"previous_names":[],"tags_count":52,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bulletmark%2Fedir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bulletmark%2Fedir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bulletmark%2Fedir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bulletmark%2Fedir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bulletmark","download_url":"https://codeload.github.com/bulletmark/edir/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254553958,"owners_count":22090417,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bulkrename","git","moreutils","ranger","trash-cli","trash-put","vidir","vim","yazi"],"created_at":"2024-11-30T18:01:39.445Z","updated_at":"2025-05-16T15:08:14.234Z","avatar_url":"https://github.com/bulletmark.png","language":"Python","funding_links":[],"categories":["Python","Command Line Tools"],"sub_categories":[],"readme":"## EDIR - Rename, Remove, and Copy Files and Directories Using Your Editor\n[![PyPi](https://img.shields.io/pypi/v/edir)](https://pypi.org/project/edir/)\n[![AUR](https://img.shields.io/aur/version/edir)](https://aur.archlinux.org/packages/edir/)\n\n[`edir`][edir] is a command line utility to rename, remove, and copy\nfilenames and directories using your text editor. Run it in the current\ndirectory and `edir` will open your editor on a list of files and\ndirectories in that directory. Each item in the directory will appear on\nits own numbered line. These numbers are how `edir` keeps track of what\nitems are changed. Delete lines to remove files/directories, edit lines\nto rename files/directories, or duplicate line numbers to copy\nfiles/directories. You can also switch pairs of numbers to swap files or\ndirectories. If run from within a [Git](https://git-scm.com/)\nrepository, `edir` will [use\nGit](#renames-and-deletes-in-a-git-repository) to rename or remove\ntracked files/directories. You can use a [trash program](#using-trash)\nto remove files.\n\nThe latest version and documentation is available at\nhttps://github.com/bulletmark/edir.\n\n## Advantages Compared to Vidir\n\n[`edir`][edir] unashamedly mimics the functionality of the\n[vidir](https://linux.die.net/man/1/vidir) utility from\n[moreutils](https://joeyh.name/code/moreutils/) but aims to improve it\nin the following ways:\n\n1. `edir` automatically uses `git mv` instead of `mv` and `git rm`\n    instead of `rm` for tracked files when invoked within a\n    [Git](https://git-scm.com/) repository. There is also a `-G/--no-git`\n    option to suppress this default action. See the description in the\n    section below about [git options](#renames-and-deletes-in-a-git-repository).\n\n2. `vidir` presents file and directories equivalently but `edir` adds a\n   trailing slash `/` to visually discriminate directories. E.g. if `afile` and\n   `bfile` are files, `adir` and `bdir` are directories, then `vidir`\n   presents these in your editor as follows.\n\n   ```\n   1\t./a\n   2\t./b\n   3\t./c\n   4\t./d\n   ```\n\n   But `edir` presents these as:\n\n   ```\n   1\t./a\n   2\t./b\n   3\t./c/\n   4\t./d/\n   ```\n\n   Note the trailing slash is only for presentation in your editor. You\n   are not required to ensure it is present after editing. E.g. editing\n   line 3 above to `./e` (or even just to `e`) would still rename the\n   directory `c` to `e`.\n\n   Note also, that both `edir` and `vidir` show the leading `./` on each\n   entry so that any leading spaces on the filename are clearly seen,\n   and can be edited.\n\n3. `edir` adds the ability to copy files or directories one or more\n   times when you duplicate a numbered line (after the original).\n   `vidir` does not have copy functionality.\n\n4. `edir` allows you to remove a file/directory by deleting the line, as\n   `vidir` does, but you can also remove it by pre-pending a `#` to\n   \"comment it out\" or by substituting an entirely blank line.\n\n5. By default, `edir` prints remove, rename, and copy messages whereas\n   `vidir` prints messages only when the `-v/--verbose` switch is added.\n   You can add `-q/--quiet` to `edir` to suppress these messages.\n\n6. `edir` outputs messages in color. Remove messages are red, rename\n   messages are yellow, and copy messages are green. You can choose to\n   disable colored output.\n\n7. When `vidir` is run with the `-v/--verbose` switch then it reports\n   the renaming of original to intermediate temporary to final files if\n   files are swapped etc. That is rather an implementation detail so\n   `edir` only reports the original to final renames which is all the\n   user really cares about.\n\n8. To remove a large recursive tree you must pipe the directory tree to\n   `vidir` and then explicitly remove all children files and directories\n   before deleting a parent directory. You can do this also in `edir` of\n   course (and arguably it is probably the safest approach) but there\n   are times when you really want to let `edir` remove recursively so\n   `edir` adds a `-r/--recurse` switch to allow this. BE CAREFUL USING\n   THIS!\n\n9. `vidir` always shows all files and directories in a directory,\n   including hidden files and directories (i.e. those starting with a\n   `.`). Usually a user does not want to be bothered with these so\n   `edir` by default does not show them. They can be included by adding\n   the `-a/--all` switch.\n\n10. `edir` does not require the user to specify the `-` if something has\n    been piped to standard input. E.g. you need only type `find | edir`\n    as opposed to `find | edir -`. Note that `vidir` requires the second\n    form.\n\n11. `edir` adds a [`-i/--interactive` option](#previewing-changes) to\n    show pending changes and prompt the user before actioning them. You\n    can also choose to re-edit the changes.\n\n12. `edir` adds a `-F/--files` option to only show files, or `-D/--dirs`\n    to only show directories.\n\n13. `edir` adds a `-L/--nolinks` option to ignore symbolic links.\n\n14. `edir` adds a `-d/--depth` option to edit to the specified directory\n    depth. The default is 1 so `edir a` (if a is a directory) will edit\n    names to `a/*`, `edir -d2 a` will edit names to `a/*/*`, etc. `edir\n    -d0 a` will just edit the `a` name directly. Can specify `-1` to\n    edit to all depths (or use a large positive number).\n\n15. `edir` adds a [`-t/--trash` option](#using-trash) to remove to your\n    [Trash](https://specifications.freedesktop.org/trash-spec/trashspec-1.0.html).\n    By default this option invokes\n    [`trash-put`](https://www.mankier.com/1/trash-put) from the\n    [trash-cli](https://github.com/andreafrancia/trash-cli) package to\n    do deletions but you can specify any alternative trash program, see\n    [section below](#using-trash).\n\n16. `edir` adds `-N/--sort-name, -M/--sort-time, -S/--sort-size` options\n    to sort the paths when listed in your editor. There is also a\n    `-E/--sort-reverse` option to reverse the order.\n\n17. `edir` adds `-X/--group-dirs-first` and `-Y/--group-dirs-last`\n    options to display directories grouped together, either first or\n    last. These can be combined with the above sorting options.\n\n18. `edir` shows a message \"No files or directories\" if there is nothing\n    to edit, rather than opening an empty file as `vidir` does.\n\n19. `edir` filters out any duplicate paths you may inadvertently specify\n    on it's command line.\n\n20. `edir` always invokes a consistent duplicate renaming scheme. E.g. if\n    you rename `b`, `c`, `d` all to the same pre-existing name `a` then\n    `edir` will rename `b` to `a~`, `c` to `a~1`, `d` to `a~2`.\n    Depending on order of operations, `vidir` is not always consistent\n    about this, E.g. sometimes it creates a `a~1` with no `a~` (this may\n    be a bug in `vidir` that nobody has ever bothered to\n    report/address?).\n\n21. `edir` creates the temporary editing file with a `.sh` suffix so\n    your EDITOR may syntax highlight the entries. Optionally, you can\n    change this default suffix.\n\n22. `edir` provides an optional environment value to add custom options\n    to the invocation of your editor. See [section\n    below](#edir_editor-environment-variable).\n\n23. `edir` provides an optional configuration file to set default `edir`\n    command line options. See [section below](#command-default-options).\n\n24. Contrary to what it's name implies, `vidir` actually respects your\n    `$EDITOR` variable and runs your preferred editor like `edir` does\n    but `edir` has been given a generic name to make this more apparent.\n    If `$EDITOR` is not set then `edir` uses a default editor\n    appropriate to your system.\n\n25. `vidir` returns status code 0 if all files successful, or 1 if any\n     error. `edir` returns 0 if all files successful, 1 if some had\n     error, or 2 if all had error.\n\n26. `vidir` returns an error when attempting to rename across different\n    file systems, which `edir` allows.\n\n27. `edir` always ensures editor line numbers have the same width (e.g.\n    `1` to `6` for 6 files, or `01` to `12` for 12 files, etc) so that\n    file names always line up justified. This facilitates block editing\n    of file names, e.g. using vim's [visual block\n    mode](https://linuxhint.com/vim-visual-block-mode/). `vidir` doesn't\n    do this so file names can be jagged wrt each other which makes block\n    editing awkward.\n\n28. `edir` is very strict about the format of the lines you edit and\n    immediately exits with an error message (before changing anything)\n    if you format one of the lines incorrectly. All lines in the edited\n    list:\n\n    1. Must start with a number and that number must be in range.\n    2. Must have at least one white space/tab after the number,\n    3. Must have a remaining valid path name.\n    4. Can start with a `#` or be completely blank to be considered the\n       same as deleted.\n\n    Note the final edited order of lines does not matter, only the first\n    number value is used to match the newly edited line to the original\n    line so an easy way to swap two file names is just to swap their\n    numbers.\n\n29. `edir` always actions files consistently. The sequence of\n     operations applied is:\n\n    1. Deleted files are removed and all renamed files and directories\n       are renamed to temporaries. The temporaries are made on the same\n       file-system as the target.\n\n    2. Empty deleted directories are removed.\n\n    3. Renamed temporary files and directories are renamed to their\n       target name. Any required copies are created.\n\n    4. Remaining deleted directories are removed.\n\n    In simple terms, remember that files are processed before\n    directories so you can rename files into a different directory and\n    then delete the original directory, all in one edit. However in\n    practice it is far **less confusing and less risky** if you perform\n    complicated renames and moves in distinct steps.\n\n## Renames and Deletes in a GIT Repository\n\nWhen working within a [Git](https://git-scm.com/) repository, you nearly\nalways want to use `git mv` instead of `mv` and `git rm` instead of `rm`\nfor files and directories so `edir` recognises this and does it\nautomatically. Note that only tracked files/dirs are moved or renamed\nusing Git. Untracked files/dirs within the repository are removed or\nrenamed in the normal way.\n\nIf for some reason you don't want automatic git action then you can use\nthe `-G/--no-git` option temporarily, or set it a default option. See\nthe section below on how to set [default\noptions](#command-default-options). If you set `--no-git` as the\ndefault, then you can use `-g/-git` on the command line to turn that\ndefault option off temporarily and re-enable git functionality.\n\n## Using Trash\n\nGiven how easy `edir` facilitates deleting files, some users may prefer\nto remove them to system\n[Trash](https://specifications.freedesktop.org/trash-spec/trashspec-1.0.html)\nfrom where they can be later listed and/or recovered. Specifying\n`-t/--trash` does this by executing the\n[`trash-put`](https://www.mankier.com/1/trash-put) command, from the\n[`trash-cli`](https://github.com/andreafrancia/trash-cli) package, to\nremove files rather than removing them natively.\n\nYou may want to set `-t/--trash` as a default option. If you do so then\nyou can use `-T` on the command line to turn that default option off\ntemporarily.\n\nYou can specify an alternative trash program, e.g.\n[`trash-d`](https://github.com/rushsteve1/trash-d), or\n[`gio trash`](https://man.archlinux.org/man/gio.1#COMMANDS), or\n[`gtrash put`](https://github.com/umlx5h/gtrash),\nby setting the `--trash-program` option. Most likely you\nwant to set this as a [default option](#command-default-options).\n\n## Previewing Changes\n\nMany users would like to see a preview of changes after they finish\nediting but before they are actioned by `edir`, i.e. to confirm exactly\nwhich files/dirs will be deleted, renamed, or copied. Add the\n`-i/--interactive` option and `edir` will present a list of changes and\nprompt you to continue, or allow you to re-edit the path list etc.\nConsider setting `--interactive` as a [default\noption](#command-default-options) so you are always prompted.\n\nAfter a preview of pending changes is shown a prompt is presented for\nthe user to enter a single key:\n\n`(P)roceed/(Y)es, (E)dit, (R)estart, (Q)uit[default]: [p|y|e|r|q]?`\n\nwhere:\n\n|Option       |Key       |Action|\n|---          |---       |---|\n|`Proceed/Yes`|`p` or `y`|Proceed with the path changes.|\n|`Edit`       |`e`       |Edit the path list again, as it is was last edited.|\n|`Restart`    |`r`       |Restart editing the path list again, as it originally began.|\n|`Quit`       |`q`       |Quit immediately without making any changes. This is the default if no key is entered.|\n\n## Installation or Upgrade\n\nPython 3.8 or later is required. Arch Linux users can install [`edir`\nfrom the AUR](https://aur.archlinux.org/packages/edir) and skip this\nsection.\n\nNote [`edir` is on PyPI](https://pypi.org/project/edir/) so the easiest\nway to install it is to use [`uv tool`][uvtool] (or [`pipx`][pipx] or\n[`pipxu`][pipxu]).\n\n```sh\n$ uv tool install edir\n```\n\nTo upgrade:\n\n```sh\n$ uv tool upgrade edir\n```\n\nTo uninstall:\n\n```sh\n$ uv tool uninstall edir\n```\n\n[Git](https://git-scm.com/) must be installed if you want to use the git\noptions. A trash program such as\n[trash-cli](https://github.com/andreafrancia/trash-cli) package is\nrequired if you want `-t/--trash` functionality.\n\n### EDIR_EDITOR Environment Variable\n\n`edir` selects your editor from the first environment value found of:\n`$EDIR_EDITOR` or `$EDITOR`, then guesses a fallback default editor\nappropriate to your system if neither of these are set.\n\nYou can also set `EDIR_EDITOR` explicitly to an editor + arguments\nstring if you want `edir` to call your editor with specific arguments.\n\n## Command Default Options\n\nYou can add default options to a personal configuration file\n`~/.config/edir-flags.conf`. If that file exists then each line of\noptions will be concatenated and automatically prepended to your `edir`\ncommand line arguments. Comments in the file (i.e. starting with a `#`)\nare ignored. Type `edir -h` to see all [supported\noptions](#command-line-options).\n\nThe options `--interactive`, `--all`, `--recurse`, `--quiet`,\n`--no-git`, `--trash`, `--suffix`, `--no-color`, `--no-invert-color`,\n`--group-dirs-first/last`, `--trash-program` are sensible candidates to\nconsider setting as default. If you set these then \"on-the-fly\" negation\noptions `-I`, `-A`, `-R`, `-Q`, `-g`, `-T`, `-Z` are also provided to\ntemporarily override and disable default options on the command line.\n\n## Examples\n\nRename and/or remove any files and directories in the current directory:\n\n```\n$ edir\n```\n\nRename and/or remove any jpeg files in current dir:\n\n```\n$ edir *.jpg\n```\n\nRename and/or remove any files under current directory and subdirectories:\n\n```\n$ find | edir -F\n```\n\nUse [`fd`](https://github.com/sharkdp/fd) to view and `git mv/rm`\nrepository files only, in the current directory only:\n\n```\n$ fd -d1 -tf | edir -g\n```\n\n## Command Line Options\n\nType `edir -h` to view the usage summary:\n\n```\nusage: edir [-h] [-i] [-I] [-a] [-A] [-r] [-R] [-q] [-Q] [-G] [-g] [-t]\n               [-T] [--trash-program TRASH_PROGRAM] [-c] [-C] [-d DEPTH] [-F |\n               -D] [-L] [-N] [-M] [-S] [-E] [-X] [-Y] [-Z] [--suffix SUFFIX]\n               [-V]\n               [args ...]\n\nProgram to rename, remove, or copy files and directories using your editor.\nWill use git to action the rename and remove if run within a git repository.\n\npositional arguments:\n  args                  file|dir, or \"-\" for stdin\n\noptions:\n  -h, --help            show this help message and exit\n  -i, --interactive     prompt with summary of changes and allow re-edit\n                        before proceeding\n  -I, --no-interactive  negate the -i/--interactive option\n  -a, --all             include all (including hidden) files\n  -A, --no-all          negate the -a/--all option\n  -r, --recurse         recursively remove any files and directories in\n                        removed directories\n  -R, --no-recurse      negate the -r/--recurse option\n  -q, --quiet           do not print successful rename/remove/copy actions\n  -Q, --no-quiet        negate the -q/--quiet option\n  -G, --no-git          do not use git if invoked within a git repository\n  -g, --git             negate the --no-git option and DO use automatic git\n  -t, --trash           use trash program to do deletions\n  -T, --no-trash        negate the -t/--trash option\n  --trash-program TRASH_PROGRAM\n                        trash program to use, default=\"trash-put\"\n  -c, --no-color        do not color rename/remove/copy messages\n  -C, --no-invert-color\n                        do not invert the color to highlight error messages\n  -d, --depth DEPTH     edit paths to specified depth, default=1\n  -F, --files           only show/edit files\n  -D, --dirs            only show/edit directories\n  -L, --nolinks         ignore all symlinks\n  -N, --sort-name       sort paths in file by name, alphabetically\n  -M, --sort-time       sort paths in file by time, oldest first\n  -S, --sort-size       sort paths in file by size, smallest first\n  -E, --sort-reverse    sort paths (by name/time/size) in reverse\n  -X, --group-dirs-first\n                        group directories first (including when sorted)\n  -Y, --group-dirs-last\n                        group directories last (including when sorted)\n  -Z, --no-group-dirs   negate the options to group directories\n  --suffix SUFFIX       specify suffix for temp editor file, default=\".sh\"\n  -V, --version         show edir version\n\nNote you can set default starting options in $HOME/.config/edir-\nflags.conf. The negation options (i.e. the --no-* options and their\nshortforms) allow you to temporarily override your defaults.\n```\n\n## Embed in Ranger File Manager\n\nIn many ways `edir` (and even `vidir`) is better than the [`ranger`][ranger]\nterminal file manager\n[`bulkrename`](https://github.com/ranger/ranger/wiki/Official-user-guide#bulk-renaming)\ncommand which does not handle name swaps and clashes etc. To add `edir` as a\ncommand within [`ranger`][ranger], add or create the following in\n`~/.config/ranger/commands.py`. Then run it from within [`ranger`][ranger] by\ntyping `:edir`.\n\n```python\nfrom ranger.api.commands import Command\n\nclass edir(Command):\n    '''\n    :edir [file|dir]\n\n    Run edir on the selected file or dir.\n    Default argument is current dir.\n    '''\n    def execute(self):\n        self.fm.run('edir -q ' + self.rest(1))\n    def tab(self, tabnum):\n        return self._tab_directory_content()\n```\n\n## Use with Yazi File Manager\n\nIf you use [`yazi`][yazi] for your file manager then you don't need any special\nconfiguration. Just type `:edir` from within [`yazi`][yazi].\n\n## License\n\nCopyright (C) 2019 Mark Blakeney. This program is distributed under the\nterms of the GNU General Public License. This program is free software:\nyou can redistribute it and/or modify it under the terms of the GNU\nGeneral Public License as published by the Free Software Foundation,\neither version 3 of the License, or any later version. This program is\ndistributed in the hope that it will be useful, but WITHOUT ANY\nWARRANTY; without even the implied warranty of MERCHANTABILITY or\nFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License at\n\u003chttp://www.gnu.org/licenses/\u003e for more details.\n\n[edir]: https://github.com/bulletmark/edir\n[edirpy]: https://pypi.org/project/edir\n[pipx]: https://github.com/pypa/pipx\n[pipxu]: https://github.com/bulletmark/pipxu\n[uvtool]: https://docs.astral.sh/uv/guides/tools/#installing-tools\n[ranger]: https://ranger.github.io/\n[yazi]: https://yazi-rs.github.io/\n\n\u003c!-- vim: se ai syn=markdown: --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbulletmark%2Fedir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbulletmark%2Fedir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbulletmark%2Fedir/lists"}