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 f109b2ca970d66c940fb4a346a4fbb50144d70a2

Add vifm.escape() Lua function
Escapes input to make it suitable for use in an external command for
current value of 'shell'.
Author: xaizek
Author date (UTC): 2022-03-17 18:24
Committer name: xaizek
Committer date (UTC): 2022-03-17 18:31
Parent(s): c8f9fe6858fd7f8f7d49ea22f24219a54b7e106e
Signing key: 99DC5E4DB05F6BE2
Tree: bf7f44915ff0c99c536166daad3457584221f6c9
File Lines added Lines deleted
data/vim/doc/app/vifm-lua.txt 11 1
src/lua/vlua.c 12 0
src/tags.c 1 0
tests/lua/api.c 9 0
File data/vim/doc/app/vifm-lua.txt changed (mode: 100644) (index 123626d34..ce6fe6351)
1 *vifm-lua.txt* For Vifm version 1.0 Last change: 2022 Mar 7
1 *vifm-lua.txt* For Vifm version 1.0 Last change: 2022 Mar 17
2 2
3 3 Email for bugs and suggestions: <xaizek@posteo.net> Email for bugs and suggestions: <xaizek@posteo.net>
4 4
 
... ... Parameters:~
417 417 Return:~ Return:~
418 418 Modified path. Modified path.
419 419
420 vifm.escape({what}) *vifm-l_vifm.escape()*
421 Escapes input to make it suitable for use in an external command for current
422 value of |vifm-'shell'|.
423
424 Parameters:~
425 {what} String to escape.
426
427 Return:~
428 Modified path.
429
420 430 vifm.exists({path}) *vifm-l_vifm.exists()* vifm.exists({path}) *vifm-l_vifm.exists()*
421 431 Checks existence of a path without resolving symbolic links. Checks existence of a path without resolving symbolic links.
422 432
File src/lua/vlua.c changed (mode: 100644) (index f6fc0a9dc..53b3100f2)
... ... static int VLUA_API(opts_global_index)(lua_State *lua);
64 64 static int VLUA_API(opts_global_newindex)(lua_State *lua); static int VLUA_API(opts_global_newindex)(lua_State *lua);
65 65 static int VLUA_API(vifm_errordialog)(lua_State *lua); static int VLUA_API(vifm_errordialog)(lua_State *lua);
66 66 static int VLUA_API(vifm_fnamemodify)(lua_State *lua); static int VLUA_API(vifm_fnamemodify)(lua_State *lua);
67 static int VLUA_API(vifm_escape)(lua_State *lua);
67 68 static int VLUA_API(vifm_exists)(lua_State *lua); static int VLUA_API(vifm_exists)(lua_State *lua);
68 69 static int VLUA_API(vifm_makepath)(lua_State *lua); static int VLUA_API(vifm_makepath)(lua_State *lua);
69 70 static int VLUA_API(vifm_expand)(lua_State *lua); static int VLUA_API(vifm_expand)(lua_State *lua);
 
... ... VLUA_DECLARE_SAFE(opts_global_index);
83 84 VLUA_DECLARE_UNSAFE(opts_global_newindex); VLUA_DECLARE_UNSAFE(opts_global_newindex);
84 85 VLUA_DECLARE_SAFE(vifm_errordialog); VLUA_DECLARE_SAFE(vifm_errordialog);
85 86 VLUA_DECLARE_SAFE(vifm_fnamemodify); VLUA_DECLARE_SAFE(vifm_fnamemodify);
87 VLUA_DECLARE_SAFE(vifm_escape);
86 88 VLUA_DECLARE_SAFE(vifm_exists); VLUA_DECLARE_SAFE(vifm_exists);
87 89 VLUA_DECLARE_SAFE(vifm_makepath); VLUA_DECLARE_SAFE(vifm_makepath);
88 90 VLUA_DECLARE_SAFE(vifm_expand); VLUA_DECLARE_SAFE(vifm_expand);
 
... ... VLUA_DECLARE_SAFE(vifm_addhandler);
103 105 static const struct luaL_Reg vifm_methods[] = { static const struct luaL_Reg vifm_methods[] = {
104 106 { "errordialog", VLUA_REF(vifm_errordialog) }, { "errordialog", VLUA_REF(vifm_errordialog) },
105 107 { "fnamemodify", VLUA_REF(vifm_fnamemodify) }, { "fnamemodify", VLUA_REF(vifm_fnamemodify) },
108 { "escape", VLUA_REF(vifm_escape) },
106 109 { "exists", VLUA_REF(vifm_exists) }, { "exists", VLUA_REF(vifm_exists) },
107 110 { "makepath", VLUA_REF(vifm_makepath) }, { "makepath", VLUA_REF(vifm_makepath) },
108 111 { "startjob", VLUA_REF(vifmjob_new) }, { "startjob", VLUA_REF(vifmjob_new) },
 
... ... VLUA_API(vifm_fnamemodify)(lua_State *lua)
358 361 return 1; return 1;
359 362 } }
360 363
364 /* Member of `vifm` that escapes its input string. Returns escaped string. */
365 static int
366 VLUA_API(vifm_escape)(lua_State *lua)
367 {
368 const char *what = luaL_checkstring(lua, 1);
369 lua_pushstring(lua, enclose_in_dquotes(what));
370 return 1;
371 }
372
361 373 /* Member of `vifm` that checks whether specified path exists without resolving /* Member of `vifm` that checks whether specified path exists without resolving
362 374 * symbolic links. Returns a boolean, which is true when path does exist. */ * symbolic links. Returns a boolean, which is true when path does exist. */
363 375 static int static int
File src/tags.c changed (mode: 100644) (index 59ececa91..aaffc4f69)
... ... const char *tags[] = {
697 697 "vifm-l_vifm.cmds.delcommand()", "vifm-l_vifm.cmds.delcommand()",
698 698 "vifm-l_vifm.currview()", "vifm-l_vifm.currview()",
699 699 "vifm-l_vifm.errordialog()", "vifm-l_vifm.errordialog()",
700 "vifm-l_vifm.escape()",
700 701 "vifm-l_vifm.exists()", "vifm-l_vifm.exists()",
701 702 "vifm-l_vifm.expand()", "vifm-l_vifm.expand()",
702 703 "vifm-l_vifm.fnamemodify()", "vifm-l_vifm.fnamemodify()",
File tests/lua/api.c changed (mode: 100644) (index c5e5808d7..aa1be827b)
... ... TEST(fnamemodify)
55 55 assert_string_equal("/parent/c.d", ui_sb_last()); assert_string_equal("/parent/c.d", ui_sb_last());
56 56 } }
57 57
58 TEST(vifm_escape)
59 {
60 ui_sb_msg("");
61
62 assert_success(vlua_run_string(vlua,
63 "print(vifm.escape(' '))"));
64 assert_string_equal("\" \"", ui_sb_last());
65 }
66
58 67 TEST(vifm_exists) TEST(vifm_exists)
59 68 { {
60 69 ui_sb_msg(""); ui_sb_msg("");
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