From cdff668d8f2523bdff624d5f357ccc5ed6ee21a0 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sun, 10 Jan 2021 13:49:57 -0500 Subject: Allow interspersing flags and config files Don't wait for getopt_long to move all the arguments to the end. This allows overriding options set by config files by placing flags after them on the command line. --- config.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index 121a849..d6eaa45 100644 --- a/config.c +++ b/config.c @@ -56,21 +56,17 @@ int getopt_config( const char *optstring, const struct option *longopts, int *longindex ) { static int opt; - if (opt >= 0) { - opt = getopt_long(argc, argv, optstring, longopts, longindex); - } - if (opt >= 0) return opt; - for (;;) { if (!file) { - if (optind < argc) { - num = 0; - path = argv[optind++]; - file = configOpen(path, "r"); - if (!file) return clean('?'); - } else { - return clean(-1); + if (optind == argc) return clean(-1); + if (opt >= 0 && argv[optind][0] == '-') { + opt = getopt_long(argc, argv, optstring, longopts, longindex); + if (opt >= 0 || optind == argc) return clean(opt); } + num = 0; + path = argv[optind++]; + file = configOpen(path, "r"); + if (!file) return clean('?'); } for (;;) { -- cgit 1.4.0 18cd1280e5704e20ccd2d1f&follow=1'>diff
path: root/.mpd (unfollow)
Commit message (Collapse)Author
2013-11-02Rehash on reloadJune McEnroe
2013-11-02Remove git prompt from titleJune McEnroe
2013-11-02Update zsh syntax highlighting and configJune McEnroe
2013-10-31Fix host in prompt, part twoJune McEnroe
2013-10-31Fix host in promptJune McEnroe
2013-10-31Wow look reorganized zsh configJune McEnroe
2013-10-30Show hostname in prompt over SSHJune McEnroe
2013-10-30Only load chruby if it existsJune McEnroe
2013-10-27Add auto-title stuff to zshJune McEnroe
2013-10-26Add gvim alias to silence stderrJune McEnroe
2013-10-26Add home.programble.me functionJune McEnroe
2013-10-14Remove unused configsJune McEnroe
2013-10-14Add therefore, because, cards compose sequencesJune McEnroe
2013-10-14Global git ignore .swo filesJune McEnroe
2013-10-14Add Heroku to zshJune McEnroe
2013-09-23Add gst git stash aliasJune McEnroe
2013-09-05Remove pacman stuffJune McEnroe
Goodbye Arch.
2013-09-05Only alias hub if it existsJune McEnroe
2013-09-05chruby to ruby-2.0.0June McEnroe
2013-08-14Add nvmJune McEnroe
2013-07-09Add title commandJune McEnroe
2013-06-09Use default client keysJune McEnroe
2013-06-09Run games in separate X serverJune McEnroe
2013-06-08Add game wrapper to kill/restart unclutterJune McEnroe
2013-06-08Add git configJune McEnroe