about summary refs log tree commit diff stats
path: root/src/omemo/store.c
blob: 434483ed2c8e9960bd2754fa9b21bc2e7381a31f (plain) (blame)
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
/*
 * store.c
 * vim: expandtab:ts=4:sts=4:sw=4
 *
 * Copyright (C) 2019 Paul Fariello <paul@fariello.eu>
 *
 * This file is part of Profanity.
 *
 * Profanity is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Profanity is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Profanity.  If not, see <https://www.gnu.org/licenses/>.
 *
 * In addition, as a special exception, the copyright holders give permission to
 * link the code of portions of this program with the OpenSSL library under
 * certain conditions as described in each individual source file, and
 * distribute linked combinations including the two.
 *
 * You must obey the GNU General Public License in all respects for all of the
 * code used other than OpenSSL. If you modify file(s) with this exception, you
 * may extend this exception to your version of the file(s), but you are not
 * obligated to do so. If you do not wish to do so, delete this exception
 * statement from your version. If you delete this exception statement from all
 * source files in the program, then also delete it here.
 *
 */
#include <glib.h>
#include <signal/signal_protocol.h>

#include "config.h"
#include "omemo/omemo.h"
#include "omemo/store.h"

static void _g_hash_table_free(GHashTable* hash_table);

GHashTable*
session_store_new(void)
{
    return g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_g_hash_table_free);
}

GHashTable*
pre_key_store_new(void)
{
    return g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_buffer_free);
}

GHashTable*
signed_pre_key_store_new(void)
{
    return g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_buffer_free);
}

void
identity_key_store_new(identity_key_store_t* identity_key_store)
{
    identity_key_store->trusted = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)signal_buffer_free);
    identity_key_store->private = NULL;
    identity_key_store->public = NULL;
}

#ifdef HAVE_LIBSIGNAL_LT_2_3_2
int
load_session(signal_buffer** record, const signal_protocol_address* address,
             void* user_data)
#else
int
load_session(signal_buffer** record, signal_buffer** user_record,
             const signal_protocol_address* address, void* user_data)
#endif
{
    GHashTable* session_store = (GHashTable*)user_data;
    GHashTable* device_store = NULL;

    device_store = g_hash_table_lookup(session_store, address->name);
    if (!device_store) {
        *record = NULL;
        return 0;
    }

    signal_buffer* original = g_hash_table_lookup(device_store, GINT_TO_POINTER(address->device_id));
    if (!original) {
        *record = NULL;
        return 0;
    }
    *record = signal_buffer_copy(original);
    return 1;
}

int
get_sub_device_sessions(signal_int_list** sessions, const char* name,
                        size_t name_len, void* user_data)
{
    GHashTable* session_store = (GHashTable*)user_data;
    GHashTable* device_store = NULL;
    GHashTableIter iter;
    gpointer key, value;

    device_store = g_hash_table_lookup(session_store, name);
    if (!device_store) {
        return SG_SUCCESS;
    }

    *sessions = signal_int_list_alloc();
    g_hash_table_iter_init(&iter, device_store);
    while (g_hash_table_iter_next(&iter, &key, &value)) {
        signal_int_list_push_back(*sessions, GPOINTER_TO_INT(key));
    }

    return SG_SUCCESS;
}

#ifdef HAVE_LIBSIGNAL_LT_2_3_2
int
store_session(const signal_protocol_address* address, uint8_t* record,
              size_t record_len, void* user_data)
#else
int
store_session(const signal_protocol_address* address,
              uint8_t* record, size_t record_len,
              uint8_t* user_record, size_t user_record_len,
              void* user_data)
