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 df15f4828df42575fa6ea5416f6c23e6d50c1c04

Don't run startup commands on session load
They are re-executed on :restart (unclear if they should) but must not
be run when loading sessions. One side-effect of this is an
impossibility to switch a session after starting Vifm with `+session
some` because any session switch will rerun `:session some`.

Thanks to maxigaz.

Fixes #1113 on GitHub.
Author: xaizek
Author date (UTC): 2026-06-09 08:41
Committer name: xaizek
Committer date (UTC): 2026-06-09 08:41
Parent(s): e928390d4ec25701e1fd575270ae4a273401e1c9
Signing key: 99DC5E4DB05F6BE2
Tree: fd2efee0117a299c2948920ff2e144d23581244a
File Lines added Lines deleted
ChangeLog 3 0
src/cmd_handlers.c 2 1
src/instance.c 5 2
src/instance.h 1 1
tests/commands/restart.c 12 0
tests/commands/sessions.c 21 0
tests/misc/vifminfo.c 1 1
tests/test-support/stubs.c 2 1
tests/test-support/stubs.h 1 0
File ChangeLog changed (mode: 100644) (index ba594000f..683ff5a98)
250 250 Fixed ruler in view mode not growing in size to accommodate its content. Fixed ruler in view mode not growing in size to accommodate its content.
251 251 Thanks to Dennis Preiser (a.k.a. 0xDP). Thanks to Dennis Preiser (a.k.a. 0xDP).
252 252
253 Fixed startup commands being executed on loading sessions. Thanks to
254 maxigaz.
255
253 256 0.14-beta to 0.14 (2025-02-08) 0.14-beta to 0.14 (2025-02-08)
254 257
255 258 Improved documentation on zh/zl menu keys a bit. Improved documentation on zh/zl menu keys a bit.
File src/cmd_handlers.c changed (mode: 100644) (index 1f3752008..d48029512)
... ... restart_into_session(const char session[], RestartType type)
4572 4572 { {
4573 4573 state_load(type != RT_FULL); state_load(type != RT_FULL);
4574 4574 result = 0; result = 0;
4575 instance_finish_restart(/*run_startup_commands=*/1);
4575 4576 } }
4576 4577 else else
4577 4578 { {
4578 4579 result = sessions_load(session); result = sessions_load(session);
4580 instance_finish_restart(/*run_startup_commands=*/0);
4579 4581 } }
4580 4582
4581 instance_finish_restart();
4582 4583 return result; return result;
4583 4584 } }
4584 4585
File src/instance.c changed (mode: 100644) (index 9801868a0..b6f95855a)
... ... instance_start_restart(RestartType type)
135 135 } }
136 136
137 137 void void
138 instance_finish_restart(void)
138 instance_finish_restart(int run_startup_commands)
139 139 { {
140 140 flist_hist_save(&lwin); flist_hist_save(&lwin);
141 141 flist_hist_save(&rwin); flist_hist_save(&rwin);
 
... ... instance_finish_restart(void)
155 155 instance_load_config(); instance_load_config();
156 156 plugs_load(curr_stats.plugs, curr_stats.plugins_dirs); plugs_load(curr_stats.plugs, curr_stats.plugins_dirs);
157 157
158 vifm_reexec_startup_commands();
158 if(run_startup_commands)
159 {
160 vifm_reexec_startup_commands();
161 }
159 162
160 163 curr_stats.restart_in_progress = RT_NONE; curr_stats.restart_in_progress = RT_NONE;
161 164
File src/instance.h changed (mode: 100644) (index 2ae8fbe3f..baeb7f5a1)
... ... void instance_start_restart(RestartType type);
35 35 /* Loads color scheme, processes configuration file and so on to finish restart. /* Loads color scheme, processes configuration file and so on to finish restart.
36 36 * Does NOT load state of the application, it's expected to be done between * Does NOT load state of the application, it's expected to be done between
37 37 * calls to instance_start_restart() and this function. */ * calls to instance_start_restart() and this function. */
38 void instance_finish_restart(void);
38 void instance_finish_restart(int run_startup_commands);
39 39
40 40 /* Loads configuration file taking care of anything that needs to be done before /* Loads configuration file taking care of anything that needs to be done before
41 41 * or after it. */ * or after it. */
File tests/commands/restart.c changed (mode: 100644) (index 32e8c86d4..b4c879ead)
1 1 #include <stic.h> #include <stic.h>
2 2
3 #include <stubs.h>
3 4 #include <test-utils.h> #include <test-utils.h>
4 5
5 6 #include "../../src/cfg/config.h" #include "../../src/cfg/config.h"
 
... ... TEST(restart_resets_abbreviations)
168 169 assert_false(vle_abbr_iter(&lhs, &rhs, &descr, &no_remap, &state)); assert_false(vle_abbr_iter(&lhs, &rhs, &descr, &no_remap, &state));
169 170 } }
170 171
172 TEST(restart_runs_startup_commands)
173 {
174 vifm_startup_commands_executed = 0;
175 assert_success(cmds_dispatch1("restart", &lwin, CIT_COMMAND));
176 assert_true(vifm_startup_commands_executed);
177
178 vifm_startup_commands_executed = 0;
179 assert_success(cmds_dispatch1("restart full", &lwin, CIT_COMMAND));
180 assert_true(vifm_startup_commands_executed);
181 }
182
171 183 static void static void
172 184 setup_tabs(void) setup_tabs(void)
173 185 { {
File tests/commands/sessions.c changed (mode: 100644) (index 7ceceea1d..61b074de5)
4 4
5 5 #include <stdlib.h> /* free() */ #include <stdlib.h> /* free() */
6 6
7 #include <stubs.h>
7 8 #include <test-utils.h> #include <test-utils.h>
8 9
9 10 #include "../../src/cfg/config.h" #include "../../src/cfg/config.h"
 
... ... TEST(autocmd_is_called_for_all_pane_tabs)
391 392 cfg.pane_tabs = 0; cfg.pane_tabs = 0;
392 393 } }
393 394
395 TEST(session_switch_doesnt_run_startup_commands)
396 {
397 make_abs_path(cfg.config_dir, sizeof(cfg.config_dir), SANDBOX_PATH, "", NULL);
398 cfg.session_options = VINFO_CHISTORY;
399
400 assert_failure(cmds_dispatch1("session session", &lwin, CIT_COMMAND));
401 assert_failure(cmds_dispatch1("session other", &lwin, CIT_COMMAND));
402
403 ui_sb_msg("");
404 vifm_startup_commands_executed = 0;
405 assert_failure(cmds_dispatch1("session session", &lwin, CIT_COMMAND));
406 assert_string_equal("Loaded session: session", ui_sb_last());
407 assert_false(vifm_startup_commands_executed);
408
409 remove_file(SANDBOX_PATH "/sessions/session.json");
410 remove_file(SANDBOX_PATH "/sessions/other.json");
411 remove_dir(SANDBOX_PATH "/sessions");
412 remove_file(SANDBOX_PATH "/vifminfo.json");
413 }
414
394 415 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */ /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
395 416 /* vim: set cinoptions+=t0 filetype=c : */ /* vim: set cinoptions+=t0 filetype=c : */
File tests/misc/vifminfo.c changed (mode: 100644) (index 8a926d60a..5639ee834)
... ... TEST(size_of_dhistory_is_limited)
489 489 /* Reload the state and config (which should be empty in tests). */ /* Reload the state and config (which should be empty in tests). */
490 490 instance_start_restart(RT_MOST); instance_start_restart(RT_MOST);
491 491 state_load(0); state_load(0);
492 instance_finish_restart();
492 instance_finish_restart(/*run_startup_commands=*/1);
493 493 /* Verify that history was trimmed to the set limit. */ /* Verify that history was trimmed to the set limit. */
494 494 assert_int_equal(2, lwin.history_num); assert_int_equal(2, lwin.history_num);
495 495
File tests/test-support/stubs.c changed (mode: 100644) (index cfff1db69..12aa9717d)
7 7 struct view_t; struct view_t;
8 8
9 9 int vifm_tests_exited; int vifm_tests_exited;
10 int vifm_startup_commands_executed;
10 11
11 12 void void
12 13 vifm_reexec_startup_commands(void) vifm_reexec_startup_commands(void)
13 14 { {
14 /* Do nothing. */
15 vifm_startup_commands_executed = 1;
15 16 } }
16 17
17 18 void void
File tests/test-support/stubs.h changed (mode: 100644) (index 0eee9ca79..cb8036b57)
2 2 #define VIFM_TESTS__TEST_SUPPORT__STUBS_H__ #define VIFM_TESTS__TEST_SUPPORT__STUBS_H__
3 3
4 4 extern int vifm_tests_exited; extern int vifm_tests_exited;
5 extern int vifm_startup_commands_executed;
5 6
6 7 #endif /* VIFM_TESTS__TEST_SUPPORT__STUBS_H__ */ #endif /* VIFM_TESTS__TEST_SUPPORT__STUBS_H__ */
7 8
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