#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)

completionFinder.py (8.8 KB) - added by gpasero 18 months ago.
completion generator v2

Download all attachments as: .zip

Change History (11)

comment:1 Changed 18 months ago by antonio

Cc: antonio added

comment:2 Changed 18 months ago by Even Rouault

Cc: Bas Couwenberg added

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 ?

comment:3 in reply to:  2 Changed 18 months ago by Bas Couwenberg

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 Changed 18 months ago by Bas Couwenberg

Regarding the bash-completion installation, the bash-completion FAQ documents the following:

  1. 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?
  1. 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 with pkg-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 is compatdir (get it with pkg-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 here

For cmake we ship the bash-completion-config.cmake and bash-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 Changed 18 months ago by gpasero

Cc: gpasero added

comment:6 Changed 18 months ago by Even Rouault

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).

Changed 18 months ago by gpasero

Attachment: completionFinder.py added

completion generator v2

comment:7 Changed 18 months ago by gpasero

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 Changed 18 months ago by Even Rouault

Milestone: 2.1.0
Resolution: fixed
Status: newclosed

trunk r33585 "Add bash completion for GDAL/OGR utilities and scripts (contributed by Guillaume Pasero, #6381)"

comment:9 Changed 18 months ago by Kurt Schwehr

Resolution: fixed
Status: closedreopened

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 Changed 18 months ago by Even Rouault

Resolution: fixed
Status: reopenedclosed

r33598 "scripts/GNUmakefile: honour ${prefix} in install target, and re-enable calling scripts/GNUmakefile from top make install (#6381)"

Note: See TracTickets for help on using tickets.