Opened 7 years ago
Closed 7 years ago
#6381 closed enhancement (fixed)
Bash completion for GDAL utilities
Reported by: | gpasero | Owned by: | warmerdam |
---|---|---|---|
Priority: | normal | Milestone: | 2.1.0 |
Component: | Utilities | Version: | unspecified |
Severity: | normal | Keywords: | |
Cc: | antonio, Bas Couwenberg, gpasero |
Description
Hi,
I would like to contribute a python script to generate bash completion for GDAL utilities (gdal_translate, gdalwarp,...). Only OGR utils are missing, I'll add them soon. The completion works by proposing :
- options keys when they start with a '-'
- pixels types when the previous key is '-ot'
- GDAL drivers when the previous key is '-of' or '--format' (the list of drivers is evaluated at completion time).
You can have a preview of this script (see attachment) If the generation script can be integrated to the sources, I would like to know the expected header for copyright and author information.
Feel free to give your feedback,
Guillaume
Attachments (1)
Change History (11)
comment:1 by , 7 years ago
Cc: | added |
---|
follow-up: 3 comment:2 by , 7 years ago
Cc: | added |
---|
comment:3 by , 7 years ago
Replying to rouault:
1) Should the make install rule of GDAL makefile try to install the bash completion script somewhere ( $(DESTDIR)/etc/bash_completion.d likely ) ? or would the packaging rules do that themselves to place in the appropriate place of the distribution ?
Yes, the GDAL Makefile should try to install the bash completion script for the benefit of everyone who builds GDAL themselves. The packages can move it to the distro specific path if needed.
/etc/bash_completion.d
is still a good choice to install the file, although recent bash-completion
releases switched to /usr/share/bash-completion/completions
. You can find the appropriate path with pkg-config --variable=completionsdir bash-completion
.
2) I guess having the generated file in the GDAL tarball should be easier for package building so as to not be dependant of having Python 2, right ?
I don't think the (build) dependency on Python 2 to build the bash-completion is an issue. Most packagers will already depend on Python for the GDAL Python bindings any way. Having the script support both Python 2 and Python 3 is good for distros that are going to move away from Python 2 in the (near) future because of its deprecation.
comment:4 by , 7 years ago
Regarding the bash-completion installation, the bash-completion FAQ documents the following:
- I author/maintain package X and would like to maintain my own completion code for this package. Where should I put it to be sure that interactive bash shells will find it and source it?
- Install it in one of the directories pointed to by bash-completion's pkgconfig file variables. There are two alternatives: the recommended one is
completionsdir
(get it withpkg-config --variable=completionsdir bash-completion
) from which completions are loaded on demand based on invoked commands' names, so be sure to name your completion file accordingly, and to include for example symbolic links in case the file provides completions for more than one command. The other one which is present for backwards compatibility reasons iscompatdir
(get it withpkg-config --variable=compatdir bash-completion
) from which files are loaded when bash_completion is loaded.For packages using GNU autotools the installation can be handled for example like this in
configure.ac
:PKG_CHECK_VAR(bashcompdir, [bash-completion], [completionsdir], , bashcompdir="${sysconfdir}/bash_completion.d") AC_SUBST(bashcompdir)...accompanied by this in
Makefile.am
:bashcompdir = @bashcompdir@ dist_bashcomp_DATA = # completion files go hereFor cmake we ship the
bash-completion-config.cmake
andbash-completion-config-version.cmake
files. Example usage:find_package(bash-completion) if(BASH_COMPLETION_FOUND) message(STATUS "Using bash completion dir ${BASH_COMPLETION_COMPLETIONSDIR}") else() set (BASH_COMPLETION_COMPLETIONSDIR "/etc/bash_completion.d") message (STATUS "Using fallback bash completion dir ${BASH_COMPLETION_COMPLETIONSDIR}") endif() install(FILES your-completion-file DESTINATION ${BASH_COMPLETION_COMPLETIONSDIR})
comment:5 by , 7 years ago
Cc: | added |
---|
comment:6 by , 7 years ago
Bas, thanks for the useful hints.
Guillaume, regarding header, you can take insipiration from autotest/gcore/asyncreader.py (replace author and copyright with your information).
comment:7 by , 7 years ago
I have uploaded the updated version with:
- header for author/copyright mentions
- handling of ogr tools
- fix one character options that were missing
comment:8 by , 7 years ago
Milestone: | → 2.1.0 |
---|---|
Resolution: | → fixed |
Status: | new → closed |
comment:9 by , 7 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
This new feature does not respect the installation location. e.g. doing:
./configure --prefix=/home/schwehr/src/gdal/inst make install
Fails because it is trying to write to /etc/bash_completion.d/ rather than /home/schwehr/src/gdal/inst/etc/bash_completion.d/
make[1]: Entering directory `/home/schwehr/src/gdal/gdal/scripts' if test "x`pkg-config --version 2>/dev/null`" != "x" -a "x`pkg-config --variable=compatdir bash-completion`" != "x"; then \ /usr/local/google/home/schwehr/src/gdal/gdal/install-sh -d `pkg-config --variable=compatdir bash-completion` ; \ cp gdal-bash-completion.sh `pkg-config --variable=compatdir bash-completion`; \ fi
comment:10 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Bas, I'd be interested of your opinion of packager regarding how to deal with this bash completion script that is contributed regarding packaging. Actually we have a Python (2 only) script that generates the bash completion script itself. My questions :
1) Should the make install rule of GDAL makefile try to install the bash completion script somewhere ( $(DESTDIR)/etc/bash_completion.d likely ) ? or would the packaging rules do that themselves to place in the appropriate place of the distribution ?
2) I guess having the generated file in the GDAL tarball should be easier for package building so as to not be dependant of having Python 2, right ?