2
0

systemd.plugin.zsh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. # systemctl aliases
  2. user_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. sudo_commands=(
  21. add-requires
  22. add-wants
  23. cancel
  24. daemon-reexec
  25. daemon-reload
  26. default
  27. disable
  28. edit
  29. emergency
  30. enable
  31. halt
  32. import-environment
  33. isolate
  34. kexec
  35. kill
  36. link
  37. list-machines
  38. load
  39. mask
  40. preset
  41. preset-all
  42. reenable
  43. reload
  44. reload-or-restart
  45. reset-failed
  46. rescue
  47. restart
  48. revert
  49. set-default
  50. set-environment
  51. set-property
  52. start
  53. stop
  54. switch-root
  55. try-reload-or-restart
  56. try-restart
  57. unmask
  58. unset-environment
  59. )
  60. power_commands=(
  61. hibernate
  62. hybrid-sleep
  63. poweroff
  64. reboot
  65. suspend
  66. )
  67. for c in $user_commands; do
  68. alias "sc-$c"="systemctl $c"
  69. alias "scu-$c"="systemctl --user $c"
  70. done
  71. for c in $sudo_commands; do
  72. alias "sc-$c"="sudo systemctl $c"
  73. alias "scu-$c"="systemctl --user $c"
  74. done
  75. for c in $power_commands; do
  76. alias "sc-$c"="systemctl $c"
  77. done
  78. unset c user_commands sudo_commands power_commands
  79. # --now commands
  80. alias sc-enable-now="sc-enable --now"
  81. alias sc-disable-now="sc-disable --now"
  82. alias sc-mask-now="sc-mask --now"
  83. alias scu-enable-now="scu-enable --now"
  84. alias scu-disable-now="scu-disable --now"
  85. alias scu-mask-now="scu-mask --now"
  86. # --failed commands
  87. alias scu-failed='systemctl --user --failed'
  88. alias sc-failed='systemctl --failed'
  89. function systemd_prompt_info {
  90. local unit
  91. for unit in "$@"; do
  92. echo -n "$ZSH_THEME_SYSTEMD_PROMPT_PREFIX"
  93. if [[ -n "$ZSH_THEME_SYSTEMD_PROMPT_CAPS" ]]; then
  94. echo -n "${(U)unit:gs/%/%%}:"
  95. else
  96. echo -n "${unit:gs/%/%%}:"
  97. fi
  98. if systemctl is-active "$unit" &>/dev/null; then
  99. echo -n "$ZSH_THEME_SYSTEMD_PROMPT_ACTIVE"
  100. elif systemctl --user is-active "$unit" &>/dev/null; then
  101. echo -n "$ZSH_THEME_SYSTEMD_PROMPT_ACTIVE"
  102. else
  103. echo -n "$ZSH_THEME_SYSTEMD_PROMPT_NOTACTIVE"
  104. fi
  105. echo -n "$ZSH_THEME_SYSTEMD_PROMPT_SUFFIX"
  106. done
  107. }