edir 2.35__tar.gz → 2.36__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: edir
3
- Version: 2.35
3
+ Version: 2.36
4
4
  Summary: Utility to rename, remove, and copy files/dirs using your editor
5
5
  Author-email: Mark Blakeney <mark.blakeney@bullet-systems.net>
6
6
  License-Expression: GPL-3.0-or-later
@@ -230,11 +230,11 @@ following ways:
230
230
 
231
231
  4. Remaining deleted directories are removed.
232
232
 
233
- In simple terms, remember that files are processed before
234
- directories so you can rename files into a different directory and
235
- then delete the original directory, all in one edit. However in
236
- practice it is far **less confusing and less risky** if you perform
237
- complicated renames and moves in distinct steps.
233
+ In simple terms, remember that files are processed before directories so
234
+ you can rename files into a different directory and then delete the
235
+ original directory, all in one edit. However in practice it is far **less
236
+ confusing and less risky** if you perform complicated renames and moves
237
+ across changed directories in distinct steps.
238
238
 
239
239
  ## Renames and Deletes in a GIT Repository
240
240
 
@@ -460,10 +460,10 @@ your defaults.
460
460
  You can use `edir` with [`sudo`][sudo] to rename, delete, or copy system files.
461
461
  For improved convenience and security, `edir` runs the editing session as your
462
462
  regular user, not as root - similar to how [`sudoedit`][sudoedit] works. This
463
- approach allows you to use graphical editors (like VS Code), which should not be
464
- run as root. Use `sudo -E` so that your preferred editor is selected via your
465
- `$EDIR_EDITOR` or `$EDITOR` environment variable. For example, to rename or
466
- delete files in `/etc` using VS Code:
463
+ approach allows you to use graphical editors (like VS Code or Zed etc), which
464
+ normally should not be run as root. Use `sudo -E` so that your preferred editor
465
+ is selected via your `$EDIR_EDITOR` or `$EDITOR` environment variable. For
466
+ example, to rename or delete files in `/etc` using VS Code:
467
467
 
468
468
  ```sh
469
469
  $ export EDIR_EDITOR="code -nw"
@@ -475,8 +475,9 @@ $ sudo -E edir /etc
475
475
  In many ways `edir` (and even `vidir`) is better than the [`ranger`][ranger]
476
476
  terminal file manager
477
477
  [`bulkrename`](https://github.com/ranger/ranger/wiki/Official-user-guide#bulk-renaming)
478
- command which does not handle name swaps and clashes etc. To add `edir` as a
479
- command within [`ranger`][ranger], add or create the following in
478
+ command which does not handle name swaps and clashes etc. Also, use `edir` to
479
+ delete or copy files, not just rename them. To add `edir` as a command within
480
+ [`ranger`][ranger], add or create the following in
480
481
  `~/.config/ranger/commands.py`. Then run it from within [`ranger`][ranger] by
481
482
  typing `:edir`.
482
483
 
@@ -499,8 +500,8 @@ class edir(Command):
499
500
  ## Use with Yazi File Manager
500
501
 
501
502
  If you use [`yazi`][yazi] for your file manager then you don't need any special
502
- configuration. Just type `:edir` from within [`yazi`][yazi] to edit all file
503
- names in the current directory.
503
+ configuration. Just type `:edir` from within [`yazi`][yazi] to rename or delete
504
+ or copy file names in the current directory.
504
505
 
505
506
  You can also replace the standard rename function (`r` key) in [`yazi`][yazi]
506
507
  to use `edir` on selected files by adding the following to your
@@ -509,10 +510,14 @@ to use `edir` on selected files by adding the following to your
509
510
  ```toml
510
511
  [[mgr.prepend_keymap]]
511
512
  on = "r"
512
- run = "shell --block -- edir -q %s"
513
+ run = "shell --block -- edir -d0 -q %s"
513
514
  desc = "Run edir on selected files/dirs"
514
515
  ```
515
516
 
517
+ So press `r` on the current selection to rename (or delete or copy) that single
518
+ file name using `edir`. Alternately, select multiple files (or all files with
519
+ the `yazi` standard key binding `Ctrl+a`), before pressing `r`.
520
+
516
521
  ## License
517
522
 
518
523
  Copyright (C) 2019 Mark Blakeney. This program is distributed under the
@@ -216,11 +216,11 @@ following ways:
216
216
 
217
217
  4. Remaining deleted directories are removed.
218
218
 
219
- In simple terms, remember that files are processed before
220
- directories so you can rename files into a different directory and
221
- then delete the original directory, all in one edit. However in
222
- practice it is far **less confusing and less risky** if you perform
223
- complicated renames and moves in distinct steps.
219
+ In simple terms, remember that files are processed before directories so
220
+ you can rename files into a different directory and then delete the
221
+ original directory, all in one edit. However in practice it is far **less
222
+ confusing and less risky** if you perform complicated renames and moves
223
+ across changed directories in distinct steps.
224
224
 
225
225
  ## Renames and Deletes in a GIT Repository
226
226
 
@@ -446,10 +446,10 @@ your defaults.
446
446
  You can use `edir` with [`sudo`][sudo] to rename, delete, or copy system files.
447
447
  For improved convenience and security, `edir` runs the editing session as your
448
448
  regular user, not as root - similar to how [`sudoedit`][sudoedit] works. This
449
- approach allows you to use graphical editors (like VS Code), which should not be
450
- run as root. Use `sudo -E` so that your preferred editor is selected via your
451
- `$EDIR_EDITOR` or `$EDITOR` environment variable. For example, to rename or
452
- delete files in `/etc` using VS Code:
449
+ approach allows you to use graphical editors (like VS Code or Zed etc), which
450
+ normally should not be run as root. Use `sudo -E` so that your preferred editor
451
+ is selected via your `$EDIR_EDITOR` or `$EDITOR` environment variable. For
452
+ example, to rename or delete files in `/etc` using VS Code:
453
453
 
454
454
  ```sh
455
455
  $ export EDIR_EDITOR="code -nw"
@@ -461,8 +461,9 @@ $ sudo -E edir /etc
461
461
  In many ways `edir` (and even `vidir`) is better than the [`ranger`][ranger]
462
462
  terminal file manager
