Skip to content

Commit 4849479

Browse files
committed
Move code to functions
1 parent 4787dcf commit 4849479

File tree

1 file changed

+75
-63
lines changed

1 file changed

+75
-63
lines changed

src/init.c

Lines changed: 75 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,6 +2682,76 @@ set_sudo_cmd(void)
26822682
sudo_cmd = DEF_SUDO_CMD;
26832683
}
26842684

2685+
#ifndef _NO_FZF
2686+
static void
2687+
set_fzftab_options(void)
2688+
{
2689+
if (fzftab == UNSET) {
2690+
if (xargs.fzftab == UNSET) {
2691+
// This flag will be true only when reloading the config file,
2692+
// because the check for the fzf binary is made at startup AFTER
2693+
// reading the config file (check_third_party_cmds() in checks.c).
2694+
if (bin_flags & FZF_BIN_OK)
2695+
fzftab = 1;
2696+
} else {
2697+
fzftab = xargs.fzftab;
2698+
}
2699+
2700+
if (xargs.fnftab == 1)
2701+
tabmode = FNF_TAB;
2702+
else if (xargs.fzftab == 1)
2703+
tabmode = FZF_TAB;
2704+
else if (xargs.smenutab == 1)
2705+
tabmode = SMENU_TAB;
2706+
else
2707+
tabmode = STD_TAB;
2708+
}
2709+
2710+
if (!conf.fzftab_options) {
2711+
if (conf.colorize == 1 || !getenv("FZF_DEFAULT_OPTS")) {
2712+
if (conf.colorize == 1) {
2713+
conf.fzftab_options =
2714+
savestring(DEF_FZFTAB_OPTIONS,
2715+
sizeof(DEF_FZFTAB_OPTIONS) - 1);
2716+
} else {
2717+
conf.fzftab_options =
2718+
savestring(DEF_FZFTAB_OPTIONS_NO_COLOR,
2719+
sizeof(DEF_FZFTAB_OPTIONS_NO_COLOR) - 1);
2720+
}
2721+
} else {
2722+
conf.fzftab_options = savestring("", 1);
2723+
}
2724+
}
2725+
2726+
set_fzf_preview_border_type();
2727+
2728+
smenutab_options_env = (xargs.secure_env_full != 1 && tabmode == SMENU_TAB)
2729+
? getenv("CLIFM_SMENU_OPTIONS") : (char *)NULL;
2730+
2731+
if (smenutab_options_env
2732+
&& sanitize_cmd(smenutab_options_env, SNT_BLACKLIST) != 0) {
2733+
err('w', PRINT_PROMPT, "%s: CLIFM_SMENU_OPTIONS contains unsafe "
2734+
"characters (<>|;&$`). Falling back to default values.\n",
2735+
PROGRAM_NAME);
2736+
smenutab_options_env = (char *)NULL;
2737+
}
2738+
}
2739+
#endif /* !_NO_FZF */
2740+
2741+
static void
2742+
set_encoded_prompt(void)
2743+
{
2744+
free(conf.encoded_prompt);
2745+
if (conf.colorize == 1) {
2746+
conf.encoded_prompt =
2747+
savestring(DEFAULT_PROMPT, sizeof(DEFAULT_PROMPT) - 1);
2748+
} else {
2749+
conf.encoded_prompt =
2750+
savestring(DEFAULT_PROMPT_NO_COLOR,
2751+
sizeof(DEFAULT_PROMPT_NO_COLOR) - 1);
2752+
}
2753+
}
2754+
26852755
#define SETOPT(cmd_line, def) ((cmd_line) == UNSET ? (def) : (cmd_line))
26862756

26872757
/* If some option was not set, set it to the default value. */
@@ -2791,59 +2861,10 @@ check_options(void)
27912861
}
27922862

27932863
#ifndef _NO_FZF
2794-
if (fzftab == UNSET) {
2795-
if (xargs.fzftab == UNSET) {
2796-
/* This flag will be true only when reloading the config file,
2797-
* because the check for the fzf binary is made at startup AFTER
2798-
* reading the config file (check_third_party_cmds() in checks.c) */
2799-
if (bin_flags & FZF_BIN_OK)
2800-
fzftab = 1;
2801-
} else {
2802-
fzftab = xargs.fzftab;
2803-
}
2804-
2805-
if (xargs.fnftab == 1)
2806-
tabmode = FNF_TAB;
2807-
else if (xargs.fzftab == 1)
2808-
tabmode = FZF_TAB;
2809-
else if (xargs.smenutab == 1)
2810-
tabmode = SMENU_TAB;
2811-
else
2812-
tabmode = STD_TAB;
2813-
}
2814-
2815-
if (!conf.fzftab_options) {
2816-
if (conf.colorize == 1 || !getenv("FZF_DEFAULT_OPTS")) {
2817-
if (conf.colorize == 1) {
2818-
conf.fzftab_options =
2819-
savestring(DEF_FZFTAB_OPTIONS,
2820-
sizeof(DEF_FZFTAB_OPTIONS) - 1);
2821-
} else {
2822-
conf.fzftab_options =
2823-
savestring(DEF_FZFTAB_OPTIONS_NO_COLOR,
2824-
sizeof(DEF_FZFTAB_OPTIONS_NO_COLOR) - 1);
2825-
}
2826-
} else {
2827-
conf.fzftab_options = savestring("", 1);
2828-
}
2829-
}
2830-
2831-
set_fzf_preview_border_type();
2832-
2833-
smenutab_options_env = (xargs.secure_env_full != 1 && tabmode == SMENU_TAB)
2834-
? getenv("CLIFM_SMENU_OPTIONS") : (char *)NULL;
2835-
2836-
if (smenutab_options_env
2837-
&& sanitize_cmd(smenutab_options_env, SNT_BLACKLIST) != 0) {
2838-
err('w', PRINT_PROMPT, "%s: CLIFM_SMENU_OPTIONS contains unsafe "
2839-
"characters (<>|;&$`). Falling back to default values.\n",
2840-
PROGRAM_NAME);
2841-
smenutab_options_env = (char *)NULL;
2842-
}
2843-
2864+
set_fzftab_options();
28442865
#else
28452866
tabmode = STD_TAB;
2846-
#endif /* _NO_FZF */
2867+
#endif /* !_NO_FZF */
28472868

28482869
#ifndef _NO_LIRA
28492870
if (xargs.stealth_mode == 1) {
@@ -2978,17 +2999,8 @@ check_options(void)
29782999
if (conf.colorize == 0)
29793000
expand_prompt_name(DEF_PROMPT_NO_COLOR_NAME);
29803001

2981-
if (!conf.encoded_prompt || !*conf.encoded_prompt) {
2982-
free(conf.encoded_prompt);
2983-
if (conf.colorize == 1) {
2984-
conf.encoded_prompt =
2985-
savestring(DEFAULT_PROMPT, sizeof(DEFAULT_PROMPT) - 1);
2986-
} else {
2987-
conf.encoded_prompt =
2988-
savestring(DEFAULT_PROMPT_NO_COLOR,
2989-
sizeof(DEFAULT_PROMPT_NO_COLOR) - 1);
2990-
}
2991-
}
3002+
if (!conf.encoded_prompt || !*conf.encoded_prompt)
3003+
set_encoded_prompt();
29923004

29933005
set_prompt_options();
29943006

@@ -3009,7 +3021,7 @@ check_options(void)
30093021
if (xargs.stealth_mode == 1 && !conf.opener) {
30103022
/* Since in stealth mode we have no access to the config file, we cannot
30113023
* use Lira, since it relays on a file. Set it thus to FALLBACK_OPENER,
3012-
* if not already set via command line */
3024+
* if not already set via command line. */
30133025
conf.opener = savestring(FALLBACK_OPENER, sizeof(FALLBACK_OPENER) - 1);
30143026
}
30153027

0 commit comments

Comments
 (0)