mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-03-20 03:13:33 +01:00
Problem: The systemd plugin requires sudo to be installed. The plugin set-up aliases sc-* for each systemctl command, and prefix the alias with sudo so they can be used from non-root account. However, this doesn't work if "sudo" is not installed. Solution: Do not prefix the alias with "sudo" when they are created for the root account. This doesn't change anything for non-root user, but allows root user to use the plugin even when sudo is not available on the machine.
16 lines
562 B
Bash
16 lines
562 B
Bash
user_commands=(
|
|
list-units is-active status show help list-unit-files
|
|
is-enabled list-jobs show-environment)
|
|
|
|
sudo_commands=(
|
|
start stop reload restart try-restart isolate kill
|
|
reset-failed enable disable reenable preset mask unmask
|
|
link load cancel set-environment unset-environment)
|
|
|
|
for c in $user_commands; do; alias sc-$c="systemctl $c"; done
|
|
# Do not use sudo for root user
|
|
if [ "`id -u`" = "0" ]; then
|
|
for c in $sudo_commands; do; alias sc-$c="systemctl $c"; done
|
|
else
|
|
for c in $sudo_commands; do; alias sc-$c="sudo systemctl $c"; done
|
|
fi
|