summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2012-01-15 13:50:40 +0100
committerDaniel Friesel <derf@finalrewind.org>2012-01-15 13:50:40 +0100
commit310b60793c9e87eb2a13a7c0396c09634ca08a22 (patch)
tree797f93774e7fae0c03eadca9b3f8b90582e8e2d9
parent919298ad43bff814c91ed7bc4a402b72db6fa9a5 (diff)
Add %F and %N printf sequences for escaped file name (closes #77)
-rw-r--r--ChangeLog6
-rw-r--r--man/feh.pre13
-rw-r--r--src/slideshow.c31
3 files changed, 48 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 358c2e6..b0794f8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+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
diff --git a/man/feh.pre b/man/feh.pre
index 56ff766..254a5f7 100644
--- a/man/feh.pre
+++ b/man/feh.pre
@@ -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
.
diff --git a/src/slideshow.c b/src/slideshow.c
index 42aaf2e..189357d 100644
--- a/src/slideshow.c
+++ b/src/slideshow.c
@@ -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);