463
463
  [`bulkrename`](https://github.com/ranger/ranger/wiki/Official-user-guide#bulk-renaming)
464
- command which does not handle name swaps and clashes etc. To add `edir` as a
465
- command within [`ranger`][ranger], add or create the following in
464
+ command which does not handle name swaps and clashes etc. Also, use `edir` to
465
+ delete or copy files, not just rename them. To add `edir` as a command within
466
+ [`ranger`][ranger], add or create the following in
466
467
  `~/.config/ranger/commands.py`. Then run it from within [`ranger`][ranger] by
467
468
  typing `:edir`.
468
469
 
@@ -485,8 +486,8 @@ class edir(Command):
485
486
  ## Use with Yazi File Manager
486
487
 
487
488
  If you use [`yazi`][yazi] for your file manager then you don't need any special
488
- configuration. Just type `:edir` from within [`yazi`][yazi] to edit all file
489
- names in the current directory.
489
+ configuration. Just type `:edir` from within [`yazi`][yazi] to rename or delete
490
+ or copy file names in the current directory.
490
491
 
491
492
  You can also replace the standard rename function (`r` key) in [`yazi`][yazi]
492
493
  to use `edir` on selected files by adding the following to your
@@ -495,10 +496,14 @@ to use `edir` on selected files by adding the following to your
495
496
  ```toml
496
497
  [[mgr.prepend_keymap]]
497
498
  on = "r"
498
- run = "shell --block -- edir -q %s"
499
+ run = "shell --block -- edir -d0 -q %s"
499
500
  desc = "Run edir on selected files/dirs"
500
501
  ```
501
502
 
503
+ So press `r` on the current selection to rename (or delete or copy) that single
504
+ file name using `edir`. Alternately, select multiple files (or all files with
505
+ the `yazi` standard key binding `Ctrl+a`), before pressing `r`.
506
+
502
507
  ## License
503
508
 
504
509
  Copyright (C) 2019 Mark Blakeney. This program is distributed under the
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: edir
3
- Version: 2.35
3
+ Version: 2.36
4
4
  Summary: Utility to rename, remove, and copy files/dirs using your editor
5
5
  Author-email: Mark Blakeney <mark.blakeney@bullet-systems.net>
6
6
  License-Expression: GPL-3.0-or-later
@@ -230,11 +230,11 @@ following ways:
230
230
 
231
231
  4. Remaining deleted directories are removed.
232
232
 
233
- In simple terms, remember that files are processed before
234
- directories so you can rename files into a different directory and
235
- then delete the original directory, all in one edit. However in
236
- practice it is far **less confusing and less risky** if you perform
237
- complicated renames and moves in distinct steps.
233
+ In simple terms, remember that files are processed before directories so
234
+ you can rename files into a different directory and then delete the
235
+ original directory, all in one edit. However in practice it is far **less
236
+ confusing and less risky** if you perform complicated renames and moves
237
+ across changed directories in distinct steps.
238
238
 
239
239
  ## Renames and Deletes in a GIT Repository
240
240
 
@@ -460,10 +460,10 @@ your defaults.
460
460
  You can use `edir` with [`sudo`][sudo] to rename, delete, or copy system files.
461
461
  For improved convenience and security, `edir` runs the editing session as your
462
462
  regular user, not as root - similar to how [`sudoedit`][sudoedit] works. This
463
- approach allows you to use graphical editors (like VS Code), which should not be
464
- run as root. Use `sudo -E` so that your preferred editor is selected via your
465
- `$EDIR_EDITOR` or `$EDITOR` environment variable. For example, to rename or
466
- delete files in `/etc` using VS Code:
463
+ approach allows you to use graphical editors (like VS Code or Zed etc), which
464
+ normally should not be run as root. Use `sudo -E` so that your preferred editor
465
+ is selected via your `$EDIR_EDITOR` or `$EDITOR` environment variable. For
466
+ example, to rename or delete files in `/etc` using VS Code:
467
467
 
468
468
  ```sh
469
469
  $ export EDIR_EDITOR="code -nw"
@@ -475,8 +475,9 @@ $ sudo -E edir /etc
475
475
  In many ways `edir` (and even `vidir`) is better than the [`ranger`][ranger]
476
476
  terminal file manager
477
477
  [`bulkrename`](https://github.com/ranger/ranger/wiki/Official-user-guide#bulk-renaming)
478
- command which does not handle name swaps and clashes etc. To add `edir` as a
479
- command within [`ranger`][ranger], add or create the following in
478
+ command which does not handle name swaps and clashes etc. Also, use `edir` to
479
+ delete or copy files, not just rename them. To add `edir` as a command within
480
+ [`ranger`][ranger], add or create the following in
480
481
  `~/.config/ranger/commands.py`. Then run it from within [`ranger`][ranger] by
481
482
  typing `:edir`.
482
483
 
@@ -499,8 +500,8 @@ class edir(Command):
499
500
  ## Use with Yazi File Manager
500
501
 
501
502
  If you use [`yazi`][yazi] for your file manager then you don't need any special
502
- configuration. Just type `:edir` from within [`yazi`][yazi] to edit all file
503
- names in the current directory.
503
+ configuration. Just type `:edir` from within [`yazi`][yazi] to rename or delete
504
+ or copy file names in the current directory.
504
505
 
505
506
  You can also replace the standard rename function (`r` key) in [`yazi`][yazi]
506
507
  to use `edir` on selected files by adding the following to your
@@ -509,10 +510,14 @@ to use `edir` on selected files by adding the following to your
509
510
  ```toml
510
511
  [[mgr.prepend_keymap]]
511
512
  on = "r"
512
- run = "shell --block -- edir -q %s"
513
+ run = "shell --block -- edir -d0 -q %s"
513
514
  desc = "Run edir on selected files/dirs"
514
515
  ```
515
516
 
517
+ So press `r` on the current selection to rename (or delete or copy) that single
518
+ file name using `edir`. Alternately, select multiple files (or all files with
519
+ the `yazi` standard key binding `Ctrl+a`), before pressing `r`.
520
+
516
521
  ## License
517
522
 
518
523
  Copyright (C) 2019 Mark Blakeney. This program is distributed under the
@@ -57,6 +57,7 @@ cwd = Path.cwd()
57
57
 
58
58
  EDITORS = {'Windows': 'notepad', 'Darwin': 'open -e', 'default': 'vim'}
59
59
 
60
+
60
61
  def get_default_editor() -> str:
61
62
  "Return default editor for this system"
62
63
  from platform import system
@@ -81,7 +82,7 @@ def make_editor_command(filename: str, sudo_user: str) -> tuple[str, list[str]]:
81
82
  return editor, editcmd
82
83
 
83
84
 
84
- def editfile(editor: str, editcmd: list[str]) -> None:
85
+ def edit_file(editor: str, editcmd: list[str]) -> None:
85
86
  "Run the editor command"
86
87
 
87
88
  # Run the editor ..
@@ -96,6 +97,23 @@ def editfile(editor: str, editcmd: list[str]) -> None:
96
97
  sys.exit(f'ERROR: "{editor}" returned error {res.returncode}')
97
98
 
98
99
 
100
+ def edit_file_conf(conf_file: Path) -> None:
101
+ "Edit the startup options configuration file"
102
+ conf_file.parent.mkdir(parents=True, exist_ok=True)
103
+
104
+ if not conf_file.is_file() or conf_file.stat().st_size == 0:
105
+ conf_file.write_text(
106
+ '# Add your default edir options, one option per line. Comments are ignored.\n'
107
+ )
108
+
109
+ editor = os.getenv('EDITOR') or get_default_editor()
110
+ edit_file(editor, [editor, str(conf_file)])
111
+
112
+ # Remove the edited config file if it is empty
113
+ if conf_file.is_file() and conf_file.stat().st_size == 0:
114
+ conf_file.unlink()
115
+
116
+
99
117
  def log(
100
118
  action: str, msg: str, error: str | None = None, *, prompt: bool = False
101
119
  ) -> None:
@@ -264,6 +282,10 @@ class Fpath:
264
282
 
265
283
  return path
266
284
 
285
+ def changed(self, newpath: Path | None = None) -> bool:
286
+ "Return True if path has been changed"
287
+ return str(newpath or self.newpath) != self.repr
288
+
267
289
  def copy(self, pathdest: Path) -> str | None:
268
290
  "Copy given pathsrc to pathdest"
269
291
  if self.is_dir:
@@ -351,7 +373,7 @@ class Fpath:
351
373
  "Log all pending changes for this path"
352
374
  if not self.newpath:
353
375
  log('remove', f'"{self.diagrepr}"{self.note}', prompt=True)
354
- elif self.newpath != self.path:
376
+ elif self.changed():
355
377
  log(
356
378
  'rename',
357
379
  f'"{self.diagrepr}" to "{self.newpath}{self.appdash}"',
@@ -481,7 +503,7 @@ class Fpath:
481
503
  newpath = Path(pathstr)
482
504
 
483
505
  if path.newpath:
484
- if newpath != path.path and newpath not in path.copies:
506
+ if path.changed(newpath) and newpath not in path.copies:
485
507
  path.copies.append(newpath)
486
508
  else:
487
509
  path.newpath = newpath
@@ -517,13 +539,13 @@ class Fpath:
517
539
  shutil.chown(fpath, sudo_user)
518
540
 
519
541
  # Invoke editor on file containing the list of paths
520
- editfile(editor, editcmd)
542
+ edit_file(editor, editcmd)
521
543
 
522
544
  # Read the changed paths from the file
523
545
  cls.readfile(fpath)
524
546
 
525
547
  # Reduce paths to those that were removed or changed by the user
526
- paths = [p for p in cls.paths if p.path != p.newpath or p.copies]
548
+ paths = [p for p in cls.paths if p.changed() or p.copies]
527
549
 
528
550
  if not paths:
529
551
  return []
@@ -781,20 +803,7 @@ def main() -> int:
781
803
  opt.error('No configuration file path determined.')
782
804
  return 1
783
805
 
784
- conf_file.parent.mkdir(parents=True, exist_ok=True)
785
-
786
- if not conf_file.is_file() or conf_file.stat().st_size == 0:
787
- conf_file.write_text(
788
- '# Add your default edir options, one option per line. Comments are ignored.\n'
789
- )
790
-
791
- editor = os.getenv('EDITOR') or get_default_editor()
792
- editfile(editor, [editor, str(conf_file)])
793
-
794
- # Remove the edited config file if it is empty
795
- if conf_file.is_file() and conf_file.stat().st_size == 0:
796
- conf_file.unlink()
797
-
806
+ edit_file_conf(conf_file)
798
807
  return 0
799
808
 
800
809
  if args.trash:
@@ -869,7 +878,7 @@ def main() -> int:
869
878
  # files.
870
879
  for p in paths:
871
880
  if p.newpath:
872
- if p.newpath != p.path:
881
+ if p.changed():
873
882
  if err := p.rename_temp():
874
883
  log('rename', f'"{p.diagrepr}" to "{p.newpath}{p.appdash}"', err)
875
884
  elif not p.is_dir:
@@ -1,4 +1,4 @@
1
- PYFILES := file_name(justfile_dir()) + '.py'
1
+ PYFILES := file_name(justfile_directory()) + '.py'
2
2
 
3
3
  check:
4
4
  ruff check {{PYFILES}}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes