-
Notifications
You must be signed in to change notification settings - Fork 802
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4371 from rouault/projinfo_bash_completion
Add bash completion script for projinfo
- Loading branch information
Showing
6 changed files
with
471 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
find_package(PkgConfig QUIET) | ||
if (PKG_CONFIG_FOUND) | ||
pkg_check_modules(PC_BASH_COMPLETION QUIET bash-completion) | ||
if (PC_BASH_COMPLETION_FOUND) | ||
pkg_get_variable(BASH_COMPLETIONS_FULL_DIR bash-completion completionsdir) | ||
pkg_get_variable(BASH_COMPLETIONS_PREFIX bash-completion prefix) | ||
if (BASH_COMPLETIONS_FULL_DIR | ||
AND BASH_COMPLETIONS_PREFIX | ||
AND BASH_COMPLETIONS_FULL_DIR MATCHES "^${BASH_COMPLETIONS_PREFIX}/") | ||
string(REGEX REPLACE "^${BASH_COMPLETIONS_PREFIX}/" "" BASH_COMPLETIONS_DIR_DEFAULT ${BASH_COMPLETIONS_FULL_DIR}) | ||
endif () | ||
endif () | ||
endif () | ||
|
||
if (NOT DEFINED BASH_COMPLETIONS_DIR_DEFAULT) | ||
include(GNUInstallDirs) | ||
set(BASH_COMPLETIONS_DIR_DEFAULT ${CMAKE_INSTALL_DATADIR}/bash-completion/completions) | ||
endif () | ||
|
||
set(BASH_COMPLETIONS_DIR | ||
"${BASH_COMPLETIONS_DIR_DEFAULT}" | ||
CACHE PATH "Installation sub-directory for bash completion scripts") | ||
|
||
if (NOT BASH_COMPLETIONS_DIR STREQUAL "") | ||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/install_bash_completions.cmake.in | ||
${CMAKE_CURRENT_BINARY_DIR}/install_bash_completions.cmake @ONLY) | ||
install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/install_bash_completions.cmake) | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
set(PROGRAMS | ||
projinfo | ||
) | ||
|
||
set(INSTALL_DIR "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/@BASH_COMPLETIONS_DIR@") | ||
|
||
file(MAKE_DIRECTORY "${INSTALL_DIR}") | ||
|
||
foreach (program IN LISTS PROGRAMS) | ||
message(STATUS "Installing ${INSTALL_DIR}/${program}") | ||
configure_file("@CMAKE_CURRENT_SOURCE_DIR@/${program}-bash-completion.sh" "${INSTALL_DIR}/${program}" COPYONLY) | ||
file(APPEND "@PROJECT_BINARY_DIR@/install_manifest_extra.txt" "${INSTALL_DIR}/${program}\n") | ||
endforeach () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/bash | ||
|
||
function_exists() { | ||
declare -f -F "$1" > /dev/null | ||
return $? | ||
} | ||
|
||
# Checks that bash-completion is recent enough | ||
function_exists _get_comp_words_by_ref || return 0 | ||
|
||
_projinfo() | ||
{ | ||
local cur prev | ||
COMPREPLY=() | ||
_get_comp_words_by_ref cur prev | ||
choices=$(projinfo completion ${COMP_LINE}) | ||
if [[ "$cur" == "=" ]]; then | ||
mapfile -t COMPREPLY < <(compgen -W "$choices" --) | ||
elif [[ "$cur" == ":" ]]; then | ||
mapfile -t COMPREPLY < <(compgen -W "$choices" --) | ||
elif [[ "${cur: -1}" == "/" ]]; then | ||
mapfile -t COMPREPLY < <(compgen -W "$choices" --) | ||
elif [[ "${cur: -2}" == "/ " ]]; then | ||
mapfile -t COMPREPLY < <(compgen -W "$choices" --) | ||
elif [[ "${cur: -1}" == "+" ]]; then | ||
mapfile -t COMPREPLY < <(compgen -W "$choices" --) | ||
elif [[ "${cur: -2}" == "+ " ]]; then | ||
mapfile -t COMPREPLY < <(compgen -W "$choices" --) | ||
elif [[ "$cur" == "!" ]]; then | ||
mapfile -t COMPREPLY < <(compgen -W "$choices" -P "! " --) | ||
else | ||
mapfile -t COMPREPLY < <(compgen -W "$choices" -- "$cur") | ||
fi | ||
for element in "${COMPREPLY[@]}"; do | ||
if [[ $element == */ ]]; then | ||
# Do not add a space if one of the suggestion ends with slash | ||
compopt -o nospace | ||
break | ||
elif [[ $element == *= ]]; then | ||
# Do not add a space if one of the suggestion ends with equal | ||
compopt -o nospace | ||
break | ||
elif [[ $element == *: ]]; then | ||
# Do not add a space if one of the suggestion ends with colon | ||
compopt -o nospace | ||
break | ||
fi | ||
done | ||
} | ||
complete -o default -F _projinfo projinfo | ||
|
Oops, something went wrong.