ref: 5ba856912e6c4a6490d31f69a09cde50a72c40f9
parent: 8154ecb3fc6c1265e0d5c0ab4288ad514463924d
author: phil9 <[email protected]>
date: Sat Mar 12 04:51:03 EST 2022
add -r flag to enable recursive delete / change menu order menu2 contained delete before rename which could lead if misclicking to unwillingly delete files or directories. Put rename before delete so that nothing bad can happen. delete will now default to non-recursive rm, a command-line flag `-r` can be used to enable recursive rm instead.
--- a/README.md
+++ b/README.md
@@ -26,11 +26,12 @@
Usage:
------
Install with the usual ``mk install``
-Run ``vdir [directory]``
+Run ``vdir [-r] [directory]``
+If the `-r` flag is passed, delete will recursively delete directories.
Path plumbing:
--------------
-When right-clicking the path, the path name is sent to plumber.
+When right-clicking the path in the toolbar, the path name is sent to plumber.
This can be used to open a window in the directory for instance:
```
src is vdir
--- a/vdir.c
+++ b/vdir.c
@@ -29,10 +29,10 @@
enum
{
- Mdelete,
Mrename,
+ Mdelete,
};
-char *menu2str[] = { "delete", "rename", nil };
+char *menu2str[] = { "rename", "delete", nil };
Menu menu2 = { menu2str };
const char ellipsis[] = "…";
@@ -76,6 +76,7 @@
int scrolling;
int oldbuttons;
int lastn;
+int rmode;
void
showerrstr(char *msg)
@@ -252,7 +253,7 @@
{
char cmd[300];
- snprint(cmd, sizeof cmd, "rm -r %s/%s", path, name);
+ snprint(cmd, sizeof cmd, "rm %s %s/%s", rmode ? "-r" : "", path, name);
if(doexec(cmd) < 0)
showerrstr("Cannot remove file/directory");
else
@@ -684,6 +685,13 @@
}
void
+usage(void)
+{
+ fprint(2, "usage: %s [-r] [path]\n", argv0);
+ exits("usage");
+}
+
+void
threadmain(int argc, char *argv[])
{
Mouse m;
@@ -699,10 +707,18 @@
scrolling = 0;
oldbuttons = 0;
lastn = -1;
+ rmode = 0;
+ ARGBEGIN{
+ case 'r':
+ ++rmode;
+ break;
+ default:
+ usage();
+ }ARGEND;
if(getwd(path, sizeof path) == nil)
sysfatal("getwd: %r");
- if(argc==2 && access(argv[1], 0) >= 0)
- snprint(path, sizeof path, abspath(path, argv[1]));
+ if(argc==1 && access(argv[0], 0) >= 0)
+ snprint(path, sizeof path, abspath(path, argv[0]));
plumbfd = plumbopen("send", OWRITE|OCEXEC);
if(plumbfd<0)
sysfatal("plumbopen: %r");