#endif
{
    GHashTable* session_store = (GHashTable*)user_data;
    GHashTable* device_store = NULL;

    device_store = g_hash_table_lookup(session_store, (void*)address->name);
    if (!device_store) {
        device_store = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_buffer_free);
        g_hash_table_insert(session_store, strdup(address->name), device_store);
    }

    signal_buffer* buffer = signal_buffer_create(record, record_len);
    g_hash_table_insert(device_store, GINT_TO_POINTER(address->device_id), buffer);

    char* record_b64 = g_base64_encode(record, record_len);
    char* device_id = g_strdup_printf("%d", address->device_id);
    g_key_file_set_string(omemo_sessions_keyfile(), address->name, device_id, record_b64);
    free(device_id);
    g_free(record_b64);

    omemo_sessions_keyfile_save();

    return SG_SUCCESS;
}

int
contains_session(const signal_protocol_address* address, void* user_data)
{
    GHashTable* session_store = (GHashTable*)user_data;
    GHashTable* device_store = NULL;

    device_store = g_hash_table_lookup(session_store, address->name);
    if (!device_store) {
        return 0;
    }

    if (!g_hash_table_lookup(device_store, GINT_TO_POINTER(address->device_id))) {
        return 0;
    }

    return 1;
}

int
delete_session(const signal_protocol_address* address, void* user_data)
{
    GHashTable* session_store = (GHashTable*)user_data;
    GHashTable* device_store = NULL;

    device_store = g_hash_table_lookup(session_store, address->name);
    if (!device_store) {
        return SG_SUCCESS;
    }

    g_hash_table_remove(device_store, GINT_TO_POINTER(address->device_id));

    char* device_id_str = g_strdup_printf("%d", address->device_id);
    g_key_file_remove_key(omemo_sessions_keyfile(), address->name, device_id_str, NULL);
    g_free(device_id_str);
    omemo_sessions_keyfile_save();

    return SG_SUCCESS;
}

int
delete_all_sessions(const char* name, size_t name_len, void* user_data)
{
    GHashTable* session_store = (GHashTable*)user_data;
    GHashTable* device_store = NULL;

    device_store = g_hash_table_lookup(session_store, name);
    if (!device_store) {
        return SG_SUCCESS;
    }

    guint len = g_hash_table_size(device_store);
    g_hash_table_remove_all(device_store);
    return len;
}

int
load_pre_key(signal_buffer** record, uint32_t pre_key_id, void* user_data)
{
    signal_buffer* original;
    GHashTable* pre_key_store = (GHashTable*)user_data;

    original = g_hash_table_lookup(pre_key_store, GINT_TO_POINTER(pre_key_id));
    if (original == NULL) {
        return SG_ERR_INVALID_KEY_ID;
    }

    *record = signal_buffer_copy(original);
    return SG_SUCCESS;
}

int
store_pre_key(uint32_t pre_key_id, uint8_t* record, size_t record_len,
              void* user_data)
{
    GHashTable* pre_key_store = (GHashTable*)user_data;

    signal_buffer* buffer = signal_buffer_create(record, record_len);
    g_hash_table_insert(pre_key_store, GINT_TO_POINTER(pre_key_id), buffer);

    /* Long term storage */
    char* pre_key_id_str = g_strdup_printf("%d", pre_key_id);
    char* record_b64 = g_base64_encode(record, record_len);
    g_key_file_set_string(omemo_identity_keyfile(), OMEMO_STORE_GROUP_PREKEYS, pre_key_id_str, record_b64);
    g_free(pre_key_id_str);
    g_free(record_b64);

    omemo_identity_keyfile_save();

    return SG_SUCCESS;
}

int
contains_pre_key(uint32_t pre_key_id, void* user_data)
{
    GHashTable* pre_key_store = (GHashTable*)user_data;

    return g_hash_table_lookup(pre_key_store, GINT_TO_POINTER(pre_key_id)) != NULL;
}

int
remove_pre_key(uint32_t pre_key_id, void* user_data)
{
    GHashTable* pre_key_store = (GHashTable*)user_data;

    int ret = g_hash_table_remove(pre_key_store, GINT_TO_POINTER(pre_key_id));

    /* Long term storage */
    char* pre_key_id_str = g_strdup_printf("%d", pre_key_id);
    g_key_file_remove_key(omemo_identity_keyfile(), OMEMO_STORE_GROUP_PREKEYS, pre_key_id_str, NULL);
    g_free(pre_key_id_str);

    omemo_identity_keyfile_save();

    if (ret > 0) {
        return SG_SUCCESS;
    } else {
        return SG_ERR_INVALID_KEY_ID;
    }
}

int
load_signed_pre_key(signal_buffer** record, uint32_t signed_pre_key_id,
                    void* user_data)
{
    signal_buffer* original;
    GHashTable* signed_pre_key_store = (GHashTable*)user_data;

    original = g_hash_table_lookup(signed_pre_key_store, GINT_TO_POINTER(signed_pre_key_id));
    if (!original) {
        return SG_ERR_INVALID_KEY_ID;
    }

    *record = signal_buffer_copy(original);
    return SG_SUCCESS;
}

int
store_signed_pre_key(uint32_t signed_pre_key_id, uint8_t* record,
                     size_t record_len, void* user_data)
{
    GHashTable* signed_pre_key_store = (GHashTable*)user_data;

    signal_buffer* buffer = signal_buffer_create(record, record_len);
    g_hash_table_insert(signed_pre_key_store, GINT_TO_POINTER(signed_pre_key_id), buffer);

    /* Long term storage */
    char* signed_pre_key_id_str = g_strdup_printf("%d", signed_pre_key_id);
    char* record_b64 = g_base64_encode(record, record_len);
    g_key_file_set_string(omemo_identity_keyfile(), OMEMO_STORE_GROUP_SIGNED_PREKEYS, signed_pre_key_id_str, record_b64);
    g_free(signed_pre_key_id_str);
    g_free(record_b64);

    omemo_identity_keyfile_save();

    return SG_SUCCESS;
}

int
contains_signed_pre_key(uint32_t signed_pre_key_id, void* user_data)
{
    GHashTable* signed_pre_key_store = (GHashTable*)user_data;

    return g_hash_table_lookup(signed_pre_key_store, GINT_TO_POINTER(signed_pre_key_id)) != NULL;
}

int
remove_signed_pre_key(uint32_t signed_pre_key_id, void* user_data)
{
    GHashTable* signed_pre_key_store = (GHashTable*)user_data;

    int ret = g_hash_table_remove(signed_pre_key_store, GINT_TO_POINTER(signed_pre_key_id));

    /* Long term storage */
    char* signed_pre_key_id_str = g_strdup_printf("%d", signed_pre_key_id);
    g_key_file_remove_key(omemo_identity_keyfile(), OMEMO_STORE_GROUP_PREKEYS, signed_pre_key_id_str, NULL);
    g_free(signed_pre_key_id_str);

    omemo_identity_keyfile_save();

    return ret;
}

int
get_identity_key_pair(signal_buffer** public_data, signal_buffer** private_data,
                      void* user_data)
{
    identity_key_store_t* identity_key_store = (identity_key_store_t*)user_data;

    *public_data = signal_buffer_copy(identity_key_store->public);
    *private_data = signal_buffer_copy(identity_key_store->private);

    return SG_SUCCESS;
}

int
get_local_registration_id(void* user_data, uint32_t* registration_id)
{
    identity_key_store_t* identity_key_store = (identity_key_store_t*)user_data;

    *registration_id = identity_key_store->registration_id;

    return SG_SUCCESS;
}

int
save_identity(const signal_protocol_address* address, uint8_t* key_data,
              size_t key_len, void* user_data)
{
    identity_key_store_t* identity_key_store = (identity_key_store_t*)user_data;

    if (identity_key_store->recv) {
        /* Do not trust identity automatically */
        /* Instead we perform a real trust check */
        identity_key_store->recv = false;
        int trusted = is_trusted_identity(address, key_data, key_len, user_data);
        identity_key_store->recv = true;
        if (trusted == 0) {
            /* If not trusted we just don't save the identity */
            return SG_SUCCESS;
        }
    }

    signal_buffer* buffer = signal_buffer_create(key_data, key_len);

    GHashTable* trusted = g_hash_table_lookup(identity_key_store->trusted, address->name);
    if (!trusted) {
        trusted = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)signal_buffer_free);
        g_hash_table_insert(identity_key_store->trusted, strdup(address->name), trusted);
    }
    g_hash_table_insert(trusted, GINT_TO_POINTER(address->device_id), buffer);

    /* Long term storage */
    char* key_b64 = g_base64_encode(key_data, key_len);
    char* device_id = g_strdup_printf("%d", address->device_id);
    g_key_file_set_string(omemo_trust_keyfile(), address->name, device_id, key_b64);
    g_free(device_id);
    g_free(key_b64);

    omemo_trust_keyfile_save();

    return SG_SUCCESS;
}

int
is_trusted_identity(const signal_protocol_address* address, uint8_t* key_data,
                    size_t key_len, void* user_data)
{
    int ret;
    identity_key_store_t* identity_key_store = (identity_key_store_t*)user_data;

    GHashTable* trusted = g_hash_table_lookup(identity_key_store->trusted, address->name);
    if (!trusted) {
        if (identity_key_store->recv) {
            return 1;
        } else {
            return 0;
        }
    }

    signal_buffer* buffer = signal_buffer_create(key_data, key_len);
    signal_buffer* original = g_hash_table_lookup(trusted, GINT_TO_POINTER(address->device_id));

    ret = original != NULL && signal_buffer_compare(buffer, original) == 0;

    signal_buffer_free(buffer);

    if (identity_key_store->recv) {
        return 1;
    } else {
        return ret;
    }
}

int
store_sender_key(const signal_protocol_sender_key_name* sender_key_name,
                 uint8_t* record, size_t record_len, uint8_t* user_record,
                 size_t user_record_len, void* user_data)
{
    return SG_SUCCESS;
}

int
load_sender_key(signal_buffer** record, signal_buffer** user_record,
                const signal_protocol_sender_key_name* sender_key_name,
                void* user_data)
{
    return SG_SUCCESS;
}

