-
Notifications
You must be signed in to change notification settings - Fork 797
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bash completion script for projinfo
and install it in standard ${prefix}/share/bash-completion/completions directory Demo: ``` source ./scripts/projinfo-bash-completion.sh ``` ``` $ projinfo <TAB><TAB> EPSG: ESRI: IAU_2015: IGNF: NKG: NRCAN: OGC: PROJ: ``` ``` $ projinfo -<TAB><TAB> -3d --boundcrs-to-wgs84 --list-crs --searchpaths --accuracy --c-ify --main-db-path --show-superseded --allow-ellipsoidal-height-as-vertical-crs --crs-extent-use--grid-check -o --single-line --area --dump-db-structure --output-id --spatial-test --authority --hide-ballpark --pivot-crs --summary --aux-db-path --identify -q --bbox -k --remote-data ``` ``` $ projinfo -o <TAB><TAB> all PROJ PROJJSON SQL WKT1:ESRI WKT1:GDAL WKT2:2015 WKT2:2019 ``` ``` $ projinfo "NAD83(2011) <TAB><TAB> NAD83(2011) NAD83(2011) / New Mexico West NAD83(2011) / Adjusted Jackson (ftUS) NAD83(2011) / New Mexico West (ftUS) NAD83(2011) / Alabama East NAD83(2011) / New York Central [ ... snip ... ] ``` ``` $ projinfo EPSG:43<TAB><TAB> 4322 -- WGS 72 4324 -- WGS 72BE 4326 -- WGS 84 ```
- Loading branch information
Showing
6 changed files
with
356 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 | ||
|
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