Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
eeb49bf5
Unverified
Commit
eeb49bf5
authored
Feb 18, 2020
by
Sir Mobus Gochfulshigan Dorphin Esquire XXIII
Committed by
GitHub
Feb 18, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
systemd: add prompt function to show systemd units' status (#7657)
Co-authored-by:
Marc Cornellà
<
marc.cornella@live.com
>
parent
de261bd2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
0 deletions
+56
-0
README.md
plugins/systemd/README.md
+41
-0
systemd.plugin.zsh
plugins/systemd/systemd.plugin.zsh
+15
-0
No files found.
plugins/systemd/README.md
View file @
eeb49bf5
...
...
@@ -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`
.
```
<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:
```
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]
```
plugins/systemd/systemd.plugin.zsh
View file @
eeb49bf5
...
...
@@ -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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment