zsh 的systemctl 智能补齐脚本

oh-my-zsh 没有systemctl的智能不全插件。自己照着docker的插件写了一个。记录一下。


#compdef systemctl


# Systemctl autocompletion for oh-my-zsh
# Requires: Systemd installed
# Author: Hpc




# ----- Commands
# Seperate function for each command, makes extension easier later
# ---------------------------


__systemd_services() {
    declare -a cont_cmd
    cont_cmd=($(ls -R /usr/lib/systemd/system/  | grep -v '/'))
    if [[  'X$cont_cmd' != 'X' ]]
        _describe 'systemctl' cont_cmd
}


__restart() {
    __systemd_services
}


__start() {
    __systemd_services
}


__status() {
    __systemd_services
}


__daemon-reload() {
    __systemd_services
}
__stop() {
    __systemd_services
}


# end commands ---------
# ----------------------


local -a _1st_arguments
_1st_arguments=(
    "restart":"Restart a running service"
    "start":"Start a stopped service"
    "status":"Display service status"
    "stop":"Stop a running service"
    "daemon_reload":"reload the service"
)


_arguments '*:: :->command'


if (( CURRENT == 1 )); then
    _describe -t commands "docker command" _1st_arguments
    return
fi


local -a _command_args
case "$words[1]" in
    restart)
        __restart ;;
    status)
        __status ;;
    start)
        __start ;;
    stop)
        __stop ;;
    daemon_reload)
        __daemon-reload ;;
esac


你可能感兴趣的:(zsh 的systemctl 智能补齐脚本)