edir 2.32__tar.gz → 2.33__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.32
3
+ Version: 2.33
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
@@ -9,7 +9,7 @@ Keywords: vidir,git,trash,trash-put,thrash-d
9
9
  Classifier: Programming Language :: Python :: 3
10
10
  Requires-Python: >=3.8
11
11
  Description-Content-Type: text/markdown
12
- Requires-Dist: platformdirs
12
+ Requires-Dist: argparse-from-file
13
13
 
14
14
  ## EDIR - Rename, Remove, and Copy Files and Directories Using Your Editor
15
15
  [![PyPi](https://img.shields.io/pypi/v/edir)](https://pypi.org/project/edir/)
@@ -383,8 +383,11 @@ usage: edir [-h] [-i] [-I] [-a] [-A] [-r] [-R] [-q] [-Q] [-G] [-g] [-t]
383
383
  [-V]
384
384
  [args ...]
385
385
 
386
- Program to rename, remove, or copy files and directories using your editor.
387
- Will use git to action the rename and remove if run within a git repository.
386
+ Command line utility to rename, remove, or copy files and directories directly
387
+ from your editor. When run, you'll see a numbered list of files in your
388
+ editor. Delete a line to remove a file, modify a line to rename a file, or
389
+ duplicate a line to copy a file. Swap line numbers to swap file names. If
390
+ inside a git repository, git will be used for renames and removals.
388
391
 
389
392
  positional arguments:
390
393
  args file|dir, or "-" for stdin
@@ -435,15 +438,15 @@ temporarily override your defaults.
435
438
 
436
439
  You can use `edir` with `sudo` to rename, delete, or copy system files. For
437
440
  improved security, `edir` runs the editing session as your regular user, not as
438
- root - similar to how `sudoedit` works. This approach allows you to use graphical
439
- editors (like VS Code), which should not be run as root. To ensure your editor
440
- settings are preserved, use `sudo -E` so that your `$EDIR_EDITOR` or `$EDITOR`
441
- environment variable is available. For example, to edit files in `/etc` with VS
441
+ root - similar to how `sudoedit` works. This approach allows you to use
442
+ graphical editors (like VS Code), which should not be run as root. Use `sudo -E`
443
+ so that your preferred editor is selected via your `$EDIR_EDITOR` or `$EDITOR`
444
+ environment variable. For example, to rename or delete files in `/etc` using VS
442
445
  Code:
443
446
 
444
447
  ```sh
445
- export EDIR_EDITOR="code -w"
446
- sudo -E edir /etc
448
+ $ export EDIR_EDITOR="code -w"
449
+ $ sudo -E edir /etc
447
450
  ```
448
451
 
449
452
  ## Embed in Ranger File Manager
@@ -370,8 +370,11 @@ usage: edir [-h] [-i] [-I] [-a] [-A] [-r] [-R] [-q] [-Q] [-G] [-g] [-t]
370
370
  [-V]
371
371
  [args ...]
372
372
 
373
- Program to rename, remove, or copy files and directories using your editor.
374
- Will use git to action the rename and remove if run within a git repository.
373
+ Command line utility to rename, remove, or copy files and directories directly
374
+ from your editor. When run, you'll see a numbered list of files in your
375
+ editor. Delete a line to remove a file, modify a line to rename a file, or
376
+ duplicate a line to copy a file. Swap line numbers to swap file names. If
377
+ inside a git repository, git will be used for renames and removals.
375
378
 
376
379
  positional arguments:
377
380
  args file|dir, or "-" for stdin
@@ -422,15 +425,15 @@ temporarily override your defaults.
422
425
 
423
426
  You can use `edir` with `sudo` to rename, delete, or copy system files. For
424
427
  improved security, `edir` runs the editing session as your regular user, not as
425
- root - similar to how `sudoedit` works. This approach allows you to use graphical
426
- editors (like VS Code), which should not be run as root. To ensure your editor
427
- settings are preserved, use `sudo -E` so that your `$EDIR_EDITOR` or `$EDITOR`
428
- environment variable is available. For example, to edit files in `/etc` with VS
428
+ root - similar to how `sudoedit` works. This approach allows you to use
429
+ graphical editors (like VS Code), which should not be run as root. Use `sudo -E`
430
+ so that your preferred editor is selected via your `$EDIR_EDITOR` or `$EDITOR`
431
+ environment variable. For example, to rename or delete files in `/etc` using VS
429
432
  Code:
430
433
 
431
434
  ```sh
432
- export EDIR_EDITOR="code -w"
433
- sudo -E edir /etc
435
+ $ export EDIR_EDITOR="code -w"
436
+ $ sudo -E edir /etc
434
437
  ```
435
438
 
436
439
  ## Embed in Ranger File Manager
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: edir
3
- Version: 2.32
3
+ Version: 2.33
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
@@ -9,7 +9,7 @@ Keywords: vidir,git,trash,trash-put,thrash-d
9
9
  Classifier: Programming Language :: Python :: 3
10
10
  Requires-Python: >=3.8
11
11
  Description-Content-Type: text/markdown
12
- Requires-Dist: platformdirs
12
+ Requires-Dist: argparse-from-file
13
13
 
14
14
  ## EDIR - Rename, Remove, and Copy Files and Directories Using Your Editor
15
15
  [![PyPi](https://img.shields.io/pypi/v/edir)](https://pypi.org/project/edir/)
@@ -383,8 +383,11 @@ usage: edir [-h] [-i] [-I] [-a] [-A] [-r] [-R] [-q] [-Q] [-G] [-g] [-t]
383
383
  [-V]
384
384
  [args ...]
385
385
 
386
- Program to rename, remove, or copy files and directories using your editor.
387
- Will use git to action the rename and remove if run within a git repository.
386
+ Command line utility to rename, remove, or copy files and directories directly
387
+ from your editor. When run, you'll see a numbered list of files in your
388
+ editor. Delete a line to remove a file, modify a line to rename a file, or
389
+ duplicate a line to copy a file. Swap line numbers to swap file names. If
390
+ inside a git repository, git will be used for renames and removals.
388
391
 
389
392
  positional arguments:
390
393
  args file|dir, or "-" for stdin
@@ -435,15 +438,15 @@ temporarily override your defaults.
435
438
 
436
439
  You can use `edir` with `sudo` to rename, delete, or copy system files. For
437
440
  improved security, `edir` runs the editing session as your regular user, not as
438
- root - similar to how `sudoedit` works. This approach allows you to use graphical
439
- editors (like VS Code), which should not be run as root. To ensure your editor
440
- settings are preserved, use `sudo -E` so that your `$EDIR_EDITOR` or `$EDITOR`
441
- environment variable is available. For example, to edit files in `/etc` with VS
441
+ root - similar to how `sudoedit` works. This approach allows you to use
442
+ graphical editors (like VS Code), which should not be run as root. Use `sudo -E`
443
+ so that your preferred editor is selected via your `$EDIR_EDITOR` or `$EDITOR`
444
+ environment variable. For example, to rename or delete files in `/etc` using VS
442
445
  Code:
443
446
 
444
447
  ```sh
445
- export EDIR_EDITOR="code -w"
446
- sudo -E edir /etc
448
+ $ export EDIR_EDITOR="code -w"
449
+ $ sudo -E edir /etc
447
450
  ```
448
451
 
449
452
  ## Embed in Ranger File Manager
@@ -0,0 +1 @@
1
+ argparse-from-file
@@ -1,17 +1,18 @@
1
1
  #!/usr/bin/env python3
2
2
  """
3
- Program to rename, remove, or copy files and directories using your
4
- editor. Will use git to action the rename and remove if run within a git
5
- repository.
3
+ Command line utility to rename, remove, or copy files and directories directly
4
+ from your editor. When run, you'll see a numbered list of files in your editor.
5
+ Delete a line to remove a file, modify a line to rename a file, or duplicate a
6
+ line to copy a file. Swap line numbers to swap file names. If inside a git
7
+ repository, git will be used for renames and removals.
6
8
  """
7
9
 
8
10
  # Author: Mark Blakeney, May 2019.
9
11
  from __future__ import annotations
10
12
 
11
- import argparse
13
+ import argparse_from_file as argparse
12
14
  import itertools
13
15
  import os
14
- import re
15
16
  import shlex
16
17
  import shutil
17
18
  import subprocess
@@ -20,11 +21,8 @@ import tempfile
20
21
  from collections.abc import Callable, Iterable, Sequence
21
22
  from pathlib import Path
22
23
 
23
- from platformdirs import user_config_path
24
-
25
24
  # Some constants
26
25
  PROG = Path(sys.argv[0]).stem
27
- CNFFILE = user_config_path() / f'{PROG}-flags.conf'
28
26
  EDITOR = PROG.upper() + '_EDITOR'
29
27
  SUFFIX = '.sh'
30
28
  SEP = os.sep
@@ -65,8 +63,10 @@ def get_default_editor() -> str:
65
63
  return EDITORS.get(system(), EDITORS['default'])
66
64
 
67
65
 
68
- def editfile(filename: Path, sudo_user: str) -> None:
69
- "Run the editor command"
66
+ def make_editor_command(filename: str, sudo_user: str) -> tuple[str, list[str]]:
67
+ "Create the edit command"
68
+ editcmd = ['runuser', '-u', sudo_user, '--'] if sudo_user else []
69
+
70
70
  # Use explicit user defined editor or choose system default
71
71
  editor = (
72
72
  os.getenv(EDITOR)
@@ -74,10 +74,14 @@ def editfile(filename: Path, sudo_user: str) -> None:
74
74
  or os.getenv('EDITOR')
75
75
  or get_default_editor()
76
76
  )
77
- editcmd = shlex.split(editor) + [str(filename)]
78
77
 
79
- if sudo_user:
80
- editcmd = ['runuser', '-u', sudo_user, '--'] + editcmd
78
+ editcmd.extend(shlex.split(editor))
79
+ editcmd.append(filename)
80
+ return editor, editcmd
81
+
82
+
83
+ def editfile(editor: str, editcmd: list[str]) -> None:
84
+ "Run the editor command"
81
85
 
82
86
  # Run the editor ..
83
87
  if sys.stdin.isatty():
@@ -88,7 +92,7 @@ def editfile(filename: Path, sudo_user: str) -> None:
88
92
 
89
93
  # Check if editor returned error
90
94
  if res.returncode != 0:
91
- sys.exit(f'ERROR: {editor} returned error {res.returncode}')
95
+ sys.exit(f'ERROR: "{editor}" returned error {res.returncode}')
92
96
 
93
97
 
94
98
  def log(
@@ -454,6 +458,10 @@ class Fpath:
454
458
 
455
459
  # Create a temp file for the user to edit then read the lines back
456
460
  fpath = Path(fdir, f'{PROG}{args.suffix}')
461
+
462
+ # Get the editor and editor command
463
+ editor, editcmd = make_editor_command(str(fpath), sudo_user)
464
+
457
465
  restart = True
458
466
  while True:
459
467
  if restart:
@@ -463,10 +471,10 @@ class Fpath:
463
471
  if sudo_user:
464
472
  shutil.chown(fpath, sudo_user)
465
473
 
466
- # Invoke editor on list of paths
467
- editfile(fpath, sudo_user)
474
+ # Invoke editor on file containing the list of paths
475
+ editfile(editor, editcmd)
468
476
 
469
- # Read the changed paths
477
+ # Read the changed paths from the file
470
478
  cls.readfile(fpath)
471
479
 
472
480
  # Reduce paths to those that were removed or changed by the user
@@ -513,7 +521,7 @@ def main() -> int:
513
521
  opt = argparse.ArgumentParser(
514
522
  description=__doc__,
515
523
  epilog='Note you can set default starting options in '
516
- f'{CNFFILE}. The negation options (i.e. the --no-* options) '
524
+ '#FROM_FILE_PATH#. The negation options (i.e. the --no-* options) '
517
525
  'allow you to temporarily override your defaults.',
518
526
  )
519
527
  opt.add_argument(
@@ -685,16 +693,7 @@ def main() -> int:
685
693
  )
686
694
  opt.add_argument('args', nargs='*', help='file|dir, or "-" for stdin')
687
695
 
688
- # Merge in default args from user config file. Then parse the
689
- # command line.
690
- if CNFFILE.exists():
691
- with CNFFILE.open() as fp:
692
- lines = [re.sub(r'#.*$', '', line).strip() for line in fp]
693
- cnflines = ' '.join(lines).strip()
694
- else:
695
- cnflines = ''
696
-
697
- args = opt.parse_args(shlex.split(cnflines) + sys.argv[1:])
696
+ args = opt.parse_args()
698
697
 
699
698
  if args.version:
700
699
  from importlib.metadata import version
@@ -14,7 +14,7 @@ classifiers = [
14
14
  ]
15
15
  dynamic = ["version"]
16
16
  dependencies = [
17
- "platformdirs",
17
+ "argparse-from-file",
18
18
  ]
19
19
 
20
20
  [[project.authors]]
@@ -1 +0,0 @@
1
- platformdirs
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes