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 34f10d7818463bdd561ef6573f1c3640efe0b0b7

Add "pwd" parameter to vifm.startjob()
It specifies initial directory of the process.

Thanks to PRESFIL.
Author: xaizek
Author date (UTC): 2024-10-30 16:44
Committer name: xaizek
Committer date (UTC): 2024-10-30 16:44
Parent(s): fe83105713c27be15a98034cb6c0ebd993bccc10
Signing key: 99DC5E4DB05F6BE2
Tree: 9035352d06f789a7611a5a8632864947b029a246
File Lines added Lines deleted
ChangeLog.LuaAPI 3 0
data/vim/doc/app/vifm-lua.txt 4 1
src/lua/vifmjob.c 7 1
tests/lua/api_jobs.c 28 0
tests/lua/asserts.h 24 5
File ChangeLog.LuaAPI changed (mode: 100644) (index 762536d87..5df87ae6b)
... ... documented in the regular ChangeLog.
38 38 Added VifmJob:terminate() to forcefully finish a job. Thanks to The Added VifmJob:terminate() to forcefully finish a job. Thanks to The
39 39 Cyberduck. Cyberduck.
40 40
41 Added "pwd" parameter to vifm.startjob() that specifies initial directory
42 of the process. Thanks to PRESFIL.
43
41 44 Made VifmJob:errors() wait for receiving errors if the job has finished. Made VifmJob:errors() wait for receiving errors if the job has finished.
42 45
43 46 Fixed jobs created via vifm.startjob() being displayed with "UNKNOWN" for Fixed jobs created via vifm.startjob() being displayed with "UNKNOWN" for
File data/vim/doc/app/vifm-lua.txt changed (mode: 100644) (index 72207c59e..11b17d828)
1 *vifm-lua.txt* For Vifm version 1.0 Last change: 2024 Oct 27
1 *vifm-lua.txt* For Vifm version 1.0 Last change: 2024 Oct 30
2 2
3 3 Email for bugs and suggestions: <xaizek@posteo.net> Email for bugs and suggestions: <xaizek@posteo.net>
4 4
 
... ... Possible fields of {job}:
710 710 The handler is {delayed}. The handler is {delayed}.
711 711 - "mergestreams" (boolean) (default: false) - "mergestreams" (boolean) (default: false)
712 712 Whether to merge error stream of the command with its output stream. Whether to merge error stream of the command with its output stream.
713 - "pwd" (string) (default: ".")
714 Working directory of the new process.
713 715 - "visible" (boolean) (default: false) - "visible" (boolean) (default: false)
714 716 Whether to show this job on a job bar. Whether to show this job on a job bar.
715 717
 
... ... Return:~
721 723
722 724 Raises an error:~ Raises an error:~
723 725 If "iomode" has incorrect value. If "iomode" has incorrect value.
726 If "pwd" doesn't specify an existing path.
724 727
725 728 vifm.stdout() *vifm-l_vifm.stdout()* vifm.stdout() *vifm-l_vifm.stdout()*
726 729 Retrieves stream to which Vifm's standard stream was redirected. Retrieves stream to which Vifm's standard stream was redirected.
File src/lua/vifmjob.c changed (mode: 100644) (index c6b1a9d60..ad2504d39)
... ... VLUA_API(vifmjob_new)(lua_State *lua)
166 166 descr = lua_tostring(lua, -1); descr = lua_tostring(lua, -1);
167 167 } }
168 168
169 const char *pwd = NULL;
170 if(vlua_cmn_check_opt_field(lua, 1, "pwd", LUA_TSTRING))
171 {
172 pwd = lua_tostring(lua, -1);
173 }
174
169 175 int with_on_exit = vlua_cmn_check_opt_field(lua, 1, "onexit", LUA_TFUNCTION); int with_on_exit = vlua_cmn_check_opt_field(lua, 1, "onexit", LUA_TFUNCTION);
170 176
171 bg_job_t *job = bg_run_external_job(cmd, flags, descr, /*pwd=*/NULL);
177 bg_job_t *job = bg_run_external_job(cmd, flags, descr, pwd);
172 178 if(job == NULL) if(job == NULL)
173 179 { {
174 180 return luaL_error(lua, "%s", "Failed to start a job"); return luaL_error(lua, "%s", "Failed to start a job");
File tests/lua/api_jobs.c changed (mode: 100644) (index 5ace92d95..ca252d2d3)
6 6 #include <string.h> /* strdup() */ #include <string.h> /* strdup() */
7 7 #include <time.h> /* time() */ #include <time.h> /* time() */
8 8
9 #include "../../src/compat/os.h"
9 10 #include "../../src/engine/var.h" #include "../../src/engine/var.h"
10 11 #include "../../src/engine/variables.h" #include "../../src/engine/variables.h"
11 12 #include "../../src/lua/vlua.h" #include "../../src/lua/vlua.h"
 
... ... TEST(vifmjob_terminate_running)
301 302 assert_true(t2 - t1 < 10); assert_true(t2 - t1 < 10);
302 303 } }
303 304
305 TEST(vifmjob_good_pwd)
306 {
307 assert_success(os_chdir(SANDBOX_PATH));
308 create_dir("sub");
309 #ifndef _WIN32
310 GLUA_ENDS(vlua, "sub",
311 "job = vifm.startjob { cmd = 'pwd', pwd = 'sub' }"
312 "print(job:stdout():lines()())");
313 #else
314 GLUA_CONTAINS(vlua, "sub",
315 "job = vifm.startjob { cmd = 'echo %CD%', pwd = 'sub' }"
316 "print(job:stdout():lines()())");
317 #endif
318
319 /* Removal might require the job to stop. */
320 GLUA_EQ(vlua, "", "job:wait()");
321
322 remove_dir("sub");
323 }
324
325 TEST(vifmjob_bad_pwd_causes_error)
326 {
327 BLUA_ENDS(vlua, ": Failed to start a job",
328 "job = vifm.startjob { cmd = 'echo', pwd = 'no-such-path' }"
329 "print(job:exitcode())");
330 }
331
304 332 static void static void
305 333 setup_io_tester(void) setup_io_tester(void)
306 334 { {
File tests/lua/asserts.h changed (mode: 100644) (index a397c9509..12da47efd)
11 11 * header. * header.
12 12 * *
13 13 * Macros name structure: * Macros name structure:
14 * - GLUA_ prefix means Lua code execution should succeed (Good)
15 * - BLUA_ prefix means Lua code execution should fail (Bad)
16 * - _EQ suffix checks output match exactly (use "" for no output)
17 * - _STARTS suffix checks that output starts with a string
18 * - _ENDS suffix checks that output ends with a string
14 * - GLUA_ prefix means Lua code execution should succeed (Good)
15 * - BLUA_ prefix means Lua code execution should fail (Bad)
16 * - _EQ suffix checks output match exactly (use "" for no output)
17 * - _STARTS suffix checks that output starts with a string
18 * - _CONTAINS suffix checks that output contains a string
19 * - _ENDS suffix checks that output ends with a string
19 20 */ */
20 21
21 22 #define GLUA_EQ(vlua, expected_output, code) \ #define GLUA_EQ(vlua, expected_output, code) \
 
36 37 } \ } \
37 38 while(0) while(0)
38 39
40 #define GLUA_CONTAINS(vlua, expected_substr, code) \
41 do \
42 { \
43 ui_sb_msg(""); \
44 assert_success(vlua_run_string(vlua, code)); \
45 assert_string_contains(expected_substr, ui_sb_last()); \
46 } \
47 while(0)
48
39 49 #define GLUA_ENDS(vlua, expected_suffix, code) \ #define GLUA_ENDS(vlua, expected_suffix, code) \
40 50 do \ do \
41 51 { \ { \
 
63 73 } \ } \
64 74 while(0) while(0)
65 75
76 #define BLUA_CONTAINS(vlua, expected_substr, code) \
77 do \
78 { \
79 ui_sb_msg(""); \
80 assert_failure(vlua_run_string(vlua, code)); \
81 assert_string_contains(expected_substr, ui_sb_last()); \
82 } \
83 while(0)
84
66 85 #define BLUA_ENDS(vlua, expected_suffix, code) \ #define BLUA_ENDS(vlua, expected_suffix, code) \
67 86 do \ do \
68 87 { \ { \
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