Example #1
0
static void
save_to_history(const char str[])
{
	save_command_history(str);
	save_search_history(str);
	save_prompt_history(str);

	save_view_history(&lwin, str, str + 1, 0);
	save_view_history(&rwin, str, str + 1, 0);
}
Example #2
0
/* Saves command-line input into appropriate history.  input can be NULL, in
 * which case it's ignored. */
static void
save_input_to_history(const keys_info_t *keys_info, const char input[])
{
	if(input == NULL)
	{
		return;
	}
	else if(input_stat.search_mode)
	{
		save_search_history(input);
	}
	else if(sub_mode == CMD_SUBMODE)
	{
		if(!keys_info->mapped && !keys_info->recursive)
		{
			save_command_history(input);
		}
	}
	else if(sub_mode == PROMPT_SUBMODE)
	{
		save_prompt_history(input);
	}
}
Example #3
0
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);
}