From c035c3859c05b664bbc5fcaf0688a538ab329f4b Mon Sep 17 00:00:00 2001 From: Max Klinger Date: Sun, 20 Sep 2015 01:11:12 +0200 Subject: [PATCH] implement confirmation switch --- doc/ncdu.pod | 5 +++++ src/browser.c | 4 +++- src/browser.h | 1 + src/global.h | 2 ++ src/main.c | 3 +++ 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/doc/ncdu.pod b/doc/ncdu.pod index ce8e8d3..43d6238 100644 --- a/doc/ncdu.pod +++ b/doc/ncdu.pod @@ -103,6 +103,11 @@ List sizes using base 10 prefixes, that is, powers of 1000 (KB, MB, etc), as defined in the International System of Units (SI), instead of the usual base 2 prefixes, that is, powers of 1024 (KiB, MiB, etc). +=item --confirm-quit + +Requires a confirmation before quitting ncdu. Very helpful when you +accidentally press 'q' during or after a very long scan. + =back =head2 Scan Options diff --git a/src/browser.c b/src/browser.c index d1adb4b..64f9bc6 100644 --- a/src/browser.c +++ b/src/browser.c @@ -397,7 +397,9 @@ int browse_key(int ch) { if(info_show) info_show = 0; else - quit_init(); + if (confirm_quit) + quit_init(); + else return 1; break; case 'g': if(++graph > 3) diff --git a/src/browser.h b/src/browser.h index 76e79a6..bc3f3fc 100644 --- a/src/browser.h +++ b/src/browser.h @@ -28,6 +28,7 @@ #include "global.h" +int confirm_quit; int browse_key(int); void browse_draw(void); void browse_init(struct dir *); diff --git a/src/global.h b/src/global.h index 17f192d..679888d 100644 --- a/src/global.h +++ b/src/global.h @@ -90,6 +90,8 @@ extern int read_only; extern long update_delay; /* filter directories with CACHEDIR.TAG */ extern int cachedir_tags; +/* flag if we should ask for confirmation when quitting */ +extern int confirm_quit; /* handle input from keyboard and update display */ int input_handle(int); diff --git a/src/main.c b/src/main.c index 6eeca0c..73ddc61 100644 --- a/src/main.c +++ b/src/main.c @@ -130,6 +130,7 @@ static void argv_parse(int argc, char **argv) { { 'X', 1, "-X,--exclude-from" }, { 'C', 0, "--exclude-caches" }, { 's', 0, "--si" }, + { 'Q', 0, "--confirm-quit" }, {0,0,NULL} }; @@ -154,6 +155,7 @@ static void argv_parse(int argc, char **argv) { printf(" --exclude PATTERN Exclude files that match PATTERN\n"); printf(" -X, --exclude-from FILE Exclude files that match any pattern in FILE\n"); printf(" --exclude-caches Exclude directories containing CACHEDIR.TAG\n"); + printf(" --confirm-quit Confirm quitting ncdu\n"); exit(0); case 'q': update_delay = 2000; break; case 'v': @@ -167,6 +169,7 @@ static void argv_parse(int argc, char **argv) { case '0': dir_ui = 0; break; case '1': dir_ui = 1; break; case '2': dir_ui = 2; break; + case 'Q': confirm_quit = 1; break; case 1 : exclude_add(val); break; /* --exclude */ case 'X': if(exclude_addfile(val)) {