aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 122e16e235d21f8cd0f45a46c10727a34cc9d711 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# An Offline Console Russian Dictionary (based on openrussian.org)

This is an offline console and terminal-friendly Russian dictionary,
based on the database of [openrussian.org](https://en.openrussian.org/).

* Works offline (without internet access) and is very fast.
  This really pays off if you browse Russian words a lot.
* It integrates well into the console environment - browse dictionary
  entries like man pages.
  Internally, Troff code is generated which makes further processing of generated
  pages ~~very easy~~ possible.
* Puts very low requirements on the runtime environment:
  a black and white terminal display is sufficient.
* Auto completions supported for Bash and Zsh.
  Most of this is handled by the script's `-C` argument, so it
  is trivial to add support for other shells.
  Contributions are welcome!
* Search terms can be: base forms (infinitives, nominative singular nouns...),
  inflections (all cases, conjugations, short forms, imperatives...) and
  translations.
* Search terms are [glob patterns](https://en.wikipedia.org/wiki/Glob_(programming)),
  which is very useful for looking up words with uncertain spelling or finding
  related words.

Possible future features:

* Limit the number of results (by default to 1000) - the sheer number of results
  can slow down auto-completions.
* Not all terminals can display the accent correctly (linux console), so we should have
  a fallback.
  Ideally this can be detected, or we simply whitelist terminal emulators via $TERM.
* Better internationalization when generating German pages (`-Lde`).
* Lookups via popular
  [ASCII-cyrillic transliterations](https://en.wikipedia.org/wiki/Informal_romanizations_of_Cyrillic) -
  would be useful without a Russian/cyrillic keyboard layout.
* Be tolerant to typing mistakes.
* Accented characters are still broken in nroff tables
  (see https://lists.gnu.org/archive/html/groff/2018-08/msg00000.html).
  We could and probably should of translate most vowel-accent combinations to single precomposed codepoints,
  but that might cause problems when copying text from the terminal.

## Installation

### Ubuntu

Build-time dependencies:

    sudo apt-get install make pkg-config lua5.2 bash-completion wget unzip gawk sqlite3

Run-time dependencies:

    sudo apt-get install lua5.2 lua-sql-sqlite3 man-db bash-completion

Furthermore, you will need the [luautf8 library](https://github.com/starwing/luautf8).
Using [LuaRocks](https://luarocks.org/), it may be installed as follows:

    sudo luarocks-5.2 install luautf8

Building is straight forward:

    make
    sudo make install

If you want to redownload the latest [openrussian.org](https://en.openrussian.org/)
database:

    make clean all check

**Warning:** While the database content might be newer, the database schema
might also at any time become incompatible with the existing script.
That is why a `check` is performed after building everything in the above
example.
If it returns lots of errors, you should probably stay with the original database.
Otherwise, the error messages might help in fixing/upgrading the script.
You are of course welcome to contribute patches. :-)

### FreeBSD

Build-time dependencies:

    pkg install gmake pkgconf groff lua52 lua52-luasql-sqlite3 lua52-luarocks wget sqlite3

Installing [luautf8](https://github.com/starwing/luautf8) using LuaRocks:

    luarocks52 install luautf8

Building is straight forward:

    gmake LUA=lua52 LUAC=luac52
    gmake install

### NixOS

`openrussian-cli` is part of the `nixos-unstable` (and soon `nixos-21.05`) channels.

To install `openrussian-cli` on NixOS:
* Via `configuration.nix`:
  ```nix
  environment.systemPackages = [ pkgs.openrussian-cli ];
  ```
* Via `nix-env`:
  ```bash
  nix-env -iA openrussian-cli
  ```

See https://nixos.org/manual/nixos/stable/index.html#sec-package-management for more information.

### Bash Aliases

While the default command name `openrussian` was chosen to avoid cluttering the
global command namespace, you may want to define more concise shortcuts.
In order to do so, add something like the following to your `~/.bashrc`:

    alias ru='openrussian' ру='openrussian'
    _completion_loader openrussian
    complete -F _openrussian_completions ru ру

This adds the alias `ru` (latin) and `ру` (cyrillic).
It would however be useful to add a few default options to the `ru` and `ру` aliases.
Unfortunately, above method cannot take that into account.
A more robust solution might be to install the
[complete-alias](https://github.com/cykerway/complete-alias) script and adding
something like the following to your `~/.bash_completion`:

    alias ru='openrussian -Lde -Len' ру='openrussian -Lde -Len'
    complete -F _complete_alias ru ру

### Zsh Aliases

Autocompletion will automatically work with aliases in the Zsh, so it is
sufficient to add the following to your `~/.zshrc`:

    alias ru='openrussian -Lde -Len' ру='openrussian -Lde -Len'

### Fish Aliases

The Fish `alias` command creates local shell aliases or
persistent aliases when invoked with the `--save` flag.

    alias --save ru='openrussian -Lde -Len'
    alias --save ру='openrussian -Lde -Len'

## Examples

A simple lookup:

    openrussian саморазрушение

Display the German translation:

    openrussian -Lde саморазрушение

Display both German and English translations, giving precedence to German:

    openrussian -Lde -Len саморазрушение

If you are unsure which consonants appear in this word:

    openrussian самора[сз]ру[шщ]ение

Find more words derived from "разрушение":

    openrussian *разрушение

Avoid ambiguous search results:

    openrussian -V коса

Look up by translation:

    openrussian catch a cold

Graphical display using `groffer`:

    openrussian -p кошка | groffer -Kutf8 --mode pdf2

You may have to specify a non-default font supporting
cyrillic characters via groffer's `-f` option.

## License

The main program is licensed under the GNU General Public License Version 3 or later
(see `COPYING`).

This repository contains database dumps from the
[openrussian.org website](https://en.openrussian.org/dictionary).
The `openrussian-sql.zip` file is licensed under the [CC BY-SA](https://creativecommons.org/licenses/)
license.

This repository also contains code, imported from the
[mysql2sqlite repository](https://github.com/dumblob/mysql2sqlite.git).
The file `mysql2qlite` is licensed under the following terms and conditions:

```
The MIT License (MIT)

Copyright (c) 2015 esperlu, 2016 dumblob

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```

## Further documentation

    man openrussian