Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide OMZ-wide option to specify subexecutor such as doas #12245

Open
pepoluan opened this issue Feb 29, 2024 · 2 comments · May be fixed by #12261
Open

Provide OMZ-wide option to specify subexecutor such as doas #12245

pepoluan opened this issue Feb 29, 2024 · 2 comments · May be fixed by #12261
Assignees
Labels
Feature New feature or request

Comments

@pepoluan
Copy link
Contributor

If the feature request is for a plugin or theme, specify it here.

No response

If the feature solves a problem you have, specify it here.

I am using Gentoo Linux, and I don't use sudo for subexecutor. Rather, I use doas

Unfortunately, all plugins that use a subexecutor to do their work, are hardcoded using sudo.

I propose having an OMZ-wide knob that allows plugins to automatically adjust to whatever subexecutor is being used.

Describe the proposed feature.

There are several alternatives:

  1. Define ZSH_SUBEXECUTOR that, by default, is set to sudo. Defining this will allow simple search-and-replace for most plugins to replace sudo with ${ZSH_SUBEXECUTOR}
    For example:

    alias nmap_slow="sudo nmap -sS -v -T1"

    becomes

    alias nmap_slow="${ZSH_SUBEXECUTOR} nmap -sS -v -T1"
  2. Define an OMZ-level zstyle to contain the name of the subexecutor being used, defaults to sudo.
    This will need some code in the plugins. So, to use the above example, will become:

    typeset _SUBEX
    zstyle -s ':omz' 'subexecutor' _SUBEX
    alias nmap_slow="${_SUBEX} nmap -sS -v -T1"
    unset _SUBEX
  3. Define a global OMZ function that adjusts the call to subexecutor automatically. Let's call it subex.
    So the above example becomes:

    alias nmap_slow="subex nmap -sS -v -T1"

    The function may internally be referring to an env var and/or a zstyle knob to provide manual override.

Describe alternatives you've considered

An alternative is to add the following code for all plugins:

# If in the future a new subexecuter is created, we only need to edit this array
typeset _KNOWN_SUBEXES=( "doas" "sudo" )
typeset _SUBEX
for _i in "${_KNOWN_SUBEXES[@]}"; do
  if command -v "$_i" > /dev/null; then
    _subex="$_i"
     break
   fi
done
if [[ -z $_subex ]]; then
  _subex="sudo"
fi
unset _KNOWN_SUBEXES

However, if we add this code to all plugins that define sudo as part of their sets of aliases, that is highly inefficient since the code will be duplicated over all impacted plugins.

Furthermore this code does not provide a way to temporarily override the subexecutor being used.

Additional context

No response

Related Issues

This is tangentially related to this discussion: #11947 , specifically this comment which mentions the doas command.

So if this issue gets solved, the solution will provide partial solution to the challenge discussed, specifically for *BSD users that use the doas command.

@pepoluan pepoluan added the Feature New feature or request label Feb 29, 2024
@pepoluan pepoluan changed the title Provide OMZ-wide option to specify subexecutor Provide OMZ-wide option to specify subexecutor such as doas Feb 29, 2024
@carlosala
Copy link
Member

What do you think about this @mcornella? I'd say it's a good option, it could be a great possibility to make it configurable even to some random script that, for example, asks for confirmation or something like that by any user.
I'd go for this with a zstyle-like config.

@pepoluan pepoluan linked a pull request Mar 6, 2024 that will close this issue
8 tasks
@pepoluan
Copy link
Contributor Author

pepoluan commented Mar 6, 2024

After some consideration, I decided to take the merging of Alternatives 2 & 3, and have submitted PR #12261 implementing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature or request
Projects
Status: Backlog
Development

Successfully merging a pull request may close this issue.

3 participants