From 7e2ff6435cd1a5a504eab34823a4f63c7a46df1f Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Fri, 15 Mar 2019 22:29:55 +0100 Subject: added Makefile and simple Bash completions * this allows precompiling openrussian.lua, automatically downloads, converts and VACUUMs the openrussian database and provides an `install` target * Bash completions allow completing "bare" Russian words for the time being. Unfortunately we cannot complete with accents, since Bash completions do not allow to change the already typed word (apparently) and users aren't going to type in accents. --- openrussian-completion.bash | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 openrussian-completion.bash (limited to 'openrussian-completion.bash') diff --git a/openrussian-completion.bash b/openrussian-completion.bash new file mode 100644 index 0000000..0facd31 --- /dev/null +++ b/openrussian-completion.bash @@ -0,0 +1,21 @@ +#/bin/bash + +# NOTE: Uses SQL for matching instead of compgen, since it's probably not +# a good idea to always retrieve all the words, although this happens anyway +# when completing an empty word. +# +# FIXME: sqlite3 command-line tool does not provide a safe method for embedding +# strings, so we should either properly escape $2 or write an external Lua script. + +_openrussian_completions() +{ + SQL="SELECT bare FROM words WHERE bare LIKE \"$2%\"" + + # Calculate database path based on the installation path of the `openrussian` + # CLI tool. This way, we can avoid preprocessing the script during installation. + PREFIX=$(dirname $(which openrussian))/.. + + COMPREPLY=($(sqlite3 "$PREFIX/share/openrussian/openrussian-sqlite3.db" "$SQL")) +} + +complete -F _openrussian_completions openrussian -- cgit v1.2.3