Skip to content

Commit

Permalink
chore: add zsh completion script
Browse files Browse the repository at this point in the history
add zsh completion script

Log: add zsh completion script
  • Loading branch information
wangfei authored and FeiWang1119 committed Jan 24, 2024
1 parent c0aafe9 commit 97df47d
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 20 deletions.
7 changes: 5 additions & 2 deletions dconfig-center/dde-dconfig/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,8 @@ target_include_directories(${PROJECT_NAME} PUBLIC
install(TARGETS dde-dconfig DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES ${QM_FILES} DESTINATION ${CMAKE_INSTALL_DATADIR}/dde-dconfig/translations/)

set(BASH_COMPLETION_COMPLETIONSDIR ${CMAKE_INSTALL_DATADIR}/bash-completion/completions/)
install(DIRECTORY bash_completion.d/ DESTINATION ${BASH_COMPLETION_COMPLETIONSDIR})
set(BASH_COMPLETION_COMPLETIONS ${CMAKE_INSTALL_DATADIR}/bash-completion/completions/)
install(FILES ./completion/dde-dconfig.bash DESTINATION ${BASH_COMPLETION_COMPLETIONS} RENAME dde-dconfig)

set(ZSH_COMPLETION_COMPLETIONS ${CMAKE_INSTALL_DATADIR}/zsh/vendor-completions/)
install(FILES ./completion/dde-dconfig.zsh DESTINATION ${ZSH_COMPLETION_COMPLETIONS} RENAME _dde-dconfig)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# SPDX-FileCopyrightText: 2023 Uniontech Software Technology Co.,Ltd.
# SPDX-FileCopyrightText: 2024 Uniontech Software Technology Co.,Ltd.
#
# SPDX-License-Identifier: LGPL-3.0-or-later

Expand All @@ -12,15 +12,10 @@ _dde_dconfig() {

case $prev in
'dde-dconfig')
COMPREPLY=($(compgen -W 'help list set get gui watch' -- $cur))
COMPREPLY=($(compgen -W 'help list set get reset gui watch' -- $cur))
return
;;
'list')
local result=($(dde-dconfig list))
COMPREPLY=($(compgen -W "${result[*]}" -- $cur))
return
;;
'set')
'list' | 'set' | 'reset' | 'watch')
local result=($(dde-dconfig list))
COMPREPLY=($(compgen -W "${result[*]}" -- $cur))
return
Expand All @@ -34,16 +29,6 @@ _dde_dconfig() {
COMPREPLY=($(compgen -W "${result[*]}" -- $cur))
return
;;
'reset')
local result=($(dde-dconfig list))
COMPREPLY=($(compgen -W "${result[*]}" -- $cur))
return
;;
'watch')
local result=($(dde-dconfig list))
COMPREPLY=($(compgen -W "${result[*]}" -- $cur))
return
;;
'-a')
local result=($(dde-dconfig list))
COMPREPLY=($(compgen -W "${result[*]}" -- $cur))
Expand Down
63 changes: 63 additions & 0 deletions dconfig-center/dde-dconfig/completion/dde-dconfig.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#compdef dde-dconfig

# SPDX-FileCopyrightText: 2024 Uniontech Software Technology Co.,Ltd.
#
# SPDX-License-Identifier: LGPL-3.0-or-later

_dde-dconfig() {
local ret=1
local -a commands=(
'list:list模式,列出可配置的应用Id,配置Id,及子目录'
'get:get模式,用于查询指定配置项的信息'
'set:set模式,用于设置配置项的值'
'reset:reset模式,用于重置配置项的值,此会清除对应的缓存值'
'watch:watch模式,用于监听配置项的更改'
'gui:gui模式,用于启动GUI工具,需要安装对应的GUI工具dde-dconfig-editor'
)

_arguments -C -s -S -n \
'(* -)'{-v,--version}"[display version information]: :->full" \
'(- 1 *)'{-h,--help}'[display usage information]: :->full' \
'1:cmd:->cmds' \
'*:: :->args' && ret=0

local last_index=$((${#words[@]}-1))
local prev=${words[$last_index]}
case "$state" in
cmds)
_describe -t commands 'commands' commands
;;
args)
case $prev in
'list' | 'set' | 'get' | 'reset' | 'watch' | '-a')
local result=($(dde-dconfig list))
compadd -a result
ret=0
;;
'-r')
local a=$words[$(($last_index-1))]
local result=($(dde-dconfig list -a $a))
compadd -a result
ret=0
;;
'-k')
local a=$words[$(($last_index-3))]
local r=$words[$(($last_index-1))]
local result=($(dde-dconfig --get -a $a -r $r))
compadd -a result
ret=0
;;
*)
local result=('-a' '-k' '-r')
compadd -a result
ret=0
;;
esac
;;
*) ;;
esac

return ret
}

_dde-dconfig
1 change: 1 addition & 0 deletions debian/dde-dconfig-daemon.install
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
usr/bin/dde-dconfig
usr/bin/dde-dconfig-daemon
usr/share/bash-completion/completions/*
usr/share/zsh/vendor-completions/*
usr/share/dbus-1/system.d/*
usr/share/dbus-1/interfaces/*
usr/share/dbus-1/system-services/*
Expand Down

0 comments on commit 97df47d

Please sign in to comment.