From bfec31666aa9e61cc869fa6e93a031b53fe47d44 Mon Sep 17 00:00:00 2001 From: Petr Šabata Date: Mon, 10 Feb 2020 19:16:02 +0100 Subject: systemd: refactor and add latest commands (#6250) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Order systemctl commands alphabetically Simplifying the plugin maintenance. Signed-off-by: Petr Šabata * Include the latest systemctl commands Based on systemd-233. I'm still keeping the old, now unsupported commands for backwards compatibility as well. Signed-off-by: Petr Šabata * Add daemon-reload (#3701) Closes #3701 Co-authored-by: Javier Tia --- plugins/systemd/systemd.plugin.zsh | 65 ++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 6 deletions(-) (limited to 'plugins/systemd') diff --git a/plugins/systemd/systemd.plugin.zsh b/plugins/systemd/systemd.plugin.zsh index 7cd27d450..201ffd998 100644 --- a/plugins/systemd/systemd.plugin.zsh +++ b/plugins/systemd/systemd.plugin.zsh @@ -1,12 +1,65 @@ user_commands=( - list-units is-active status show help list-unit-files - is-enabled list-jobs show-environment cat list-timers) + cat + get-default + help + is-active + is-enabled + is-failed + is-system-running + list-dependencies + list-jobs + list-sockets + list-timers + list-unit-files + list-units + show + show-environment + status) 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 - edit) + add-requires + add-wants + cancel + daemon-reexec + daemon-reload + default + disable + edit + emergency + enable + halt + hibernate + hybrid-sleep + import-environment + isolate + kexec + kill + link + list-machines + load + mask + poweroff + preset + preset-all + reboot + reenable + reload + reload-or-restart + reset-failed + rescue + restart + revert + set-default + set-environment + set-property + start + stop + suspend + switch-root + try-reload-or-restart + try-restart + unmask + unset-environment) for c in $user_commands; do; alias sc-$c="systemctl $c"; done for c in $sudo_commands; do; alias sc-$c="sudo systemctl $c"; done -- cgit v1.2.3-70-g09d2 From eeb49bf5b0b8b700713e5b91464003cc09d1b44d Mon Sep 17 00:00:00 2001 From: Sir Mobus Gochfulshigan Dorphin Esquire XXIII Date: Tue, 18 Feb 2020 17:04:14 -0500 Subject: systemd: add prompt function to show systemd units' status (#7657) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marc Cornellà --- plugins/systemd/README.md | 41 ++++++++++++++++++++++++++++++++++++++ plugins/systemd/systemd.plugin.zsh | 15 ++++++++++++++ 2 files changed, 56 insertions(+) (limited to 'plugins/systemd') diff --git a/plugins/systemd/README.md b/plugins/systemd/README.md index d91329290..3fa1d2118 100644 --- a/plugins/systemd/README.md +++ b/plugins/systemd/README.md @@ -51,3 +51,44 @@ plugins=(... systemd) You can use the above aliases as `--user` by using the prefix `scu` instead of `sc`. For example: `scu-list-units` will be aliased to `systemctl --user list-units`. + +### Unit Status Prompt + +You can add a token to your prompt in a similar way to the gitfast plugin. To add the token +to your prompt, drop `$(systemd_prompt_info [unit]...)` into your prompt (more than one unit +may be specified). + +The plugin will add the following to your prompt for each `$unit`. +``` +: +``` +You can control these parts with the following variables: + +- ``: Set `$ZSH_THEME_SYSTEMD_PROMPT_PREFIX`. + +- ``: Set `$ZSH_THEME_SYSTEMD_PROMPT_SUFFIX`. + +- ``: name passed as parameter to the function. If you want it to be in ALL CAPS, + you can set the variable `$ZSH_THEME_SYSTEMD_PROMPT_CAPS` to a non-empty string. + +- ``: shown if the systemd unit is active. + Set `$ZSH_THEME_SYSTEMD_PROMPT_ACTIVE`. + +- ``: shown if the systemd unit is *not* active. + Set `$ZSH_THEME_SYSTEMD_PROMPT_NOTACTIVE`. + +For example, if your prompt contains `PROMPT='$(systemd_prompt_info dhcpd httpd)'` and you set the following variables: + +``` +ZSH_THEME_SYSTEMD_PROMPT_PREFIX="[" +ZSH_THEME_SYSTEMD_PROMPT_SUFFIX="]" +ZSH_THEME_SYSTEMD_PROMPT_ACTIVE="+" +ZSH_THEME_SYSTEMD_PROMPT_NOTACTIVE="X" +ZSH_THEME_SYSTEMD_PROMPT_CAPS=1 +``` + +If `dhcpd` is running, and `httpd` is not, then your prompt will look like this: + +``` +[DHCPD: +][HTTPD: X] +``` diff --git a/plugins/systemd/systemd.plugin.zsh b/plugins/systemd/systemd.plugin.zsh index 201ffd998..f2d1d6f1c 100644 --- a/plugins/systemd/systemd.plugin.zsh +++ b/plugins/systemd/systemd.plugin.zsh @@ -73,3 +73,18 @@ alias sc-mask-now="sc-mask --now" alias scu-enable-now="scu-enable --now" alias scu-disable-now="scu-disable --now" alias scu-mask-now="scu-mask --now" + +function systemd_prompt_info { + local unit + for unit in $@; do + echo -n "$ZSH_THEME_SYSTEMD_PROMPT_PREFIX" + [[ -n "$ZSH_THEME_SYSTEMD_PROMPT_CAPS" ]] && echo "${(U)unit}:" || echo "$unit:" + if systemctl is-active $unit &>/dev/null; then + echo -n "$ZSH_THEME_SYSTEMD_PROMPT_ACTIVE" + else + echo -n "$ZSH_THEME_SYSTEMD_PROMPT_NOTACTIVE" + fi + echo -n "$ZSH_THEME_SYSTEMD_PROMPT_SUFFIX" + done +} + -- cgit v1.2.3-70-g09d2