Back to Ohmyzsh

Systemd plugin

plugins/systemd/README.md

latest6.5 KB
Original Source

Systemd plugin

The systemd plugin provides many useful aliases for systemd.

To use it, add systemd to the plugins array of your zshrc file:

zsh
plugins=(... systemd)

Aliases

AliasCommandDescription
sc-failedsystemctl --failedList failed systemd units
sc-list-unitssystemctl list-unitsList all units systemd has in memory
sc-is-activesystemctl is-activeShow whether a unit is active
sc-statussystemctl statusShow terse runtime status information about one or more units
sc-showsystemctl showShow properties of units, jobs, or the manager itself
sc-helpsystemctl helpShow man page of units
sc-list-unit-filessystemctl list-unit-filesList unit files installed on the system
sc-is-enabledsystemctl is-enabledChecks whether any of the specified unit files are enabled
sc-list-jobssystemctl list-jobsList jobs that are in progress
sc-show-environmentsystemctl show-environmentDump the systemd manager environment block
sc-catsystemctl catShow backing files of one or more units
sc-list-timerssystemctl list-timersList timer units currently in memory
Aliases with sudo
sc-startsudo systemctl startStart Unit(s)
sc-stopsudo systemctl stopStop Unit(s)
sc-reloadsudo systemctl reloadReload Unit(s)
sc-restartsudo systemctl restartRestart Unit(s)
sc-try-restartsudo systemctl try-restartRestart Unit(s)
sc-isolatesudo systemctl isolateStart a unit and its dependencies and stop all others
sc-killsudo systemctl killKill unit(s)
sc-reset-failedsudo systemctl reset-failedReset the "failed" state of the specified units,
sc-enablesudo systemctl enableEnable unit(s)
sc-disablesudo systemctl disableDisable unit(s)
sc-reenablesudo systemctl reenableReenable unit(s)
sc-presetsudo systemctl presetReset the enable/disable status one or more unit files
sc-masksudo systemctl maskMask unit(s)
sc-unmasksudo systemctl unmaskUnmask unit(s)
sc-linksudo systemctl linkLink a unit file into the unit file search path
sc-loadsudo systemctl loadLoad unit(s)
sc-cancelsudo systemctl cancelCancel job(s)
sc-set-environmentsudo systemctl set-environmentSet one or more systemd manager environment variables
sc-unset-environmentsudo systemctl unset-environmentUnset one or more systemd manager environment variables
sc-editsudo systemctl editEdit a drop-in snippet or a whole replacement file with --full
sc-enable-nowsudo systemctl enable --nowEnable and start unit(s)
sc-disable-nowsudo systemctl disable --nowDisable and stop unit(s)
sc-mask-nowsudo systemctl mask --nowMask and stop unit(s)

User aliases

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.

text
<prefix><unit>:<active|notactive><suffix>

You can control these parts with the following variables:

  • <prefix>: Set $ZSH_THEME_SYSTEMD_PROMPT_PREFIX.

  • <suffix>: Set $ZSH_THEME_SYSTEMD_PROMPT_SUFFIX.

  • <unit>: 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.

  • <active>: shown if the systemd unit is active. Set $ZSH_THEME_SYSTEMD_PROMPT_ACTIVE.

  • <notactive>: 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:

sh
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:

text
[DHCPD: +][HTTPD: X]