mirror of
https://github.com/robbyrussell/oh-my-zsh.git
synced 2026-11-26 18:33:03 +01:00
feat(systemd): support other privilege elevation tools (#13695)
This commit is contained in:
1 parent
4d643a3c86
commit
0876f10264
2 files changed
+39
-6
No files matched your search
@@ -24,7 +24,7 @@ plugins=(... systemd)
|
||||
| `sc-show-environment` | `systemctl show-environment` | Dump the systemd manager environment block |
|
||||
| `sc-cat` | `systemctl cat` | Show backing files of one or more units |
|
||||
| `sc-list-timers` | `systemctl list-timers` | List timer units currently in memory |
|
||||
| **Aliases with sudo** |||
|
||||
| **Privileged aliases** |||
|
||||
| `sc-start` | `sudo systemctl start` | Start Unit(s) |
|
||||
| `sc-stop` | `sudo systemctl stop` | Stop Unit(s) |
|
||||
| `sc-reload` | `sudo systemctl reload` | Reload Unit(s) |
|
||||
@@ -50,6 +50,28 @@ plugins=(... systemd)
|
||||
| `sc-disable-now` | `sudo systemctl disable --now` | Disable and stop unit(s) |
|
||||
| `sc-mask-now` | `sudo systemctl mask --now` | Mask and stop unit(s) |
|
||||
|
||||
### Privileged aliases
|
||||
|
||||
systemd plugin supports alternative privilege elevation tools. You can prepend an arbitrary string,
|
||||
replacing `sudo`, to the privileged aliases by setting `$ZSH_SYSTEMD_SUDO` variable. You can leave
|
||||
authorization to systemd by setting `$ZSH_SYSTEMD_SUDO` to an empty string.
|
||||
|
||||
To use `doas` as your elevation tool you will need to add the following line to your zshrc;
|
||||
|
||||
```zsh
|
||||
ZSH_SYSTEMD_SUDO="doas"
|
||||
```
|
||||
|
||||
After shell restart, you will see that alias for `sc-enable` is changed:
|
||||
|
||||
```sh
|
||||
$ which sc-enable
|
||||
sc-enable: aliased to doas systemctl enable
|
||||
```
|
||||
|
||||
These aliases are evaluated during oh-my-zsh startup, and can't be changed interactively (you will
|
||||
need to restart shell to see changes).
|
||||
|
||||
### User aliases
|
||||
|
||||
You can use the above aliases as `--user` by using the prefix `scu` instead of `sc`.
|
||||
|
||||
@@ -67,15 +67,27 @@ power_commands=(
|
||||
suspend
|
||||
)
|
||||
|
||||
if ! [[ -v ZSH_SYSTEMD_SUDO ]]; then
|
||||
ZSH_SYSTEMD_SUDO="sudo"
|
||||
fi
|
||||
|
||||
for c in $user_commands; do
|
||||
alias "sc-$c"="systemctl $c"
|
||||
alias "scu-$c"="systemctl --user $c"
|
||||
done
|
||||
|
||||
for c in $sudo_commands; do
|
||||
alias "sc-$c"="sudo systemctl $c"
|
||||
alias "scu-$c"="systemctl --user $c"
|
||||
done
|
||||
# Avoids leading space in alias when using polkit
|
||||
if [[ -n "${ZSH_SYSTEMD_SUDO}" ]]; then
|
||||
for c in $sudo_commands; do
|
||||
alias "sc-$c"="$ZSH_SYSTEMD_SUDO systemctl $c"
|
||||
alias "scu-$c"="systemctl --user $c"
|
||||
done
|
||||
else
|
||||
for c in $sudo_commands; do
|
||||
alias "sc-$c"="systemctl $c"
|
||||
alias "scu-$c"="systemctl --user $c"
|
||||
done
|
||||
fi
|
||||
|
||||
for c in $power_commands; do
|
||||
alias "sc-$c"="systemctl $c"
|
||||
@@ -83,7 +95,6 @@ done
|
||||
|
||||
unset c user_commands sudo_commands power_commands
|
||||
|
||||
|
||||
# --now commands
|
||||
alias sc-enable-now="sc-enable --now"
|
||||
alias sc-disable-now="sc-disable --now"
|
||||
|
||||
Reference in new issue
Block a user