9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] [PATCH] rio: allow spaces in working directory path (-cd) when creating a new window
@ 2021-11-25  2:17 igor
  2021-11-25  9:57 ` cinap_lenrek
  0 siblings, 1 reply; 4+ messages in thread
From: igor @ 2021-11-25  2:17 UTC (permalink / raw)
  To: 9front; +Cc: igor

[-- Attachment #1: Type: text/plain, Size: 2102 bytes --]

The below patch is for review and testing.  It enables rio to open new
windows in a working directory `dirname` (i.e.  using `-cd dirname`)
where the dirname path contains spaces.  I ran into this issue while
browsing hierarchies imported via sshfs(4) in vdir⁽¹⁾, using vdir's
feature to open a window with the working directory set to the
selected path via right clicking on a path.

Please give this a try and/or provide feedback if you run into any
issues or disagree with the solution.  If there is agreement and no
one runs into problems over the next week or two I will merge this
patch.

¹…http://shithub.us/phil9/vdir/HEAD/info.html

<snip>
From: Igor Böhm <igor@9lab.org>
Date: Thu, 25 Nov 2021 01:57:04 +0000
Subject: [PATCH] rio: allow spaces in working directory path (-cd) when creating a new window


The initial working directory of the new window may be set by a
`-cd directory` option. However, the `-cd directory` option is
not capable of handling paths with spaces.

To enable paths with spaces the function
/sys/src/cmd/rio/wctl.c:/^parsewctl is extended to handle quoted
directory paths, using a closing quote as the end of a path instead
of a space.

Before applying the patch the following will fail to open a new
window by writing to /dev/wctl:

<snip>
 % rio -i window
 % mkdir '/tmp/path with space'
 % echo new -cd '''/tmp/path with space''' window -x rc >> /dev/wctl
 % pwd
 /tmp/path with space
<snap>

After applying the patch the above sequence works as expected,
opening a window running rc and the working directory set to
'/tmp/path with space'.
---
diff f8dc73782d90c741e7886629252215c13e35af40 343aafa3a09dd808a1652670d8a7e20021cb0057
--- a/sys/src/cmd/rio/wctl.c	Mon Nov  8 00:31:11 2021
+++ b/sys/src/cmd/rio/wctl.c	Thu Nov 25 02:57:04 2021
@@ -252,8 +252,13 @@
 			s++;
 		if(param == Cd){
 			*cdp = s;
-			while(*s && !isspace(*s))
-				s++;
+			if(*s == '\''){	/* quoted directory */
+				*cdp = ++s;
+				while(*s && *s != '\'')
+					s++;
+			}else
+				while(*s && !isspace(*s))
+					s++;
 			if(*s != '\0')
 				*s++ = '\0';
 			continue;
</snap>

[-- Attachment #2: rio-working-directory-with-spaces.patch --]
[-- Type: text/plain, Size: 1437 bytes --]

From: Igor Böhm <igor@9lab.org>
Date: Thu, 25 Nov 2021 01:57:04 +0000
Subject: [PATCH] rio: allow spaces in working directory path (-cd) when creating a new window


The initial working directory of the new window may be set by a
`-cd directory` option. However, the `-cd directory` option is
not capable of handling paths with spaces.

To enable paths with spaces the function
/sys/src/cmd/rio/wctl.c:/^parsewctl is extended to handle quoted
directory paths, using a closing quote as the end of a path instead
of a space.

Before applying the patch the following will fail to open a new
window by writing to /dev/wctl:

<snip>
 % rio -i window
 % mkdir '/tmp/path with space'
 % echo new -cd '''/tmp/path with space''' window -x rc >> /dev/wctl
 % pwd
 /tmp/path with space
<snap>

After applying the patch the above sequence works as expected,
opening a window running rc and the working directory set to
'/tmp/path with space'.
---
diff f8dc73782d90c741e7886629252215c13e35af40 343aafa3a09dd808a1652670d8a7e20021cb0057
--- a/sys/src/cmd/rio/wctl.c	Mon Nov  8 00:31:11 2021
+++ b/sys/src/cmd/rio/wctl.c	Thu Nov 25 02:57:04 2021
@@ -252,8 +252,13 @@
 			s++;
 		if(param == Cd){
 			*cdp = s;
-			while(*s && !isspace(*s))
-				s++;
+			if(*s == '\''){	/* quoted directory */
+				*cdp = ++s;
+				while(*s && *s != '\'')
+					s++;
+			}else
+				while(*s && !isspace(*s))
+					s++;
 			if(*s != '\0')
 				*s++ = '\0';
 			continue;

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-11-29  0:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-25  2:17 [9front] [PATCH] rio: allow spaces in working directory path (-cd) when creating a new window igor
2021-11-25  9:57 ` cinap_lenrek
2021-11-25 10:40   ` igor
2021-11-29  0:29   ` igor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).