xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
Commit 86b14b1d1d149ec0691adb6f47740c7bc580dc4d

Fix processing of path regexps for filetypes
When operating on selection.

Also fix running multiple files in custom view (origin directory
wasn't taken into account).

Thanks to aleksejrs.
Author: xaizek
Author date (UTC): 2016-02-07 20:54
Committer name: xaizek
Committer date (UTC): 2016-02-07 21:08
Parent(s): 2a8d75c074a61b14739d5a0942344507813ec50b
Signing key:
Tree: 4d7bacb14ef246cf9b2162cc90e9520b75a06138
File Lines added Lines deleted
ChangeLog 5 0
src/filelist.c 0 7
src/filelist.h 1 4
src/running.c 3 3
tests/misc/running.c 127 0
File ChangeLog changed (mode: 100644) (index c84c84458..a17734708)
71 71 Fixed TUI glitches in the form of borders after shrinking terminal to Fixed TUI glitches in the form of borders after shrinking terminal to
72 72 smallest possible height and restoring it back. smallest possible height and restoring it back.
73 73
74 Fixed processing of path regexps for filetypes when operating on
75 selection. Thanks to aleksejrs.
76
77 Fixed running multiple files in custom view.
78
74 79 0.8.1-beta to 0.8.1 0.8.1-beta to 0.8.1
75 80
76 81 Added summary to builtin tree implementation. Thanks to aleksejrs. Added summary to builtin tree implementation. Thanks to aleksejrs.
File src/filelist.c changed (mode: 100644) (index ca8958f38..277a38d41)
... ... get_typed_entry_fpath(const dir_entry_t *entry)
1427 1427 return format_str("%s%s", full_path, type_suffix); return format_str("%s%s", full_path, type_suffix);
1428 1428 } }
1429 1429
1430 char *
1431 get_typed_entry_fname(const dir_entry_t *entry)
1432 {
1433 const char *const name = entry->name;
1434 return is_directory_entry(entry) ? format_str("%s/", name) : strdup(name);
1435 }
1436
1437 1430 int int
1438 1431 flist_custom_active(const FileView *view) flist_custom_active(const FileView *view)
1439 1432 { {
File src/filelist.h changed (mode: 100644) (index acc7c2b1a..2a6fb7bee)
... ... void save_view_history(FileView *view, const char path[], const char file[],
178 178 int is_in_view_history(FileView *view, const char *path); int is_in_view_history(FileView *view, const char *path);
179 179 void clean_positions_in_history(FileView *view); void clean_positions_in_history(FileView *view);
180 180
181 /* Typed (with trailing slash for directories) file name functions. */
181 /* Typed (with trailing slash for directories) file name function. */
182 182
183 183 /* Gets typed path for the entry. On return allocates memory, that should be /* Gets typed path for the entry. On return allocates memory, that should be
184 184 * freed by the caller. */ * freed by the caller. */
185 185 char * get_typed_entry_fpath(const dir_entry_t *entry); char * get_typed_entry_fpath(const dir_entry_t *entry);
186 /* Gets typed filename (not path, just name) for the entry. Allocates memory,
187 * that should be freed by the caller. */
188 char * get_typed_entry_fname(const dir_entry_t *entry);
189 186
190 187 /* Custom file list functions. */ /* Custom file list functions. */
191 188
File src/running.c changed (mode: 100644) (index 667ce16c2..f587fe3d6)
... ... run_file(FileView *view, int dont_execute)
421 421 char *typed_fname; char *typed_fname;
422 422 const char *entry_prog_cmd; const char *entry_prog_cmd;
423 423
424 if(!path_exists(entry->name, DEREF))
424 if(!path_exists_at(entry->origin, entry->name, DEREF))
425 425 { {
426 426 show_error_msgf("Broken Link", "Destination of \"%s\" link doesn't exist", show_error_msgf("Broken Link", "Destination of \"%s\" link doesn't exist",
427 427 entry->name); entry->name);
428 428 return; return;
429 429 } }
430 430
431 typed_fname = get_typed_entry_fname(entry);
431 typed_fname = get_typed_entry_fpath(entry);
432 432 entry_prog_cmd = ft_get_program(typed_fname); entry_prog_cmd = ft_get_program(typed_fname);
433 433 free(typed_fname); free(typed_fname);
434 434
 
... ... run_selection_separately(FileView *view, int dont_execute)
510 510 char *typed_fname; char *typed_fname;
511 511 const char *entry_prog_cmd; const char *entry_prog_cmd;
512 512
513 typed_fname = get_typed_entry_fname(entry);
513 typed_fname = get_typed_entry_fpath(entry);
514 514 entry_prog_cmd = ft_get_program(typed_fname); entry_prog_cmd = ft_get_program(typed_fname);
515 515 free(typed_fname); free(typed_fname);
516 516
File tests/misc/running.c added (mode: 100644) (index 000000000..61bf07a2f)
1 #include <stic.h>
2
3 #include <unistd.h> /* chdir() */
4
5 #include <stddef.h> /* NULL */
6 #include <stdio.h> /* snprintf() */
7 #include <string.h> /* strdup() */
8
9 #include "../../src/cfg/config.h"
10 #include "../../src/utils/dynarray.h"
11 #include "../../src/utils/fs.h"
12 #include "../../src/utils/matcher.h"
13 #include "../../src/utils/path.h"
14 #include "../../src/utils/str.h"
15 #include "../../src/filelist.h"
16 #include "../../src/filetype.h"
17 #include "../../src/running.h"
18 #include "../../src/status.h"
19
20 static int prog_exists(const char name[]);
21
22 SETUP()
23 {
24 #ifndef _WIN32
25 update_string(&cfg.shell, "/bin/sh");
26 #else
27 update_string(&cfg.shell, "cmd");
28 #endif
29
30 update_string(&cfg.vi_command, "echo");
31
32 stats_update_shell_type(cfg.shell);
33
34 lwin.list_rows = 2;
35 lwin.list_pos = 0;
36 lwin.dir_entry = dynarray_cextend(NULL,
37 lwin.list_rows*sizeof(*lwin.dir_entry));
38 lwin.dir_entry[0].name = strdup("a");
39 lwin.dir_entry[0].origin = &lwin.curr_dir[0];
40 lwin.dir_entry[0].selected = 1;
41 lwin.dir_entry[1].name = strdup("b");
42 lwin.dir_entry[1].origin = &lwin.curr_dir[0];
43 lwin.dir_entry[1].selected = 1;
44 lwin.selected_files = 2;
45 curr_view = &lwin;
46
47 ft_init(&prog_exists);
48
49 if(is_path_absolute(TEST_DATA_PATH))
50 {
51 snprintf(lwin.curr_dir, sizeof(lwin.curr_dir), "%s/existing-files",
52 TEST_DATA_PATH);
53 }
54 else
55 {
56 char cwd[PATH_MAX];
57 assert_non_null(get_cwd(cwd, sizeof(cwd)));
58
59 snprintf(lwin.curr_dir, sizeof(lwin.curr_dir), "%s/%s/existing-files", cwd,
60 TEST_DATA_PATH);
61 }
62 }
63
64 TEARDOWN()
65 {
66 int i;
67
68 update_string(&cfg.shell, NULL);
69 stats_update_shell_type("/bin/sh");
70
71 for(i = 0; i < lwin.list_rows; ++i)
72 {
73 free_dir_entry(&lwin, &lwin.dir_entry[i]);
74 }
75 dynarray_free(lwin.dir_entry);
76
77 ft_reset(0);
78 update_string(&cfg.vi_command, NULL);
79 }
80
81 TEST(full_path_regexps_are_handled_for_selection)
82 {
83 matcher_t *m;
84 char pattern[PATH_MAX];
85 char *error;
86
87 /* Mind that there is no chdir(), this additionally checks that origins are
88 * being used by the code. */
89
90 snprintf(pattern, sizeof(pattern), "//%s/*//", lwin.curr_dir);
91 m = matcher_alloc(pattern, 0, 1, &error);
92 assert_non_null(m);
93 ft_set_programs(m, "echo %f >> " SANDBOX_PATH "/run", 0, 1);
94
95 open_file(&lwin, FHE_NO_RUN);
96
97 /* Checking for file existence on its removal. */
98 assert_success(remove(SANDBOX_PATH "/run"));
99 }
100
101 TEST(full_path_regexps_are_handled_for_selection2)
102 {
103 matcher_t *m;
104 char pattern[PATH_MAX];
105 char *error;
106
107 /* Mind that there is no chdir(), this additionally checks that origins are
108 * being used by the code. */
109
110 snprintf(pattern, sizeof(pattern), "//%s/*//", lwin.curr_dir);
111 m = matcher_alloc(pattern, 0, 1, &error);
112 assert_non_null(m);
113 ft_set_programs(m, "echo %c &", 0, 1);
114
115 open_file(&lwin, FHE_NO_RUN);
116
117 /* If we don't crash, then everything is fine. */
118 }
119
120 static int
121 prog_exists(const char name[])
122 {
123 return 1;
124 }
125
126 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
127 /* vim: set cinoptions+=t0 filetype=c : */
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master