Skip to content

Commit

Permalink
feat: add bash completion for ll-builder
Browse files Browse the repository at this point in the history
-

Log:
  • Loading branch information
kamiyadm committed Jan 25, 2024
1 parent c7ed762 commit 74a6366
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions debian/linglong-builder.install
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
usr/bin/ll-builder
usr/share/linglong/builder/config.yaml
usr/share/linglong/builder/templates/*.yaml
usr/share/bash-completion/completions/ll-builder
2 changes: 1 addition & 1 deletion misc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include(GNUInstallDirs)

# bash-completion

set(BASH_COMPLETIONS bash_completion/ll-cli)
set(BASH_COMPLETIONS bash_completion/ll-cli bash_completion/ll-builder)

install(FILES ${BASH_COMPLETIONS}
DESTINATION ${CMAKE_INSTALL_DATADIR}/bash-completion/completions)
Expand Down
36 changes: 36 additions & 0 deletions misc/bash_completion/ll-builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/env bash

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

# linglong builder completion

__ll_builder_find_subcommand()
{
for i in "${COMP_WORDS[@]}"
do
if ! [[ $i = -* ]] && ! [[ $i = ll-builder ]]
then
echo "$i"
return
fi
done
echo ""
return
}

_ll_builder()
{
local wordlist

subcommand=$(__ll_builder_find_subcommand)
wordlist=$(ll-builder "$subcommand" --help | grep -Po '((?<= )-\w|(?<= )--[\w-]+)|(?<=subcommand )\w+|^ + \w+$' | tr '\n' ' ')

local cur=${COMP_WORDS[COMP_CWORD]};
COMPREPLY=( $(compgen -W "${wordlist}" -- "${cur}") )

return 0
}

complete -F _ll_builder ll-builder

0 comments on commit 74a6366

Please sign in to comment.