Commit 310b6079 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Add %F and %N printf sequences for escaped file name (closes #77)

parent 919298ad
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
git HEAD

    * Add %F and %N format specifiers, containing an escaped version of %f/%n.
      Example: %F for foo'bar".jpg will return 'foo'"'"'bar".jpg'
      <https://github.com/derf/feh/issues/77>

Mon, 02 Jan 2012 11:54:01 +0100  Daniel Friesel <derf@finalrewind.org>

* Release v2.2
+11 −2
Original line number Diff line number Diff line
@@ -744,6 +744,11 @@ file
.
Image path/filename
.
.It %F
.
Escaped image path/filename
.Pq for use in shell commands
.
.It %h
.
Image height
@@ -760,6 +765,10 @@ Current mode
.
Image name
.
.It \&%N
.
Escaped image name
.
.It %p
.
Number of image pixels
@@ -1329,7 +1338,7 @@ Open each image in /opt/images/holidays in its own window
Show the images in .../presentation, sorted by name, in fullscreen,
automatically change to the next image after 5 seconds
.
.It feh -rSwidth -A Qo mv '%f' ~/images/'%n' Qc /opt/images
.It feh -rSwidth -A Qo mv %F ~/images/\&%N Qc /opt/images
.
View all images in /opt/images and below, sorted by width, move an image to
~/image/image_name when enter is pressed
@@ -1343,7 +1352,7 @@ images are still in the slideshow and can be viewed normally
.
Same as above
.
.It feh --info \&"exifgrep '\&(Model\&|DateTimeOriginal\&|FNumber\&|ISO\&|Flash\&)' '%f' \&| cut -d \&. -f 4-\&" \&.
.It feh --info \&"exifgrep '\&(Model\&|DateTimeOriginal\&|FNumber\&|ISO\&|Flash\&)' %F \&| cut -d \&. -f 4-\&" \&.
.
Show some EXIF information, extracted by exifprobe/exifgrep
.
+31 −0
Original line number Diff line number Diff line
@@ -381,6 +381,29 @@ void feh_action_run(feh_file * file, char *action)
	return;
}

char *shell_escape(char *input)
{
	static char ret[1024];
	unsigned int out = 0, in = 0;

	ret[out++] = '\'';
	for (in = 0; input[in] && (out < (sizeof(ret) - 7)); in++) {
		if (input[in] == '\'') {
			ret[out++] = '\'';
			ret[out++] = '"';
			ret[out++] = '\'';
			ret[out++] = '"';
			ret[out++] = '\'';
		}
		else
			ret[out++] = input[in];
	}
	ret[out++] = '\'';
	ret[out++] = '\0';

	return ret;
}

char *feh_printf(char *str, feh_file * file)
{
	char *c;
@@ -397,10 +420,18 @@ char *feh_printf(char *str, feh_file * file)
				if (file)
					strcat(ret, file->filename);
				break;
			case 'F':
				if (file)
					strcat(ret, shell_escape(file->filename));
				break;
			case 'n':
				if (file)
					strcat(ret, file->name);
				break;
			case 'N':
				if (file)
					strcat(ret, shell_escape(file->name));
				break;
			case 'w':
				if (file && (file->info || !feh_file_info_load(file, NULL))) {
					snprintf(buf, sizeof(buf), "%d", file->info->width);