Пример #1
0
/* Converts old versions of configuration files to new ones.  Terminates
 * application with error message on error or when user chooses to do not update
 * anything. */
static void
convert_configs(void)
{
	int vifm_like_mode;

	if(!query_user_menu("Configuration update", "Your vifmrc will be "
			"upgraded to a new format.  Your current configuration will be copied "
			"before performing any changes, but if you don't want to take the risk "
			"and would like to make one more copy say No to exit vifm.  Continue?"))
	{
#ifdef _WIN32
		system("cls");
#endif
		endwin();
		exit(0);
	}

	vifm_like_mode = !query_user_menu("Configuration update", "This version of "
			"vifm is able to save changes in the configuration files automatically "
			"when quitting, as it was possible in older versions.  It is from now "
			"on recommended though, to save permanent changes manually in the "
			"configuration file as it is done in vi/vim.  Do you want vifm to "
			"behave like vi/vim?");

	if(run_converter(vifm_like_mode) != 0)
	{
		endwin();
		fputs("Problems with running vifmrc-converter\n", stderr);
		exit(0);
	}

	show_error_msg("Configuration update", "Your vifmrc has been upgraded to "
			"new format, you can find its old version in " CONF_DIR "/vifmrc.bak.  "
			"vifm will not write anything to vifmrc, and all variables that are "
			"saved between runs of vifm are stored in " CONF_DIR "/vifminfo now "
			"(you can edit it by hand, but do it carefully).  You can control what "
			"vifm stores in vifminfo with 'vifminfo' option.");
}
Пример #2
0
static int
op_remove(void *data, const char *src, const char *dst)
{
	if(cfg.confirm && !curr_stats.confirmed)
	{
		curr_stats.confirmed = query_user_menu("Permanent deletion",
				"Are you sure? If you undoing a command and want to see file names, "
				"use :undolist! command");
		if(!curr_stats.confirmed)
			return SKIP_UNDO_REDO_OPERATION;
	}

	return op_removesl(data, src, dst);
}
Пример #3
0
void
write_color_scheme_file()
{
	FILE *fp;
	char config_file[PATH_MAX];
	int x, y;
	char buf[128];
	char fg_buf[64];
	char bg_buf[64];
	struct stat stat_buf;

	snprintf(config_file, sizeof(config_file), "%s/colorschemes",
		   	cfg.config_dir);

	if(stat(config_file, &stat_buf) == 0) 
	{
		if (stat_buf.st_mtime > curr_stats.colorscheme_file_mtime)
		{
			if (! query_user_menu(" Colorscheme file has been modified ",
				 "File has been modified would you still like to write to file? "))
				return;
		}
	}


	if((fp = fopen(config_file, "w")) == NULL)
		return;

	fprintf(fp, "# You can edit this file by hand.\n");
	fprintf(fp, "# The # character at the beginning of a line comments out the line.\n");
	fprintf(fp, "# Blank lines are ignored.\n\n");

	fprintf(fp, "# The Default color scheme is used for any directory that does not have\n");
	fprintf(fp, "# a specified scheme.  A color scheme set for a base directory will also\n");
	fprintf(fp, "# be used for the sub directories.\n\n");

	fprintf(fp, "# The standard ncurses colors are: \n");
 	fprintf(fp, "# Default = -1 used for fake transparency\n");
	fprintf(fp, "# Black = 0\n");
	fprintf(fp, "# Red = 1\n");
	fprintf(fp, "# Green = 2\n");
	fprintf(fp, "# Yellow = 3\n");
	fprintf(fp, "# Blue = 4\n");
	fprintf(fp, "# Magenta = 5\n");
	fprintf(fp, "# Cyan = 6\n");
	fprintf(fp, "# White = 7\n\n");

	fprintf(fp, "# COLORSCHEME=OneWordDescription\n");
	fprintf(fp, "# DIRECTORY=/Full/Path/To/Base/Directory\n");
	fprintf(fp, "# COLOR=Window_name=foreground_color_number=background_color_number\n\n");


	for(x = 0; x < cfg.color_scheme_num; x++)
	{
		fprintf(fp, "\nCOLORSCHEME=%s\n", col_schemes[x].name);
		fprintf(fp, "DIRECTORY=%s\n", col_schemes[x].dir);

		for(y = 0; y < 12; y++)
		{

			while(col_schemes[x].color[y].name > 11)
			{
				col_schemes[x].color[y].name =
				   	col_schemes[x].color[y].name - 12;
			}

			switch(col_schemes[x].color[y].name)
			{
				case 0:
					snprintf(buf, sizeof(buf), "MENU");
					break;
				case 1:
					snprintf(buf, sizeof(buf), "BORDER");
					break;
				case 2:
					snprintf(buf, sizeof(buf), "WIN");
					break;
				case 3:
					snprintf(buf, sizeof(buf), "STATUS_BAR");
					break;
				case 4:
					snprintf(buf, sizeof(buf), "CURR_LINE");
					break;
				case 5:
					snprintf(buf, sizeof(buf), "DIRECTORY");
					break;
				case 6:
					snprintf(buf, sizeof(buf), "LINK");
					break;
				case 7:
					snprintf(buf, sizeof(buf), "SOCKET");
					break;
				case 8:
					snprintf(buf, sizeof(buf), "DEVICE");
					break;
				case 9:
					snprintf(buf, sizeof(buf), "EXECUTABLE");
					break;
				case 10:
					snprintf(buf, sizeof(buf), "SELECTED");
					break;
				case 11:
					snprintf(buf, sizeof(buf), "CURRENT");
					break;
				default:
					snprintf(buf, sizeof(buf), "# Unknown");
					break;
			};

			switch (col_schemes[x].color[y].fg)
			{
				case -1:
					snprintf(fg_buf, sizeof(fg_buf), "default");
					break;
				case 0:
					snprintf(fg_buf, sizeof(fg_buf), "black");
					break;
				case 1:
					snprintf(fg_buf, sizeof(fg_buf), "red");
					break;
				case 2:
					snprintf(fg_buf, sizeof(fg_buf), "green");
					break;
				case 3:
					snprintf(fg_buf, sizeof(fg_buf), "yellow");
					break;
				case 4:
					snprintf(fg_buf, sizeof(fg_buf), "blue");
					break;
				case 5:
					snprintf(fg_buf, sizeof(fg_buf), "magenta");
					break;
				case 6:
					snprintf(fg_buf, sizeof(fg_buf), "cyan");
					break;
				case 7:
					snprintf(fg_buf, sizeof(fg_buf), "white");
					break;
				default:
					snprintf(fg_buf, sizeof(fg_buf), "-1");
					break;
			}

			switch (col_schemes[x].color[y].bg)
			{
 				case -1:
 					snprintf(bg_buf, sizeof(bg_buf), "default");
 					break;
				case 0:
					snprintf(bg_buf, sizeof(bg_buf), "black");
					break;
				case 1:
					snprintf(bg_buf, sizeof(bg_buf), "red");
					break;
				case 2:
					snprintf(bg_buf, sizeof(bg_buf), "green");
					break;
				case 3:
					snprintf(bg_buf, sizeof(bg_buf), "yellow");
					break;
				case 4:
					snprintf(bg_buf, sizeof(bg_buf), "blue");
					break;
				case 5:
					snprintf(bg_buf, sizeof(bg_buf), "magenta");
					break;
				case 6:
					snprintf(bg_buf, sizeof(bg_buf), "cyan");
					break;
				case 7:
					snprintf(bg_buf, sizeof(bg_buf), "white");
					break;
				default:
					snprintf(bg_buf, sizeof(bg_buf), "-1");
					break;
			}

			fprintf(fp, "COLOR=%s=%s=%s\n", buf, fg_buf, bg_buf);

		}
	}

	fclose(fp);
	return;
}
Пример #4
0
void
write_config_file(void)
{
	FILE *fp;
	int x = 0;
	char config_file[PATH_MAX];
	struct stat stat_buf;


	/* None of the user settings have changed. */
	if ((!curr_stats.setting_change) && (!cfg.using_default_config))
		return;

	curr_stats.getting_input = 1;

	snprintf(config_file, sizeof(config_file), "%s/vifmrc", cfg.config_dir);

	if(stat(config_file, &stat_buf) == 0) 
	{
		if ((stat_buf.st_mtime > curr_stats.config_file_mtime) &&
				(!cfg.using_default_config))
		{
			if (! query_user_menu(" Vifmrc file has been modified ",
				 "File has been modified would you still like to write to file? "))
				return;
		}
	}

	if((fp = fopen(config_file, "w")) == NULL)
		return;

	fprintf(fp, "# You can edit this file by hand.\n");
	fprintf(fp, "# The # character at the beginning of a line comments out the line.\n");
	fprintf(fp, "# Blank lines are ignored.\n");
	fprintf(fp, "# The basic format for each item is shown with an example.\n");
	fprintf(fp,
		"# The '=' character is used to separate fields within a single line.\n");
	fprintf(fp, "# Most settings are true = 1 or false = 0.\n");
	
	fprintf(fp, "\n# This is the actual command used to start vi.  The default is vi.\n");
	fprintf(fp,
			"# If you would like to use another vi clone such as Vim, Elvis, or Vile\n");
	fprintf(fp, "# you will need to change this setting.\n");
	fprintf(fp, "\nVI_COMMAND=%s", cfg.vi_command);
	fprintf(fp, "\n# VI_COMMAND=vim");
	fprintf(fp, "\n# VI_COMMAND=elvis -G termcap");
	fprintf(fp, "\n# VI_COMMAND=vile");
	fprintf(fp, "\n");
	fprintf(fp, "\n# Trash Directory\n");
	fprintf(fp, "# The default is to move files that are deleted with dd or :d to\n");
	fprintf(fp, "# the trash directory.  1 means use the trash directory 0 means\n");
	fprintf(fp, "# just use rm.  If you change this you will not be able to move\n");
	fprintf(fp, "# files by deleting them and then using p to put the file in the new location.\n");
	fprintf(fp, "# I recommend not changing this until you are familiar with vifm.\n");
	fprintf(fp, "# This probably shouldn't be an option.\n");
	fprintf(fp, "\nUSE_TRASH=%d\n", cfg.use_trash);

	fprintf(fp, "\n# Show only one Window\n");
	fprintf(fp, "# If you would like to start vifm with only one window set this to 1\n");
	fprintf(fp, "\nUSE_ONE_WINDOW=%d\n", curr_stats.number_of_windows == 1 ? 1 : 0);

	fprintf(fp, "\n# Screen configuration.  If you would like to use vifm with\n"); 
	fprintf(fp, "# the screen program set this to 1.\n");
	fprintf(fp, "\nUSE_SCREEN=%d\n", cfg.use_screen);

	fprintf(fp, "\n# 1 means use color if the terminal supports it.\n");
	fprintf(fp, "# 0 means don't use color even if supported.\n");

	fprintf(fp, "\n# This is how many files to show in the directory history menu.\n");
	fprintf(fp, "\nHISTORY_LENGTH=%d\n", cfg.history_len);

	fprintf(fp, "\n# The sort type is how the files will be sorted in the file listing.\n");
	fprintf(fp, "# Sort by File Extension = 0\n");
	fprintf(fp, "# Sort by File Name = 1\n");
	fprintf(fp, "# Sort by Group ID = 2\n");
	fprintf(fp, "# Sort by Group Name = 3\n");
	fprintf(fp, "# Sort by Mode = 4\n");
	fprintf(fp, "# Sort by Owner ID = 5\n");
	fprintf(fp, "# Sort by Owner Name = 6\n");
	fprintf(fp, "# Sort by Size (Ascending) = 7\n");
	fprintf(fp, "# Sort by Size (Descending) = 8\n");

	fprintf(fp, "# Sort by Time Accessed =9\n");
	fprintf(fp, "# Sort by Time Changed =10\n");
	fprintf(fp, "# Sort by Time Modified =11\n");
	fprintf(fp, "# This can be set with the :sort command in vifm.\n");
	fprintf(fp, "\nLEFT_WINDOW_SORT_TYPE=%d\n", lwin.sort_type);
	fprintf(fp, "\nRIGHT_WINDOW_SORT_TYPE=%d\n", rwin.sort_type);

	fprintf(fp, "\n# The regular expression used to filter files out of\n");
	fprintf(fp, "# the directory listings.\n");
	fprintf(fp, "# LWIN_FILTER=\\.o$ and LWIN_INVERT=1 would filter out all\n");
	fprintf(fp, "# of the .o files from the directory listing. LWIN_INVERT=0\n");
	fprintf(fp, "# would show only the .o files\n");
	fprintf(fp, "\nLWIN_FILTER=%s\n", lwin.filename_filter);
	fprintf(fp, "LWIN_INVERT=%d\n", lwin.invert);
	fprintf(fp, "RWIN_FILTER=%s\n", rwin.filename_filter);
	fprintf(fp, "RWIN_INVERT=%d\n", rwin.invert);

	fprintf(fp, "\n# If you installed the vim.txt help file change this to 1.\n");
	fprintf(fp, "# If would rather use a plain text help file set this to 0.\n");
	fprintf(fp, "\nUSE_VIM_HELP=%d\n", cfg.use_vim_help);

	fprintf(fp, "\n# If you would like to run an executable file when you \n");
	fprintf(fp, "# press return on the file name set this to 1.\n");
	fprintf(fp, "\nRUN_EXECUTABLE=%d\n", cfg.auto_execute);

	fprintf(fp, "\n# BOOKMARKS=mark=/full/directory/path=filename\n\n");
	for(x = 0; x < NUM_BOOKMARKS; x++)
	{
		if (is_bookmark(x))
		{
			fprintf(fp, "BOOKMARKS=%c=%s=%s\n",
					index2mark(x),
					bookmarks[x].directory, bookmarks[x].file);
		}
	}

	fprintf(fp, "\n# COMMAND=command_name=action\n");
	fprintf(fp, "# The following macros can be used in a command\n");
	fprintf(fp, "# %%a is replaced with the user arguments.\n");
	fprintf(fp, "# %%f the current selected file, or files.\n");
	fprintf(fp, "# %%F the current selected file, or files in the other directoy.\n");
	fprintf(fp, "# %%d the current directory name.\n");
	fprintf(fp, "# %%D the other window directory name.\n");
	fprintf(fp, "# %%m run the command in a menu window\n\n");
	for(x = 0; x < cfg.command_num; x++)
	{
		fprintf(fp, "COMMAND=%s=%s\n", command_list[x].name, 
				command_list[x].action);
	}

	fprintf(fp, "\n# The file type is for the default programs to be used with\n");
	fprintf(fp, "# a file extension. \n");
	fprintf(fp, "# FILETYPE=description=extension1,extension2=defaultprogram, program2\n");
	fprintf(fp, "# FILETYPE=Web=html,htm,shtml=links,mozilla,elvis\n");
	fprintf(fp, "# would set links as the default program for .html .htm .shtml files\n");
	fprintf(fp, "# The other programs for the file type can be accessed with the :file command\n");
	fprintf(fp, "# The command macros %%f, %%F, %%d, %%F may be used in the commands.\n");
	fprintf(fp, "# The %%a macro is ignored.  To use a %% you must put %%%%.\n\n");
	for(x = 0; x < cfg.filetypes_num; x++)
	{
		fprintf(fp, "FILETYPE=%s=%s=%s\n", filetypes[x].type, filetypes[x].ext, filetypes[x].programs);
	}

/*_SZ_BEGIN_*/
	fprintf(fp, "\n# For automated FUSE mounts, you must register an extension with FILETYPE=..\n"); 
	fprintf(fp, "# in the following format:\n");
	fprintf(fp, "# FILETYPE=description=extensions=FUSE_MOUNT|some_mount_command using %%SOURCE_FILE and %%DESTINATION_DIR variables\n");
	fprintf(fp, "# %%SOURCE_FILE and %%DESTINATION_DIR are filled in by vifm at runtime.\n");
	fprintf(fp, "# A sample line might look like this:\n");
	fprintf(fp, "# FILETYPE=FuseZipMount=zip,jar,war,ear=FUSE_MOUNT|fuse-zip %%SOURCE_FILE %%DESTINATION_DIR\n\n");
	fprintf(fp, "# The FUSE_HOME directory will be used as a root dir for all FUSE mounts.\n");
	fprintf(fp, "# Unless it exists with write/exec permissions set, vifm will attempt to create it.\n");
	fprintf(fp, "\nFUSE_HOME=%s\n", cfg.fuse_home);
/*_SZ_END_*/

	fclose(fp);

	curr_stats.getting_input = 0;
}