Skip to content

Conversation

@fwam
Copy link
Contributor

@fwam fwam commented Nov 2, 2025

ISSUE TYPE

  • Improvement/feature implementation

CHECKLIST

  • The CONTRIBUTING document has been read [REQUIRED]
  • All changes follow the code style [REQUIRED]
  • All new and existing tests pass [REQUIRED]
  • Changes require config files to be updated
    • Config files have been updated
  • Changes require documentation to be updated
    • Documentation has been updated
  • Changes require tests to be updated
    • Tests have been updated

DESCRIPTION

Add support for doas and run0 in -r flag (no support for f flag yet.)

MOTIVATION AND CONTEXT

Hard-coded sudo might cause problems on systems where sudo isn't installed.

TESTING

IMAGES / VIDEOS

@fwam fwam force-pushed the r-flag-feat branch 5 times, most recently from b8ce4f4 to 07437d2 Compare November 2, 2025 01:03
root_command = None
for tested_command in root_commands:
if tested_command not in get_executables():
continue
Copy link
Contributor

@belkka belkka Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for x in seq:
   if not condition:
      continue
   else:
      # do smth

Could it be simplified, avoiding one of if branches and continue?

for x in seq:
   if condition:
      # do smth

BTW, an alternative way to reach the same result in a single assignment, instead of nested for + if:

root_command = next(
   (cmd for cmd in root_commands if cmd in get_executables()),
   None,
)

generator expression is used to filter out elements, and
built-in next() is used to select first element of sequence, or None if empty

Just sharing a thought, it's up to personal taste whether to use this or for: if:

else:
action = ['sudo'] + (f_flag and ['-b'] or []) + action
# TODO: 'f' flag for doas/run0
match(root_command):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: match statements are added in Python 3.10

AFAIK (based on setup.py content), ranger is supporting Python 3.1 and even 2.7 😞

if isinstance(action, str):
action = 'sudo ' + (f_flag and '-b ' or '') + action
else:
action = ['sudo'] + (f_flag and ['-b'] or []) + action
Copy link
Contributor

@belkka belkka Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch (I assume, for when action is a list) has no correspondence in the new code. In the new code action is unconditionally treated as a str (concatenated with other strings).

Was this if branch unreachable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants