5b2f99bcb7186bfb11b91a8686d750af95e41eff

Author
scrouthtv <lennivh24@gmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

fix(systemd): remove `sudo` from power-related aliases (#9441)

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/systemd/README.md b/plugins/systemd/README.md
  2index 3fa1d21183faf9bb1aba9f9b7dfc76311675c20e..ffa0567a853f683930e069a931fe835f7ea5609a 100644
  3--- a/plugins/systemd/README.md
  4+++ b/plugins/systemd/README.md
  5@@ -3,7 +3,8 @@
  6 The systemd plugin provides many useful aliases for systemd.
  7 
  8 To use it, add systemd to the plugins array of your zshrc file:
  9-```
 10+
 11+```zsh
 12 plugins=(... systemd)
 13 ```
 14 
 15@@ -22,7 +23,7 @@ plugins=(... systemd)
 16 | `sc-show-environment`  | `systemctl show-environment`       | Dump the systemd manager environment block                       |
 17 | `sc-cat`               | `systemctl cat`                    | Show backing files of one or more units                          |
 18 | `sc-list-timers`       | `systemctl list-timers`            | List timer units currently in memory                             |
 19-| **Aliases with sudo**                                                                                                          |
 20+| **Aliases with sudo**                                                                                                        |||
 21 | `sc-start`             | `sudo systemctl start`             | Start Unit(s)                                                    |
 22 | `sc-stop`              | `sudo systemctl stop`              | Stop Unit(s)                                                     |
 23 | `sc-reload`            | `sudo systemctl reload`            | Reload Unit(s)                                                   |
 24@@ -59,9 +60,11 @@ to your prompt, drop `$(systemd_prompt_info [unit]...)` into your prompt (more t
 25 may be specified).
 26 
 27 The plugin will add the following to your prompt for each `$unit`.
 28-```
 29+
 30+```text
 31 <prefix><unit>:<active|notactive><suffix>
 32 ```
 33+
 34 You can control these parts with the following variables:
 35 
 36 - `<prefix>`: Set `$ZSH_THEME_SYSTEMD_PROMPT_PREFIX`.
 37@@ -79,7 +82,7 @@ You can control these parts with the following variables:
 38 
 39 For example, if your prompt contains `PROMPT='$(systemd_prompt_info dhcpd httpd)'` and you set the following variables:
 40 
 41-```
 42+```sh
 43 ZSH_THEME_SYSTEMD_PROMPT_PREFIX="["
 44 ZSH_THEME_SYSTEMD_PROMPT_SUFFIX="]"
 45 ZSH_THEME_SYSTEMD_PROMPT_ACTIVE="+"
 46@@ -89,6 +92,6 @@ ZSH_THEME_SYSTEMD_PROMPT_CAPS=1
 47 
 48 If `dhcpd` is running, and `httpd` is not, then your prompt will look like this:
 49 
 50-```
 51+```text
 52 [DHCPD: +][HTTPD: X]
 53 ```
 54diff --git a/plugins/systemd/systemd.plugin.zsh b/plugins/systemd/systemd.plugin.zsh
 55index c6fd52990df9eae1213b7fff3235ad4d68914208..e9ac6438263fbd5eb88880b93ff5a867c7412b66 100644
 56--- a/plugins/systemd/systemd.plugin.zsh
 57+++ b/plugins/systemd/systemd.plugin.zsh
 58@@ -1,3 +1,4 @@
 59+# systemctl aliases
 60 user_commands=(
 61   cat
 62   get-default
 63@@ -14,7 +15,8 @@ user_commands=(
 64   list-units
 65   show
 66   show-environment
 67-  status)
 68+  status
 69+)
 70 
 71 sudo_commands=(
 72   add-requires
 73@@ -28,8 +30,6 @@ sudo_commands=(
 74   emergency
 75   enable
 76   halt
 77-  hibernate
 78-  hybrid-sleep
 79   import-environment
 80   isolate
 81   kexec
 82@@ -38,34 +38,53 @@ sudo_commands=(
 83   list-machines
 84   load
 85   mask
 86-  poweroff
 87   preset
 88   preset-all
 89-  reboot
 90   reenable
 91   reload
 92   reload-or-restart
 93   reset-failed
 94   rescue
 95-  restart
 96   revert
 97   set-default
 98   set-environment
 99   set-property
100   start
101   stop
102-  suspend
103   switch-root
104   try-reload-or-restart
105   try-restart
106   unmask
107-  unset-environment)
108+  unset-environment
109+)
110+
111+power_commands=(
112+  hibernate
113+  hybrid-sleep
114+  poweroff
115+  reboot
116+  restart
117+  suspend
118+)
119+
120+for c in $user_commands; do
121+  alias "sc-$c"="systemctl $c"
122+  alias "scu-$c"="systemctl --user $c"
123+done
124+
125+for c in $sudo_commands; do
126+  alias "sc-$c"="sudo systemctl $c"
127+  alias "scu-$c"="systemctl --user $c"
128+done
129 
130-for c in $user_commands; do; alias sc-$c="systemctl $c"; done
131-for c in $sudo_commands; do; alias sc-$c="sudo systemctl $c"; done
132-for c in $user_commands; do; alias scu-$c="systemctl --user $c"; done
133-for c in $sudo_commands; do; alias scu-$c="systemctl --user $c"; done
134+for c in $power_commands; do
135+  alias "sc-$c"="systemctl $c"
136+done
137 
138+unset c user_commands sudo_commands power_commands
139+
140+
141+# --now commands
142 alias sc-enable-now="sc-enable --now"
143 alias sc-disable-now="sc-disable --now"
144 alias sc-mask-now="sc-mask --now"
145@@ -74,17 +93,24 @@ alias scu-enable-now="scu-enable --now"
146 alias scu-disable-now="scu-disable --now"
147 alias scu-mask-now="scu-mask --now"
148 
149+
150 function systemd_prompt_info {
151   local unit
152-  for unit in $@; do
153+  for unit in "$@"; do
154     echo -n "$ZSH_THEME_SYSTEMD_PROMPT_PREFIX"
155-    [[ -n "$ZSH_THEME_SYSTEMD_PROMPT_CAPS" ]] && echo -n "${(U)unit}:" || echo -n "$unit:"
156-    if systemctl is-active $unit &>/dev/null; then
157-        echo -n "$ZSH_THEME_SYSTEMD_PROMPT_ACTIVE"