Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] Add -- option to prevent interpretation of filenames with dashes #59

Open
protist opened this issue Nov 23, 2022 · 2 comments · May be fixed by #60
Open

[FR] Add -- option to prevent interpretation of filenames with dashes #59

protist opened this issue Nov 23, 2022 · 2 comments · May be fixed by #60

Comments

@protist
Copy link

protist commented Nov 23, 2022

Observed behaviour

$ touch -- a b -i
$ dragon *

The dragon window only show files a and b, using -i as the option (i.e. --icon-only).

Expected behaviour

dragon should interpret -i correctly as a file, not as an option. This could be by a -- option, i.e.

$ dragon -- *
@N-R-K
Copy link
Contributor

N-R-K commented Nov 24, 2022

Quick and dirty patch:

diff --git a/dragon.c b/dragon.c
index 2e1e635..4d1e4e7 100644
--- a/dragon.c
+++ b/dragon.c
@@ -516,6 +516,8 @@ int main (int argc, char **argv) {
                 exit(1);
             }
             argv[i][0] = '\0';
+        } else if (strcmp(argv[i], "--") == 0) { /* "--" stops option processing */
+            break;
         } else if (argv[i][0] == '-') {
             fprintf(stderr, "%s: error: unknown option `%s'.\n",
                     progname, argv[i]);
@@ -566,8 +568,10 @@ int main (int argc, char **argv) {
     else if (drag_all)
         uri_collection = malloc(sizeof(char*) * ((argc > MAX_SIZE ? argc : MAX_SIZE) + 1));
 
-    for (int i=1; i<argc; i++) {
-        if (argv[i][0] != '-' && argv[i][0] != '\0')
+    for (int optended = 0, i=1; i<argc; i++) {
+        if (strcmp(argv[i], "--") == 0)
+            optended = 1;
+        else if (optended || (argv[i][0] != '-' && argv[i][0] != '\0'))
            make_btn(argv[i]);
     }
     if (from_stdin)

@protist
Copy link
Author

protist commented Nov 25, 2022

Thanks @N-R-K! That seems to work perfectly!

N-R-K added a commit to N-R-K/dragon that referenced this issue Dec 1, 2022
since it's valid for filenames to begin with a dash, there's an
ambiguity on weather something like `-i` refers to the cli flag or a
file named `-i`.

the convention is to use a double-dash "--" as a way to mark the end of
cli options so that everything that comes after it can be treated as
arguments.

Closes: mwh#59
@N-R-K N-R-K linked a pull request Dec 1, 2022 that will close this issue
krayon pushed a commit to krayon/dragon-drag-drop-tool that referenced this issue Aug 3, 2024
since it's valid for filenames to begin with a dash, there's an
ambiguity on weather something like `-i` refers to the cli flag or a
file named `-i`.

the convention is to use a double-dash "--" as a way to mark the end of
cli options so that everything that comes after it can be treated as
arguments.

Closes: mwh#59
krayon pushed a commit to krayon/dragon-drag-drop-tool that referenced this issue Aug 3, 2024
since it's valid for filenames to begin with a dash, there's an
ambiguity on weather something like `-i` refers to the cli flag or a
file named `-i`.

the convention is to use a double-dash "--" as a way to mark the end of
cli options so that everything that comes after it can be treated as
arguments.

Closes: mwh#59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants