/* Writes path configuration file and directories for further usage. */ static void store_config_paths(void) { LOG_FUNC_ENTER; const char *const trash_dir_fmt = #ifndef _WIN32 "%%r/.vifm-Trash-%%u,%s/" TRASH ",%%r/.vifm-Trash"; #else "%%r/.vifm-Trash,%s/" TRASH; #endif char *fuse_home; const char *trash_base = path_exists_at(env_get(VIFM_EV), TRASH, DEREF) ? cfg.config_dir : cfg.data_dir; const char *base = path_exists(cfg.data_dir, DEREF) ? cfg.data_dir : cfg.config_dir; snprintf(cfg.home_dir, sizeof(cfg.home_dir), "%s/", env_get(HOME_EV)); copy_str(cfg.config_dir, sizeof(cfg.config_dir), env_get(VIFM_EV)); snprintf(cfg.colors_dir, sizeof(cfg.colors_dir), "%s/colors/", cfg.config_dir); snprintf(cfg.trash_dir, sizeof(cfg.trash_dir), trash_dir_fmt, trash_base); snprintf(cfg.log_file, sizeof(cfg.log_file), "%s/" LOG, base); fuse_home = format_str("%s/fuse/", base); (void)cfg_set_fuse_home(fuse_home); free(fuse_home); }
int are_old_color_schemes(void) { char colors_dir[PATH_MAX]; snprintf(colors_dir, sizeof(colors_dir), "%s/colors", cfg.config_dir); return !is_dir(colors_dir) && path_exists_at(cfg.config_dir, "colorschemes"); }
/* Tries to use $XDG_CONFIG_HOME/vifm as configuration directory. Returns * non-zero on success, otherwise zero is returned. */ static int try_xdg_for_conf(void) { LOG_FUNC_ENTER; char *config_dir; const char *const config_home = env_get("XDG_CONFIG_HOME"); if(!is_null_or_empty(config_home) && is_path_absolute(config_home)) { config_dir = format_str("%s/vifm", config_home); } else if(path_exists_at(env_get(HOME_EV), ".config", DEREF)) { config_dir = format_str("%s/.config/vifm", env_get(HOME_EV)); } else { return 0; } env_set(VIFM_EV, config_dir); free(config_dir); return 1; }
/* Checks if file specified can be displayed. Used to filter some files, that * are hidden intentionally. Returns non-zero if file can be made visible. */ static int file_can_be_displayed(const char directory[], const char filename[]) { if(is_parent_dir(filename)) { return cfg_parent_dir_is_visible(is_root_dir(directory)); } return path_exists_at(directory, filename, DEREF); }
/* tries to use directory of executable file as configuration directory */ static int try_exe_directory_for_conf(void) { LOG_FUNC_ENTER; #ifndef _WIN32 return 0; #else char exe_dir[PATH_MAX]; GetModuleFileNameA(NULL, exe_dir, sizeof(exe_dir)); to_forward_slash(exe_dir); *strrchr(exe_dir, '/') = '\0'; if(!path_exists_at(exe_dir, VIFMRC)) return 0; env_set(VIFM_EV, exe_dir); return 1; #endif }
/* Tries to use directory of executable file as configuration directory. * Returns non-zero on success, otherwise zero is returned. */ static int try_exe_directory_for_conf(void) { LOG_FUNC_ENTER; char exe_dir[PATH_MAX + 1]; if(get_exe_dir(exe_dir, sizeof(exe_dir)) != 0) { return 0; } if(!path_exists_at(exe_dir, VIFMRC, DEREF)) { return 0; } env_set(VIFM_EV, exe_dir); return 1; }
void run_using_prog(FileView *view, const char prog_spec[], int dont_execute, int force_bg) { const dir_entry_t *const entry = &view->dir_entry[view->list_pos]; const int pause = skip_prefix(&prog_spec, "!!"); if(!path_exists_at(entry->origin, entry->name, DEREF)) { show_error_msg("Access Error", "File doesn't exist."); return; } if(fuse_is_mount_string(prog_spec)) { if(dont_execute) { view_current_file(view); } else { fuse_try_mount(view, prog_spec); } } else if(strcmp(prog_spec, VIFM_PSEUDO_CMD) == 0) { open_dir(view); } else if(strchr(prog_spec, '%') != NULL) { run_explicit_prog(prog_spec, pause, force_bg); } else { run_implicit_prog(view, prog_spec, pause, force_bg); } }
static void run_file(FileView *view, int dont_execute) { /* TODO: refactor this function run_file() */ char *typed_fname; const char *multi_prog_cmd; int undef; int same; dir_entry_t *entry; int no_multi_run; if(!view->dir_entry[view->list_pos].selected) { clean_selected_files(view); } typed_fname = get_typed_entry_fpath(get_current_entry(view)); multi_prog_cmd = ft_get_program(typed_fname); free(typed_fname); no_multi_run = !is_multi_run_compat(view, multi_prog_cmd); undef = 0; same = 1; entry = NULL; while(iter_selected_entries(view, &entry)) { char *typed_fname; const char *entry_prog_cmd; if(!path_exists_at(entry->origin, entry->name, DEREF)) { show_error_msgf("Broken Link", "Destination of \"%s\" link doesn't exist", entry->name); return; } typed_fname = get_typed_entry_fpath(entry); entry_prog_cmd = ft_get_program(typed_fname); free(typed_fname); if(entry_prog_cmd == NULL) { ++undef; continue; } no_multi_run += !is_multi_run_compat(view, entry_prog_cmd); if(multi_prog_cmd == NULL) { multi_prog_cmd = entry_prog_cmd; } else if(strcmp(entry_prog_cmd, multi_prog_cmd) != 0) { same = 0; } } if(!same && undef == 0 && no_multi_run) { show_error_msg("Run error", "Handlers of selected files are incompatible."); return; } if(undef > 0) { multi_prog_cmd = NULL; } /* Check for a filetype */ /* vi is set as the default for any extension without a program */ if(multi_prog_cmd == NULL) { run_with_defaults(view); return; } if(no_multi_run) { run_using_prog(view, multi_prog_cmd, dont_execute, 0); } else { run_selection_separately(view, dont_execute); } }
void read_info_file(int reread) { /* TODO: refactor this function read_info_file() */ FILE *fp; char info_file[PATH_MAX]; char *line = NULL, *line2 = NULL, *line3 = NULL, *line4 = NULL; snprintf(info_file, sizeof(info_file), "%s/vifminfo", cfg.config_dir); if((fp = fopen(info_file, "r")) == NULL) return; while((line = read_vifminfo_line(fp, line)) != NULL) { const char type = line[0]; const char *const line_val = line + 1; if(type == LINE_TYPE_COMMENT || type == '\0') continue; if(type == LINE_TYPE_OPTION) { if(line_val[0] == '[' || line_val[0] == ']') { FileView *v = curr_view; curr_view = (line_val[0] == '[') ? &lwin : &rwin; process_set_args(line_val + 1); curr_view = v; } else { process_set_args(line_val); } } else if(type == LINE_TYPE_FILETYPE) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { /* This is to prevent old builtin fake associations to be loaded. */ if(!ends_with(line2, "}" VIFM_PSEUDO_CMD)) { set_programs(line_val, line2, 0, curr_stats.env_type == ENVTYPE_EMULATOR_WITH_X); } } } else if(type == LINE_TYPE_XFILETYPE) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { set_programs(line_val, line2, 1, curr_stats.env_type == ENVTYPE_EMULATOR_WITH_X); } } else if(type == LINE_TYPE_FILEVIEWER) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { set_fileviewer(line_val, line2); } } else if(type == LINE_TYPE_COMMAND) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { char *cmdadd_cmd; if((cmdadd_cmd = format_str("command %s %s", line_val, line2)) != NULL) { exec_commands(cmdadd_cmd, curr_view, GET_COMMAND); free(cmdadd_cmd); } } } else if(type == LINE_TYPE_BOOKMARK) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { if((line3 = read_vifminfo_line(fp, line3)) != NULL) { add_bookmark(line_val[0], line2, line3); } } } else if(type == LINE_TYPE_ACTIVE_VIEW) { /* don't change active view on :restart command */ if(line_val[0] == 'r' && !reread) { update_view_title(&lwin); update_view_title(&rwin); curr_view = &rwin; other_view = &lwin; } } else if(type == LINE_TYPE_QUICK_VIEW_STATE) { const int i = atoi(line_val); curr_stats.view = (i == 1); } else if(type == LINE_TYPE_WIN_COUNT) { const int i = atoi(line_val); cfg.show_one_window = (i == 1); curr_stats.number_of_windows = (i == 1) ? 1 : 2; } else if(type == LINE_TYPE_SPLIT_ORIENTATION) { curr_stats.split = (line_val[0] == 'v') ? VSPLIT : HSPLIT; } else if(type == LINE_TYPE_SPLIT_POSITION) { curr_stats.splitter_pos = atof(line_val); } else if(type == LINE_TYPE_LWIN_SORT) { get_sort_info(&lwin, line_val); } else if(type == LINE_TYPE_RWIN_SORT) { get_sort_info(&rwin, line_val); } else if(type == LINE_TYPE_LWIN_HIST) { int pos; if(line_val[0] == '\0') { if(reread) continue; if(lwin.history_num > 0) strcpy(lwin.curr_dir, lwin.history[lwin.history_pos].dir); continue; } if((line2 = read_vifminfo_line(fp, line2)) == NULL) continue; pos = read_possible_possible_pos(fp); get_history(&lwin, reread, line_val, line2, pos); } else if(type == LINE_TYPE_RWIN_HIST) { int pos; if(line_val[0] == '\0') { if(reread) continue; if(rwin.history_num > 0) strcpy(rwin.curr_dir, rwin.history[rwin.history_pos].dir); continue; } if((line2 = read_vifminfo_line(fp, line2)) == NULL) continue; pos = read_possible_possible_pos(fp); get_history(&rwin, reread, line_val, line2, pos); } else if(type == LINE_TYPE_CMDLINE_HIST) { inc_history(&cfg.cmd_history, &cfg.cmd_history_num, &cfg.history_len); save_command_history(line_val); } else if(type == LINE_TYPE_SEARCH_HIST) { inc_history(&cfg.search_history, &cfg.search_history_num, &cfg.history_len); save_search_history(line_val); } else if(type == LINE_TYPE_PROMPT_HIST) { inc_history(&cfg.prompt_history, &cfg.prompt_history_num, &cfg.history_len); save_prompt_history(line_val); } else if(type == LINE_TYPE_DIR_STACK) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { if((line3 = read_vifminfo_line(fp, line3)) != NULL) { if((line4 = read_vifminfo_line(fp, line4)) != NULL) { push_to_dirstack(line_val, line2, line3 + 1, line4); } } } } else if(type == LINE_TYPE_TRASH) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { if(!path_exists_at(cfg.trash_dir, line_val)) continue; add_to_trash(line2, line_val); } } else if(type == LINE_TYPE_REG) { append_to_register(line_val[0], line_val + 1); } else if(type == LINE_TYPE_LWIN_FILT) { (void)replace_string(&lwin.prev_filter, line_val); set_filename_filter(&lwin, line_val); } else if(type == LINE_TYPE_RWIN_FILT) { (void)replace_string(&rwin.prev_filter, line_val); set_filename_filter(&rwin, line_val); } else if(type == LINE_TYPE_LWIN_FILT_INV) { const int i = atoi(line_val); lwin.invert = (i != 0); } else if(type == LINE_TYPE_RWIN_FILT_INV) { const int i = atoi(line_val); rwin.invert = (i != 0); } else if(type == LINE_TYPE_USE_SCREEN) { const int i = atoi(line_val); set_use_screen(i != 0); } else if(type == LINE_TYPE_COLORSCHEME) { strcpy(curr_stats.color_scheme, line_val); } else if(type == LINE_TYPE_LWIN_SPECIFIC || type == LINE_TYPE_RWIN_SPECIFIC) { FileView *view = (type == LINE_TYPE_LWIN_SPECIFIC) ? &lwin : &rwin; set_view_property(view, line_val[0], line_val + 1); } } free(line); free(line2); free(line3); free(line4); fclose(fp); }
/* Reads contents of the filename file as an info file and updates it with the * state of current instance. */ static void update_info_file(const char filename[]) { /* TODO: refactor this function update_info_file() */ FILE *fp; char ** list; int nlist = -1; char **ft = NULL, **fx = NULL , **fv = NULL, **cmds = NULL, **marks = NULL; char **lh = NULL, **rh = NULL, **cmdh = NULL, **srch = NULL, **regs = NULL; int *lhp = NULL, *rhp = NULL; size_t nlhp = 0, nrhp = 0; char **prompt = NULL, **trash = NULL; int nft = 0, nfx = 0, nfv = 0, ncmds = 0, nmarks = 0, nlh = 0, nrh = 0; int ncmdh = 0, nsrch = 0, nregs = 0, nprompt = 0, ntrash = 0; int i; if(cfg.vifm_info == 0) return; list = list_udf(); while(list[++nlist] != NULL); if((fp = fopen(filename, "r")) != NULL) { char *line = NULL, *line2 = NULL, *line3 = NULL; while((line = read_vifminfo_line(fp, line)) != NULL) { const char type = line[0]; const char *const line_val = line + 1; if(type == LINE_TYPE_COMMENT || type == '\0') continue; if(type == LINE_TYPE_FILETYPE) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { assoc_record_t prog; if(get_default_program_for_file(line_val, &prog)) { free_assoc_record(&prog); continue; } nft = add_to_string_array(&ft, nft, 2, line_val, line2); } } else if(type == LINE_TYPE_XFILETYPE) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { assoc_record_t x_prog; if(get_default_program_for_file(line_val, &x_prog)) { assoc_record_t console_prog; if(get_default_program_for_file(line_val, &console_prog)) { if(strcmp(x_prog.command, console_prog.command) == 0) { free_assoc_record(&console_prog); free_assoc_record(&x_prog); continue; } } free_assoc_record(&x_prog); } nfx = add_to_string_array(&fx, nfx, 2, line_val, line2); } } else if(type == LINE_TYPE_FILEVIEWER) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { if(get_viewer_for_file(line_val) != NULL) continue; nfv = add_to_string_array(&fv, nfv, 2, line_val, line2); } } else if(type == LINE_TYPE_COMMAND) { if(line_val[0] == '\0') continue; if((line2 = read_vifminfo_line(fp, line2)) != NULL) { const char *p = line_val; for(i = 0; i < nlist; i += 2) { int cmp = strcmp(list[i], p); if(cmp < 0) continue; if(cmp == 0) p = NULL; break; } if(p == NULL) continue; ncmds = add_to_string_array(&cmds, ncmds, 2, line_val, line2); } } else if(type == LINE_TYPE_LWIN_HIST) { if(line_val[0] == '\0') continue; if((line2 = read_vifminfo_line(fp, line2)) != NULL) { int pos; if(lwin.history_pos + nlh/2 == cfg.history_len - 1) continue; if(is_in_view_history(&lwin, line_val)) continue; pos = read_possible_possible_pos(fp); nlh = add_to_string_array(&lh, nlh, 2, line_val, line2); if(nlh/2 > nlhp) { nlhp = add_to_int_array(&lhp, nlhp, pos); nlhp = MIN(nlh/2, nlhp); } } } else if(type == LINE_TYPE_RWIN_HIST) { if(line_val[0] == '\0') continue; if((line2 = read_vifminfo_line(fp, line2)) != NULL) { int pos; if(rwin.history_pos + nrh/2 == cfg.history_len - 1) continue; if(is_in_view_history(&rwin, line_val)) continue; pos = read_possible_possible_pos(fp); nrh = add_to_string_array(&rh, nrh, 2, line_val, line2); if(nrh/2 > nrhp) { nrhp = add_to_int_array(&rhp, nrhp, pos); nrhp = MIN(nrh/2, nrhp); } } } else if(type == LINE_TYPE_BOOKMARK) { const char mark = line_val[0]; if(line_val[1] != '\0') { LOG_ERROR_MSG("Expected end of line, but got: %s", line_val + 1); } if((line2 = read_vifminfo_line(fp, line2)) != NULL) { if((line3 = read_vifminfo_line(fp, line3)) != NULL) { const char mark_str[] = { mark, '\0' }; if(!char_is_one_of(valid_bookmarks, mark)) continue; if(!is_bookmark_empty(mark2index(mark))) continue; nmarks = add_to_string_array(&marks, nmarks, 3, mark_str, line2, line3); } } } else if(type == LINE_TYPE_TRASH) { if((line2 = read_vifminfo_line(fp, line2)) != NULL) { if(!path_exists_at(cfg.trash_dir, line_val)) continue; if(is_in_trash(line_val)) continue; ntrash = add_to_string_array(&trash, ntrash, 2, line_val, line2); } } else if(type == LINE_TYPE_CMDLINE_HIST) { if(cfg.cmd_history_num >= 0 && is_in_string_array(cfg.cmd_history, cfg.cmd_history_num + 1, line_val)) continue; ncmdh = add_to_string_array(&cmdh, ncmdh, 1, line_val); } else if(type == LINE_TYPE_SEARCH_HIST) { if(cfg.search_history_num >= 0 && is_in_string_array(cfg.search_history, cfg.search_history_num + 1, line_val)) continue; nsrch = add_to_string_array(&srch, nsrch, 1, line_val); } else if(type == LINE_TYPE_PROMPT_HIST) { if(cfg.prompt_history_num >= 0 && is_in_string_array(cfg.prompt_history, cfg.prompt_history_num + 1, line_val)) continue; nprompt = add_to_string_array(&prompt, nprompt, 1, line_val); } else if(type == LINE_TYPE_REG) { if(register_exists(line_val[0])) continue; nregs = add_to_string_array(®s, nregs, 1, line); } } free(line); free(line2); free(line3); fclose(fp); } if((fp = fopen(filename, "w")) == NULL) { return; } fprintf(fp, "# You can edit this file by hand, but it's recommended not to do that.\n"); if(cfg.vifm_info & VIFMINFO_OPTIONS) { fputs("\n# Options:\n", fp); fprintf(fp, "=aproposprg=%s\n", escape_spaces(cfg.apropos_prg)); fprintf(fp, "=%sautochpos\n", cfg.auto_ch_pos ? "" : "no"); fprintf(fp, "=columns=%d\n", cfg.columns); fprintf(fp, "=%sconfirm\n", cfg.confirm ? "" : "no"); fprintf(fp, "=cpoptions=%s%s%s\n", cfg.filter_inverted_by_default ? "f" : "", cfg.selection_is_primary ? "s" : "", cfg.tab_switches_pane ? "t" : ""); fprintf(fp, "=%sfastrun\n", cfg.fast_run ? "" : "no"); fprintf(fp, "=findprg=%s\n", escape_spaces(cfg.find_prg)); fprintf(fp, "=%sfollowlinks\n", cfg.follow_links ? "" : "no"); fprintf(fp, "=fusehome=%s\n", escape_spaces(cfg.fuse_home)); fprintf(fp, "=%sgdefault\n", cfg.gdefault ? "" : "no"); fprintf(fp, "=grepprg=%s\n", escape_spaces(cfg.grep_prg)); fprintf(fp, "=history=%d\n", cfg.history_len); fprintf(fp, "=%shlsearch\n", cfg.hl_search ? "" : "no"); fprintf(fp, "=%siec\n", cfg.use_iec_prefixes ? "" : "no"); fprintf(fp, "=%signorecase\n", cfg.ignore_case ? "" : "no"); fprintf(fp, "=%sincsearch\n", cfg.inc_search ? "" : "no"); fprintf(fp, "=%slaststatus\n", cfg.last_status ? "" : "no"); fprintf(fp, "=lines=%d\n", cfg.lines); fprintf(fp, "=locateprg=%s\n", escape_spaces(cfg.locate_prg)); fprintf(fp, "=rulerformat=%s\n", escape_spaces(cfg.ruler_format)); fprintf(fp, "=%srunexec\n", cfg.auto_execute ? "" : "no"); fprintf(fp, "=%sscrollbind\n", cfg.scroll_bind ? "" : "no"); fprintf(fp, "=scrolloff=%d\n", cfg.scroll_off); fprintf(fp, "=shell=%s\n", escape_spaces(cfg.shell)); fprintf(fp, "=shortmess=%s\n", cfg.trunc_normal_sb_msgs ? "T" : ""); #ifndef _WIN32 fprintf(fp, "=slowfs=%s\n", escape_spaces(cfg.slow_fs_list)); #endif fprintf(fp, "=%ssmartcase\n", cfg.smart_case ? "" : "no"); fprintf(fp, "=%ssortnumbers\n", cfg.sort_numbers ? "" : "no"); fprintf(fp, "=statusline=%s\n", escape_spaces(cfg.status_line)); fprintf(fp, "=tabstop=%d\n", cfg.tab_stop); fprintf(fp, "=timefmt=%s\n", escape_spaces(cfg.time_format + 1)); fprintf(fp, "=timeoutlen=%d\n", cfg.timeout_len); fprintf(fp, "=%strash\n", cfg.use_trash ? "" : "no"); fprintf(fp, "=undolevels=%d\n", cfg.undo_levels); fprintf(fp, "=vicmd=%s%s\n", escape_spaces(cfg.vi_command), cfg.vi_cmd_bg ? " &" : ""); fprintf(fp, "=vixcmd=%s%s\n", escape_spaces(cfg.vi_x_command), cfg.vi_cmd_bg ? " &" : ""); fprintf(fp, "=%swrapscan\n", cfg.wrap_scan ? "" : "no"); fprintf(fp, "=[viewcolumns=%s\n", escape_spaces(lwin.view_columns)); fprintf(fp, "=]viewcolumns=%s\n", escape_spaces(rwin.view_columns)); fprintf(fp, "=[%slsview\n", lwin.ls_view ? "" : "no"); fprintf(fp, "=]%slsview\n", rwin.ls_view ? "" : "no"); fprintf(fp, "%s", "=dotdirs="); if(cfg.dot_dirs & DD_ROOT_PARENT) fprintf(fp, "%s", "rootparent,"); if(cfg.dot_dirs & DD_NONROOT_PARENT) fprintf(fp, "%s", "nonrootparent,"); fprintf(fp, "\n"); fprintf(fp, "=classify=%s\n", escape_spaces(classify_to_str())); fprintf(fp, "=vifminfo=options"); if(cfg.vifm_info & VIFMINFO_FILETYPES) fprintf(fp, ",filetypes"); if(cfg.vifm_info & VIFMINFO_COMMANDS) fprintf(fp, ",commands"); if(cfg.vifm_info & VIFMINFO_BOOKMARKS) fprintf(fp, ",bookmarks"); if(cfg.vifm_info & VIFMINFO_TUI) fprintf(fp, ",tui"); if(cfg.vifm_info & VIFMINFO_DHISTORY) fprintf(fp, ",dhistory"); if(cfg.vifm_info & VIFMINFO_STATE) fprintf(fp, ",state"); if(cfg.vifm_info & VIFMINFO_CS) fprintf(fp, ",cs"); if(cfg.vifm_info & VIFMINFO_SAVEDIRS) fprintf(fp, ",savedirs"); if(cfg.vifm_info & VIFMINFO_CHISTORY) fprintf(fp, ",chistory"); if(cfg.vifm_info & VIFMINFO_SHISTORY) fprintf(fp, ",shistory"); if(cfg.vifm_info & VIFMINFO_PHISTORY) fprintf(fp, ",phistory"); if(cfg.vifm_info & VIFMINFO_DIRSTACK) fprintf(fp, ",dirstack"); if(cfg.vifm_info & VIFMINFO_REGISTERS) fprintf(fp, ",registers"); fprintf(fp, "\n"); fprintf(fp, "=%svimhelp\n", cfg.use_vim_help ? "" : "no"); fprintf(fp, "=%swildmenu\n", cfg.wild_menu ? "" : "no"); fprintf(fp, "=%swrap\n", cfg.wrap_quick_view ? "" : "no"); } if(cfg.vifm_info & VIFMINFO_FILETYPES) { fputs("\n# Filetypes:\n", fp); for(i = 0; i < filetypes.count; i++) { int j; assoc_t ft_assoc = filetypes.list[i]; for(j = 0; j < ft_assoc.records.count; j++) { assoc_record_t ft_record = ft_assoc.records.list[j]; /* The type check is to prevent builtin fake associations to be written * into vifminfo file */ if(ft_record.command[0] != '\0' && ft_record.type != ART_BUILTIN) { fprintf(fp, ".%s\n\t{%s}%s\n", ft_assoc.pattern, ft_record.description, ft_record.command); } } } for(i = 0; i < nft; i += 2) fprintf(fp, ".%s\n\t%s\n", ft[i], ft[i + 1]); fputs("\n# X Filetypes:\n", fp); for(i = 0; i < xfiletypes.count; i++) { int j; assoc_t xft_assoc = xfiletypes.list[i]; for(j = 0; j < xft_assoc.records.count; j++) { assoc_record_t xft_record = xft_assoc.records.list[j]; if(xft_record.command[0] != '\0') { fprintf(fp, "x%s\n\t{%s}%s\n", xft_assoc.pattern, xft_record.description, xft_record.command); } } } for(i = 0; i < nfx; i += 2) fprintf(fp, ".%s\n\t%s\n", fx[i], fx[i + 1]); fputs("\n# Fileviewers:\n", fp); for(i = 0; i < fileviewers.count; i++) { int j; assoc_t fv_assoc = fileviewers.list[i]; for(j = 0; j < fv_assoc.records.count; j++) { assoc_record_t fv_record = fileviewers.list[i].records.list[j]; if(fv_record.command[0] != '\0') { fprintf(fp, ",%s\n\t%s\n", fv_assoc.pattern, fv_record.command); } } } for(i = 0; i < nfv; i += 2) fprintf(fp, ",%s\n\t%s\n", fv[i], fv[i + 1]); } if(cfg.vifm_info & VIFMINFO_COMMANDS) { fputs("\n# Commands:\n", fp); for(i = 0; list[i] != NULL; i += 2) fprintf(fp, "!%s\n\t%s\n", list[i], list[i + 1]); for(i = 0; i < ncmds; i += 2) fprintf(fp, "!%s\n\t%s\n", cmds[i], cmds[i + 1]); } if(cfg.vifm_info & VIFMINFO_BOOKMARKS) { int len = init_active_bookmarks(valid_bookmarks); fputs("\n# Bookmarks:\n", fp); for(i = 0; i < len; i++) { int j = active_bookmarks[i]; if(is_spec_bookmark(j)) continue; fprintf(fp, "'%c\n\t%s\n\t", index2mark(j), bookmarks[j].directory); fprintf(fp, "%s\n", bookmarks[j].file); } for(i = 0; i < nmarks; i += 3) fprintf(fp, "'%c\n\t%s\n\t%s\n", marks[i][0], marks[i + 1], marks[i + 2]); } if(cfg.vifm_info & VIFMINFO_TUI) { fputs("\n# TUI:\n", fp); fprintf(fp, "a%c\n", (curr_view == &rwin) ? 'r' : 'l'); fprintf(fp, "q%d\n", curr_stats.view); fprintf(fp, "v%d\n", curr_stats.number_of_windows); fprintf(fp, "o%c\n", (curr_stats.split == VSPLIT) ? 'v' : 'h'); fprintf(fp, "m%d\n", curr_stats.splitter_pos); put_sort_info(fp, 'l', &lwin); put_sort_info(fp, 'r', &rwin); } if((cfg.vifm_info & VIFMINFO_DHISTORY) && cfg.history_len > 0) { save_view_history(&lwin, NULL, NULL, -1); fputs("\n# Left window history (oldest to newest):\n", fp); for(i = 0; i < nlh; i += 2) fprintf(fp, "d%s\n\t%s\n%d\n", lh[i], lh[i + 1], lhp[i/2]); for(i = 0; i <= lwin.history_pos; i++) fprintf(fp, "d%s\n\t%s\n%d\n", lwin.history[i].dir, lwin.history[i].file, lwin.history[i].rel_pos); if(cfg.vifm_info & VIFMINFO_SAVEDIRS) fprintf(fp, "d\n"); save_view_history(&rwin, NULL, NULL, -1); fputs("\n# Right window history (oldest to newest):\n", fp); for(i = 0; i < nrh; i += 2) fprintf(fp, "D%s\n\t%s\n%d\n", rh[i], rh[i + 1], rhp[i/2]); for(i = 0; i <= rwin.history_pos; i++) fprintf(fp, "D%s\n\t%s\n%d\n", rwin.history[i].dir, rwin.history[i].file, rwin.history[i].rel_pos); if(cfg.vifm_info & VIFMINFO_SAVEDIRS) fprintf(fp, "D\n"); } if(cfg.vifm_info & VIFMINFO_CHISTORY) { fputs("\n# Command line history (oldest to newest):\n", fp); for(i = 0; i < MIN(ncmdh, cfg.history_len - cfg.cmd_history_num); i++) fprintf(fp, ":%s\n", cmdh[i]); for(i = cfg.cmd_history_num; i >= 0; i--) fprintf(fp, ":%s\n", cfg.cmd_history[i]); } if(cfg.vifm_info & VIFMINFO_SHISTORY) { fputs("\n# Search history (oldest to newest):\n", fp); for(i = 0; i < nsrch; i++) fprintf(fp, "/%s\n", srch[i]); for(i = cfg.search_history_num; i >= 0; i--) fprintf(fp, "/%s\n", cfg.search_history[i]); } if(cfg.vifm_info & VIFMINFO_PHISTORY) { fputs("\n# Prompt history (oldest to newest):\n", fp); for(i = 0; i < nprompt; i++) fprintf(fp, "p%s\n", prompt[i]); for(i = cfg.prompt_history_num; i >= 0; i--) fprintf(fp, "p%s\n", cfg.prompt_history[i]); } if(cfg.vifm_info & VIFMINFO_REGISTERS) { fputs("\n# Registers:\n", fp); for(i = 0; i < nregs; i++) fprintf(fp, "%s\n", regs[i]); for(i = 0; valid_registers[i] != '\0'; i++) { int j; registers_t *reg = find_register(valid_registers[i]); if(reg == NULL) continue; for(j = 0; j < reg->num_files; j++) { if(reg->files[j] == NULL) continue; fprintf(fp, "\"%c%s\n", reg->name, reg->files[j]); } } } if(cfg.vifm_info & VIFMINFO_DIRSTACK) { fputs("\n# Directory stack (oldest to newest):\n", fp); for(i = 0; i < stack_top; i++) { fprintf(fp, "S%s\n\t%s\n", stack[i].lpane_dir, stack[i].lpane_file); fprintf(fp, "S%s\n\t%s\n", stack[i].rpane_dir, stack[i].rpane_file); } } fputs("\n# Trash content:\n", fp); for(i = 0; i < nentries; i++) fprintf(fp, "t%s\n\t%s\n", trash_list[i].trash_name, trash_list[i].path); for(i = 0; i < ntrash; i += 2) fprintf(fp, "t%s\n\t%s\n", trash[i], trash[i + 1]); if(cfg.vifm_info & VIFMINFO_STATE) { fputs("\n# State:\n", fp); fprintf(fp, "f%s\n", lwin.filename_filter); fprintf(fp, "i%d\n", lwin.invert); fprintf(fp, "[.%d\n", lwin.hide_dot); fprintf(fp, "F%s\n", rwin.filename_filter); fprintf(fp, "I%d\n", rwin.invert); fprintf(fp, "].%d\n", rwin.hide_dot); fprintf(fp, "s%d\n", cfg.use_screen); } if(cfg.vifm_info & VIFMINFO_CS) { fputs("\n# Color scheme:\n", fp); fprintf(fp, "c%s\n", cfg.cs.name); } fclose(fp); free_string_array(ft, nft); free_string_array(fv, nfv); free_string_array(fx, nfx); free_string_array(cmds, ncmds); free_string_array(marks, nmarks); free_string_array(list, nlist); free_string_array(lh, nlh); free_string_array(rh, nrh); free(lhp); free(rhp); free_string_array(cmdh, ncmdh); free_string_array(srch, nsrch); free_string_array(regs, nregs); free_string_array(prompt, nprompt); free_string_array(trash, ntrash); }