static void
_g_hash_table_free(GHashTable* hash_table)
{
    g_hash_table_remove_all(hash_table);
    g_hash_table_unref(hash_table);
}
an class="se">\fR, \fBnatural\fR, \fBtype\fR, \fBsize\fR .Sp Note: You can reverse the order by using an uppercase O in the key combination. .IP "tilde_in_titlebar [bool]" 4 .IX Item "tilde_in_titlebar [bool]" Abbreviate \f(CW$HOME\fR with ~ in the title bar (first line) of ranger? .IP "unicode_ellipsis [bool]" 4 .IX Item "unicode_ellipsis [bool]" Use a unicode \*(L"...\*(R" character instead of \*(L"~\*(R" to mark cut-off filenames? .IP "update_title [bool]" 4 .IX Item "update_title [bool]" Set a window title? .IP "use_preview_script [bool] <zv>" 4 .IX Item "use_preview_script [bool] <zv>" Use the preview script defined in the setting \fIpreview_script\fR? .IP "xterm_alt_key [bool]" 4 .IX Item "xterm_alt_key [bool]" Enable this if key combinations with the Alt Key don't work for you. (Especially on xterm) .SH "COMMANDS" .IX Header "COMMANDS" You can enter the commands in the console which is opened by pressing \*(L":\*(R". .PP There are additional commands which are directly translated to python functions, one for every method in the ranger.core.actions.Actions class. They are not documented here, since they are mostly for key bindings, not to be typed in by a user. Read the source if you are interested in them. .IP "bulkrename" 2 .IX Item "bulkrename" This command opens a list of selected files in an external editor. After you edit and save the file, it will generate a shell script which does bulk renaming according to the changes you did in the file. .Sp This shell script is opened in an editor for you to review. After you close it, it will be executed. .IP "cd [\fIdirectory\fR]" 2 .IX Item "cd [directory]" The cd command changes the directory. The command \f(CW\*(C`:cd \-\*(C'\fR is equivalent to typing ``. .IP "chain \fIcommand1\fR[; \fIcommand2\fR[; \fIcommand3\fR...]]" 2 .IX Item "chain command1[; command2[; command3...]]" Combines multiple commands into one, separated by columns. .IP "chmod \fIoctal_number\fR" 2 .IX Item "chmod octal_number" Sets the permissions of the selection to the octal number. .Sp The octal number is between 000 and 777. The digits specify the permissions for the user, the group and others. A 1 permits execution, a 2 permits writing, a 4 permits reading. Add those numbers to combine them. So a 7 permits everything. .Sp Key bindings in the form of [\-+]<who><what> and =<octal> also exist. For example, \fB+ar\fR allows reading for everyone, \-ow forbids others to write and =777 allows everything. .Sp See also: man 1 chmod .IP "cmap \fIkey\fR \fIcommand\fR" 2 .IX Item "cmap key command" Binds keys for the console. Works like the \f(CW\*(C`map\*(C'\fR command. .IP "console [\-p\fIN\fR] \fIcommand\fR" 2 .IX Item "console [-pN] command" Opens the console with the command already typed in. The cursor is placed at \&\fIN\fR. .IP "copycmap \fIkey\fR \fInewkey\fR [\fInewkey2\fR ...]" 2 .IX Item "copycmap key newkey [newkey2 ...]" See \f(CW\*(C`copymap\*(C'\fR .IP "copymap \fIkey\fR \fInewkey\fR [\fInewkey2\fR ...]" 2 .IX Item "copymap key newkey [newkey2 ...]" Copies the keybinding \fIkey\fR to \fInewkey\fR in the \*(L"browser\*(R" context. This is a deep copy, so if you change the new binding (or parts of it) later, the old one is not modified. .Sp To copy key bindings of the console, taskview, or pager use \*(L"copycmap\*(R", \&\*(L"copytmap\*(R" or \*(L"copypmap\*(R". .IP "copypmap \fIkey\fR \fInewkey\fR [\fInewkey2\fR ...]" 2 .IX Item "copypmap key newkey [newkey2 ...]" See \f(CW\*(C`copymap\*(C'\fR .IP "copytmap \fIkey\fR \fInewkey\fR [\fInewkey2\fR ...]" 2 .IX Item "copytmap key newkey [newkey2 ...]" See \f(CW\*(C`copymap\*(C'\fR .IP "cunmap \fIkey\fR \fIcommand\fR" 2 .IX Item "cunmap key command" Removes key mappings of the console. Works like the \f(CW\*(C`unmap\*(C'\fR command. .IP "delete [\fIconfirmation\fR]" 2 .IX Item "delete [confirmation]" Destroy all files in the selection with a roundhouse kick. ranger will ask for a confirmation if you attempt to delete multiple (marked) files or non-empty directories. .Sp When asking for confirmation, this command will only proceed if the last given word starts with a `y'. .IP "edit [\fIfilename\fR]" 2 .IX Item "edit [filename]" Edit the current file or the file in the argument. .IP "eval [\fI\-q\fR] \fIpython_code\fR" 2 .IX Item "eval [-q] python_code" Evaluates the python code. `fm' is a reference to the \s-1FM\s0 instance. To display text, use the function `p'. The result is displayed on the screen unless you use the \*(L"\-q\*(R" option. .Sp Examples: :eval fm :eval len(fm.env.directories) :eval p(\*(L"Hello World!\*(R") .IP "filter [\fIstring\fR]" 2 .IX Item "filter [string]" Displays only the files which contain the \fIstring\fR in their basename. .IP "find \fIpattern\fR" 2 .IX Item "find pattern" Search files in the current directory that match the given (case-insensitive) regular expression pattern as you type. Once there is an unambiguous result, it will be run immediately. (Or entered, if it's a directory.) .IP "grep \fIpattern\fR" 2 .IX Item "grep pattern" Looks for a string in all marked files or directories. .IP "load_copy_buffer" 2 .IX Item "load_copy_buffer" Load the copy buffer from \fI~/.config/ranger/copy_buffer\fR. This can be used to pass the list of copied files to another ranger instance. .IP "map \fIkey\fR \fIcommand\fR" 2 .IX Item "map key command" Assign the key combination to the given command. Whenever you type the key/keys, the command will be executed. Additionally, if you use a quantifier when typing the key, like 5j, it will be passed to the command as the attribute \&\*(L"self.quantifier\*(R". .Sp The keys you bind with this command are accessible in the file browser only, not in the console, task view or pager. To bind keys there, use the commands \&\*(L"cmap\*(R", \*(L"tmap\*(R" or \*(L"pmap\*(R". .IP "mark \fIpattern\fR" 2 .IX Item "mark pattern" Mark all files matching the regular expression pattern. .IP "mkdir \fIdirname\fR" 2 .IX Item "mkdir dirname" Creates a directory with the name \fIdirname\fR. .IP "open_with [\fIapplication\fR] [\fIflags\fR] [\fImode\fR]" 2 .IX Item "open_with [application] [flags] [mode]" Open the selected files with the given application, unless it is omitted, in which case the default application is used. \fIflags\fR are characters out of \&\*(L"sdpcwSDPCW\*(R" and \fImode\fR is any positive integer. Their meanings are discussed in their own sections. .IP "pmap \fIkey\fR \fIcommand\fR" 2 .IX Item "pmap key command" Binds keys for the pager. Works like the \f(CW\*(C`map\*(C'\fR command. .IP "punmap \fIkey\fR \fIcommand\fR" 2 .IX Item "punmap key command" Removes key mappings of the pager. Works like the \f(CW\*(C`unmap\*(C'\fR command. .IP "quit" 2 .IX Item "quit" Like quit!, but closes only this tab if multiple tabs are open. .IP "quit!" 2 .IX Item "quit!" Quit ranger. The current directory will be bookmarked as ' so you can re-enter it by typing `` or '' the next time you start ranger. .IP "rename \fInewname\fR" 2 .IX Item "rename newname" Rename the current file. If a file with that name already exists, the renaming will fail. Also try the key binding A for appending something to a file name. .IP "save_copy_buffer" 2 .IX Item "save_copy_buffer" Save the copy buffer from \fI~/.config/ranger/copy_buffer\fR. This can be used to pass the list of copied files to another ranger instance. .IP "search \fIpattern\fR" 2 .IX Item "search pattern" Search files in the current directory that match the given (case insensitive) regular expression pattern. .IP "search_inc \fIpattern\fR" 2 .IX Item "search_inc pattern" Search files in the current directory that match the given (case insensitive) regular expression pattern. This command gets you to matching files as you type. .IP "set \fIoption\fR=\fIvalue\fR" 2 .IX Item "set option=value" Assigns a new value to an option. Valid options are listed in the settings section. Use tab completion to get the current value of an option, though this doesn't work for functions and regular expressions. Valid values are: .Sp .Vb 8 \& None None \& bool True or False \& integer 0 or 1 or \-1 or 2 etc. \& list [1, 2, 3] \& tuple 1, 2, 3 or (1, 2, 3) \& function lambda <arguments>: <expression> \& regexp regexp(\*(Aq<pattern>\*(Aq) \& string Anything .Ve .IP "shell [\-\fIflags\fR] \fIcommand\fR" 2 .IX Item "shell [-flags] command" Run a shell command. \fIflags\fR are discussed in their own section. .IP "terminal" 2 .IX Item "terminal" Spawns the \fIx\-terminal-emulator\fR starting in the current directory. .IP "touch \fIfilename\fR" 2 .IX Item "touch filename" Creates an empty file with the name \fIfilename\fR, unless it already exists. .IP "tmap \fIkey\fR \fIcommand\fR" 2 .IX Item "tmap key command" Binds keys for the taskview. Works like the \f(CW\*(C`map\*(C'\fR command. .IP "tunmap \fIkey\fR \fIcommand\fR" 2 .IX Item "tunmap key command" Removes key mappings of the taskview. Works like the \f(CW\*(C`unmap\*(C'\fR command. .IP "unmap [\fIkeys\fR ...]" 2 .IX Item "unmap [keys ...]" Removes the given key mappings in the \*(L"browser\*(R" context. To unmap key bindings in the console, taskview, or pager use \*(L"cunmap\*(R", \*(L"tunmap\*(R" or \*(L"punmap\*(R". .IP "unmark \fIpattern\fR" 2 .IX Item "unmark pattern" Unmark all files matching a regular expression pattern. .SH "FILES" .IX Header "FILES" ranger reads several configuration files which are located in \&\fI\f(CI$HOME\fI/.config/ranger\fR or \fI\f(CI$XDG_CONFIG_HOME\fI/ranger\fR if \f(CW$XDG_CONFIG_HOME\fR is defined. The configuration is done mostly in python. When removing a configuration file, remove its compiled version too. (Python automatically compiles modules. Since python3 they are saved in the _\|_pycache_\|_ directory, earlier versions store them with the .pyc extension in the same directory.) .PP Use the \-\-copy\-config option to obtain the default configuration files. They include further documentation and it's too much to put here. .PP You don't need to copy the whole file though, most configuration files are overlaid on top of the defaults (\fIoptions.py\fR, \fIcommand.py\fR, \fIrc.conf\fR) or can be sub-classed (\fIapps.py\fR, \fIcolorschemes\fR). .PP When starting ranger with the \fB\-\-clean\fR option, it will not access or create any of these files. .SS "\s-1CONFIGURATION\s0" .IX Subsection "CONFIGURATION" .IP "apps.py" 10 .IX Item "apps.py" Controls which applications are used to open files. .IP "commands.py" 10 .IX Item "commands.py" Defines commands which can be used by typing \*(L":\*(R". .IP "rc.conf" 10 .IX Item "rc.conf" Contains a list of commands which are executed on startup. Mostly key bindings are defined here. .IP "options.py" 10 .IX Item "options.py" Sets a handful of basic options. .IP "scope.sh" 10 .IX Item "scope.sh" This is a script that handles file previews. When the options \&\fIuse_preview_script\fR and \fIpreview_files\fR or, respectively, \&\fIpreview_directories\fR are set, the program specified in the option \&\fIpreview_script\fR is run and its output and/or exit code determines rangers reaction. .IP "colorschemes/" 10 .IX Item "colorschemes/" Colorschemes can be placed here. .SS "\s-1STORAGE\s0" .IX Subsection "STORAGE" .IP "bookmarks" 10 .IX Item "bookmarks" This file contains a list of bookmarks. The syntax is /^(.):(.*)$/. The first character is the bookmark key and the rest after the colon is the path to the file. In ranger, bookmarks can be set by typing m<key>, accessed by typing \&'<key> and deleted by typing um<key>. .IP "copy_buffer" 10 .IX Item "copy_buffer" When running the command :save_copy_buffer, the paths of all currently copied files are saved in this file. You can later run :load_copy_buffer to copy the same files again, pass them to another ranger instance or process them in a script. .IP "history" 10 .IX Item "history" Contains a list of commands that have been previously typed in. .IP "tagged" 10 .IX Item "tagged" Contains a list of tagged files. The syntax is /^(.:)?(.*)$/ where the first letter is the optional name of the tag and the rest after the optional colon is the path to the file. In ranger, tags can be set by pressing t and removed with T. To assign a named tag, type "<tagname>. .SH "ENVIRONMENT" .IX Header "ENVIRONMENT" These environment variables have an effect on ranger: .IP "\s-1EDITOR\s0" 8 .IX Item "EDITOR" Defines the editor to be used for the \*(L"E\*(R" key. Defaults to the first installed program out of \*(L"vim\*(R", \*(L"emacs\*(R" and \*(L"nano\*(R". .IP "\s-1SHELL\s0" 8 .IX Item "SHELL" Defines the shell that ranger is going to use with the :shell command and the \*(L"S\*(R" key. Defaults to \*(L"bash\*(R". .IP "\s-1XDG_CONFIG_HOME\s0" 8 .IX Item "XDG_CONFIG_HOME" Specifies the directory for configuration files. Defaults to \fI\f(CI$HOME\fI/.config\fR. .IP "\s-1PYTHONOPTIMIZE\s0" 8 .IX Item "PYTHONOPTIMIZE" This variable determines the optimize level of python. .Sp Using PYTHONOPTIMIZE=1 (like python \-O) will make python discard assertion statements. You will gain efficiency at the cost of losing some debug info. .Sp Using PYTHONOPTIMIZE=2 (like python \-OO) will additionally discard any docstrings. Using this will disable the <F1> key on commands. .SH "EXAMPLES" .IX Header "EXAMPLES" .SS "\s-1VIM:\s0 File Chooser" .IX Subsection "VIM: File Chooser" This is a vim function which allows you to use ranger to select a file for opening in your current vim session. .PP .Vb 9 \& fun! RangerChooser() \& silent !ranger \-\-choosefile=/tmp/chosenfile \`[ \-z \*(Aq%\*(Aq ] && echo \-n . || dirname %\` \& if filereadable(\*(Aq/tmp/chosenfile\*(Aq) \& exec \*(Aqedit \*(Aq . system(\*(Aqcat /tmp/chosenfile\*(Aq) \& call system(\*(Aqrm /tmp/chosenfile\*(Aq) \& endif \& redraw! \& endfun \& map ,r :call RangerChooser()<CR> .Ve .SS "Bash: cd to last path after exit" .IX Subsection "Bash: cd to last path after exit" This is a bash function (for \fI~/.bashrc\fR) to change the directory to the last visited one after ranger quits. You can always type \f(CW\*(C`cd \-\*(C'\fR to go back to the original one. .PP .Vb 9 \& function ranger\-cd { \& tempfile=\*(Aq/tmp/chosendir\*(Aq \& /usr/bin/ranger \-\-choosedir="$tempfile" "${@:\-$(pwd)}" \& test \-f "$tempfile" && \& if [ "$(cat \-\- "$tempfile")" != "$(echo \-n \`pwd\`)" ]; then \& cd \-\- "$(cat "$tempfile")" \& fi \& rm \-f \-\- "$tempfile" \& } \& \& # This binds Ctrl\-O to ranger\-cd: \& bind \*(Aq"\eC\-o":"ranger\-cd\eC\-m"\*(Aq .Ve .SH "LICENSE" .IX Header "LICENSE" \&\s-1GNU\s0 General Public License 3 or (at your option) any later version. .SH "LINKS" .IX Header "LINKS" .IP "Download: <http://ranger.nongnu.org/ranger-stable.tar.gz>" 4 .IX Item "Download: <http://ranger.nongnu.org/ranger-stable.tar.gz>" .PD 0 .IP "The project page: <http://ranger.nongnu.org/>" 4 .IX Item "The project page: <http://ranger.nongnu.org/>" .IP "The mailing list: <http://savannah.nongnu.org/mail/?group=ranger>" 4 .IX Item "The mailing list: <http://savannah.nongnu.org/mail/?group=ranger>" .PD .PP ranger is maintained with the git version control system. To fetch a fresh copy, run: .PP .Vb 1 \& git clone git://git.savannah.nongnu.org/ranger.git .Ve .SH "BUGS" .IX Header "BUGS" Report bugs here: <http://savannah.nongnu.org/bugs/?group=ranger> .PP Please include as much relevant information as possible. For the most diagnostic output, run ranger like this: \f(CW\*(C`PYTHONOPTIMIZE= ranger \-\-debug\*(C'\fR