Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

[feature request] Load all images in the same folder #179

Closed
causes- opened this issue Oct 12, 2014 · 3 comments
Closed

[feature request] Load all images in the same folder #179

causes- opened this issue Oct 12, 2014 · 3 comments

Comments

@causes-
Copy link

causes- commented Oct 12, 2014

If i click a picture in filemanager it opens only the clicked picture. I would really like to see feature to load all pictures in the same folder so i could browse through the pictures.

@causes- causes- changed the title [feature request] Load all images in same folder [feature request] Load all images in the same folder Oct 12, 2014
@xyb3rt
Copy link
Owner

xyb3rt commented Oct 12, 2014

sxiv is designed for command line users. Please use a wrapper script for that. Google sxiv-rifle or use the following one:

#!/bin/sh

if [ $# -ne 1 -o ! -f "$1" ]; then
    echo "usage: ${0##*/} FILE" >&2
    exit 1
fi

file -i "$(dirname "$1")"/* \
    | awk -F ': *' -v f="$1" '
        $2 ~ "^image" {
            files[cnt++] = $1;
            if ($1 == f)
                n = cnt;
        }
        END {
            for (i = 0; i < cnt; i++)
                print files[i] | "sxiv -i -n " n;
        }'

@agguser
Copy link

agguser commented Apr 5, 2020

It would be good if -n option can also take "file name" instead of just "index number", like opening a file manager with a specific file selected. With this, you can use something like sxiv -n x.png *.png

diff --git a/options.c b/options.c
index de02407..b9ca468 100644
--- a/options.c
+++ b/options.c
@@ -45,6 +45,7 @@ void parse_options(int argc, char **argv)
 	int n, opt;
 	char *end, *s;
 	const char *scalemodes = "dfwh";
+	char *opt_n = NULL;   /* -n (starting picture number) can be index or filename */
 
 	progname = strrchr(argv[0], '/');
 	progname = progname ? progname + 1 : argv[0];
@@ -117,10 +118,7 @@ void parse_options(int argc, char **argv)
 				_options.from_stdin = true;
 				break;
 			case 'n':
-				n = strtol(optarg, &end, 0);
-				if (*end != '\0' || n <= 0)
-					error(EXIT_FAILURE, 0, "Invalid argument for option -n: %s", optarg);
-				_options.startnum = n - 1;
+				opt_n = optarg;
 				break;
 			case 'N':
 				_options.res_name = optarg;
@@ -172,6 +170,21 @@ void parse_options(int argc, char **argv)
 	_options.filenames = argv + optind;
 	_options.filecnt = argc - optind;
 
+	if (opt_n != NULL) {
+		for (n = 0; n < _options.filecnt; n++) {
+			if (strcmp(_options.filenames[n], opt_n) == 0)
+				break;
+		}
+		if (n < _options.filecnt) {
+			_options.startnum = n;
+		} else {
+			n = strtol(opt_n, &end, 0);
+			if (*end != '\0' || n <= 0)
+				error(EXIT_FAILURE, 0, "Invalid argument for option -n: %s", optarg);
+			_options.startnum = n - 1;
+		}
+	}
+
 	if (_options.filecnt == 1 && STREQ(_options.filenames[0], "-")) {
 		_options.filenames++;
 		_options.filecnt--;

EDIT: Just noticed that there is already a pull request (#371).

@Parveshdhull
Copy link

My workaround for this:
https://github.com/Parveshdhull/misc/tree/master/linux

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants