Parent directory

systemd.plugin.zsh

2078 bytes
  1# systemctl aliases
  2user_commands=(
  3  cat
  4  get-default
  5  help
  6  is-active
  7  is-enabled
  8  is-failed
  9  is-system-running
 10  list-dependencies
 11  list-jobs
 12  list-sockets
 13  list-timers
 14  list-unit-files
 15  list-units
 16  show
 17  show-environment
 18  status
 19)
 20
 21sudo_commands=(
 22  add-requires
 23  add-wants
 24  cancel
 25  daemon-reexec
 26  daemon-reload
 27  default
 28  disable
 29  edit
 30  emergency
 31  enable
 32  halt
 33  import-environment
 34  isolate
 35  kexec
 36  kill
 37  link
 38  list-machines
 39  load
 40  mask
 41  preset
 42  preset-all
 43  reenable
 44  reload
 45  reload-or-restart
 46  reset-failed
 47  rescue
 48  restart
 49  revert
 50  set-default
 51  set-environment
 52  set-property
 53  start
 54  stop
 55  switch-root
 56  try-reload-or-restart
 57  try-restart
 58  unmask
 59  unset-environment
 60)
 61
 62power_commands=(
 63  hibernate
 64  hybrid-sleep
 65  poweroff
 66  reboot
 67  suspend
 68)
 69
 70for c in $user_commands; do
 71  alias "sc-$c"="systemctl $c"
 72  alias "scu-$c"="systemctl --user $c"
 73done
 74
 75for c in $sudo_commands; do
 76  alias "sc-$c"="sudo systemctl $c"
 77  alias "scu-$c"="systemctl --user $c"
 78done
 79
 80for c in $power_commands; do
 81  alias "sc-$c"="systemctl $c"
 82done
 83
 84unset c user_commands sudo_commands power_commands
 85
 86
 87# --now commands
 88alias sc-enable-now="sc-enable --now"
 89alias sc-disable-now="sc-disable --now"
 90alias sc-mask-now="sc-mask --now"
 91
 92alias scu-enable-now="scu-enable --now"
 93alias scu-disable-now="scu-disable --now"
 94alias scu-mask-now="scu-mask --now"
 95
 96# --failed commands
 97alias scu-failed='systemctl --user --failed'
 98alias sc-failed='systemctl --failed'
 99
100function systemd_prompt_info {
101  local unit
102  for unit in "$@"; do
103    echo -n "$ZSH_THEME_SYSTEMD_PROMPT_PREFIX"
104
105    if [[ -n "$ZSH_THEME_SYSTEMD_PROMPT_CAPS" ]]; then
106      echo -n "${(U)unit:gs/%/%%}:"
107    else
108      echo -n "${unit:gs/%/%%}:"
109    fi
110
111    if systemctl is-active "$unit" &>/dev/null; then
112      echo -n "$ZSH_THEME_SYSTEMD_PROMPT_ACTIVE"
113    elif systemctl --user is-active "$unit" &>/dev/null; then
114      echo -n "$ZSH_THEME_SYSTEMD_PROMPT_ACTIVE"
115    else
116      echo -n "$ZSH_THEME_SYSTEMD_PROMPT_NOTACTIVE"
117    fi
118
119    echo -n "$ZSH_THEME_SYSTEMD_PROMPT_SUFFIX"
120  done
121}