shithub: rio

Download patch

ref: 6814cdf2a73b50f8b676047ace86ed78f4c79258
parent: 51cd581eb268a1944653e119ddfcb989cb18ff47
author: glenda <glenda@cirno>
date: Fri Mar 21 22:41:41 EDT 2025

add completion for /bin and subdirs

--- a/wind.c
+++ b/wind.c
@@ -476,6 +476,7 @@
 {
 	char	*dir;
 	char	*str;
+	char	*binpath;
 	Window	*win;
 };
 
@@ -487,8 +488,11 @@
 
 	job = arg;
 	threadsetname("namecomplete %s", job->dir);
-
 	c = complete(job->dir, job->str);
+	if((c == nil || c->nmatch == 0) && job->binpath != nil){
+		c = complete(job->binpath, job->str);
+	}
+	
 	if(c != nil && sendp(job->win->complete, c) <= 0)
 		freecompletion(c);
 
@@ -496,6 +500,7 @@
 
 	free(job->dir);
 	free(job->str);
+	free(job->binpath);
 	free(job);
 }
 
@@ -522,7 +527,7 @@
 {
 	int nstr, npath;
 	Rune *path, *str;
-	char *dir, *root;
+	char *dir, *root, *binpath;
 	Completejob *job;
 
 	/* control-f: filename completion; works back to white space or / */
@@ -532,11 +537,15 @@
 	str = w->r+(w->q0-nstr);
 	npath = windfilewidth(w, w->q0-nstr, FALSE);
 	path = w->r+(w->q0-nstr-npath);
+	binpath = nil;
 
 	/* is path rooted? if not, we need to make it relative to window path */
 	if(npath>0 && path[0]=='/')
 		dir = runetobyte(path, npath, &npath);
 	else {
+		/* only to try completing a command if it's at the start of a prompt */
+		if(w->q0-nstr-npath == w->qh)
+			binpath = smprint("/bin/%.*S", npath, path);
 		if(strcmp(w->dir, "") == 0)
 			root = ".";
 		else
@@ -545,11 +554,15 @@
 	}
 	if(dir == nil)
 		return;
-
+		
 	/* run in background, winctl will collect the result on w->complete chan */
 	job = emalloc(sizeof *job);
 	job->str = runetobyte(str, nstr, &nstr);
 	job->dir = cleanname(dir);
+	if(binpath != nil)
+		job->binpath = cleanname(binpath);
+	else
+		job->binpath = nil;
 	job->win = w;
 	incref(w);
 	proccreate(completeproc, job, STACK);