diff --git a/CHANGES b/CHANGES index cf5f9637e..58602f256 100644 --- a/CHANGES +++ b/CHANGES @@ -6,10 +6,11 @@ website will have to do for older versions. # 3.2.24 (unreleased) # This release contains contributions from (alphabetically by first name): - - No external contributors yet + - Gaël PORTAY ## Core ## - - No core changes yet + - There is now a bash-completions script for Calamares; turn on + the (CMake-time) option INSTALL_COMPLETION to get it. (Thanks Gaël) ## Modules ## - No module changes yet diff --git a/CMakeLists.txt b/CMakeLists.txt index bc14780a9..6edece315 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ set( CALAMARES_VERSION_RC 1 ) # Set to 0 during release cycle, 1 during develop # option( INSTALL_CONFIG "Install configuration files" OFF ) option( INSTALL_POLKIT "Install Polkit configuration" ON ) +option( INSTALL_COMPLETION "Install shell completions" OFF ) option( BUILD_TESTING "Build the testing tree." ON ) option( WITH_PYTHON "Enable Python modules API (requires Boost.Python)." ON ) option( WITH_PYTHONQT "Enable next generation Python modules API (experimental, requires PythonQt)." OFF ) @@ -389,6 +390,13 @@ list( SORT CALAMARES_TRANSLATION_LANGUAGES ) add_subdirectory( lang ) # i18n tools +if ( INSTALL_COMPLETION ) + if( NOT CMAKE_INSTALL_BASHCOMPLETIONDIR ) + set( CMAKE_INSTALL_BASHCOMPLETIONDIR "${CMAKE_INSTALL_DATADIR}/bash-completion/completions" ) + endif() + + install( FILES ${CMAKE_SOURCE_DIR}/data/completion/bash/calamares DESTINATION "${CMAKE_INSTALL_BASHCOMPLETIONDIR}" ) +endif() ### Example Distro # diff --git a/data/completion/bash/calamares b/data/completion/bash/calamares new file mode 100644 index 000000000..47c2bb268 --- /dev/null +++ b/data/completion/bash/calamares @@ -0,0 +1,36 @@ +# === This file is part of Calamares - === +# +# Copyright 2020, Gaël PORTAY +# +# Calamares is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Calamares is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Calamares. If not, see . + +_calamares() +{ + local cur prev words cword + _init_completion || return + + case "$prev" in + -D) + COMPREPLY=( $( compgen -W "$( seq 0 1 8 )" -- "$cur" ) ) + return + ;; + -c|--config) + _filedir + return + ;; + esac + + COMPREPLY=( $( compgen -W "-h --help -v --version -d --debug -D -c --config -X -xdg-config -T --debug-translation" -- "$cur" ) ) +} && +complete -F _calamares calamares