diff --git a/doc/ncdu.pod b/doc/ncdu.pod index ce8e8d319035864e7088480e5e4c8818c3715299..43d623859472c8824f1bc010c45cbbe9ed1caf41 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 d1adb4bcd17eedbbd7643016f688ad4ee2163d10..64f9bc6a0234dca51548b41eb0bdbe39571c0337 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 76e79a679e443f814c65587bca186ec4ca95e156..bc3f3fc1de75a11c2b23cca8395cb047c4252e34 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 17f192dcff315f61983a9f62661989d2d9d50272..679888d62802f597562ad4c0a195a1ff9036a12c 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 6eeca0cb2c7e5c0780a001e2830078a7ae9e1bcc..73ddc6199fd282be141e8d3f3fa2371cb0a585a2 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)) {