]> gitweb.factorcode.org Git - factor.git/commitdiff
io.pathnames: Revised ~ support to expand on the first tilde, and not on "~/".
authorotoburb <otoburb@gmail.com>
Wed, 11 Jan 2012 02:25:53 +0000 (02:25 +0000)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 31 Mar 2012 04:01:57 +0000 (21:01 -0700)
This mimics the same behaviour as "ls ~" in the shell, which expands the alias
as a directory, and not as a filename. For the specific edge-case where a
filename called "~" must have a path constructed to it (e.g. "./~" or "~/~").

core/io/pathnames/pathnames-docs.factor
core/io/pathnames/pathnames-tests.factor
core/io/pathnames/pathnames.factor

index d20db3f3a98f1090ffd67a422d4c4440ba133f39..94cb23832dd9ff2105ee77719298adf303796a22 100644 (file)
@@ -106,7 +106,7 @@ HELP: absolute-path
     { "path" "a pathname string" }
     { "path'" "a pathname string" }
 }
-{ $description "Prepends the " { $link current-directory } " to the pathname and resolves a " { $snippet "resource:" } ", " { $snippet "~/" } " or " { $snippet "vocab:" } " prefix, if present (see " { $link "io.pathnames.special" } ")." }
+{ $description "Prepends the " { $link current-directory } " to the pathname and resolves a " { $snippet "resource:" } ", " { $snippet "~" } " or " { $snippet "vocab:" } " prefix, if present (see " { $link "io.pathnames.special" } ")." }
 { $notes "This word is exactly the same as " { $link normalize-path } ", except on Windows NT platforms, where it does not prepend the Unicode path prefix. Most code should call " { $link normalize-path } " instead." } ;
 
 HELP: resolve-symlinks
@@ -133,7 +133,7 @@ ARTICLE: "io.pathnames.special" "Special pathnames"
 $nl
 "If a pathname begins with " { $snippet "vocab:" } ", then it will be searched for in all current vocabulary roots (see " { $link "add-vocab-roots" } ")."
 $nl
-"If a pathname begins with " { $snippet "~/" } ", it will be searched for in the home directory. Subsequent tildes in the pathname will be construed as literal tilde path or filenames and will not be treated specially. It should be noted that the " { $snippet "~" } " symbol without a forward slash will be also be treated as a literal path or filename." ;
+"If a pathname begins with " { $snippet "~" } ", it will be searched for in the home directory. Subsequent tildes in the pathname will be construed as literal tilde path or filenames and will not be treated specially. To access a filename named " { $snippet "~" } ", you must construct a path to reference the filename, even if it's within the current directory such as " { $snippet "./~" } "." ;
 
 ARTICLE: "io.pathnames.presentations" "Pathname presentations"
 "Pathname presentations are objects that wrap a pathname string. Clicking a pathname presentation in the UI brings up the file in one of the supported editors. See " { $link "editor" } " for more details."
index 6c92a83bd5a4f818ef2ff80e0ab55ad014c1b7cd..2d352848cedc81e46f4f360498f253d1606e99a6 100644 (file)
@@ -1,6 +1,7 @@
 USING: io.pathnames io.files.temp io.directories
 continuations math io.files.private kernel
-namespaces sequences tools.test io.pathnames.private ;
+namespaces sequences system tools.test 
+io.backend io.pathnames.private ;
 IN: io.pathnames.tests
 
 [ "passwd" ] [ "/etc/passwd" file-name ] unit-test
@@ -71,8 +72,14 @@ IN: io.pathnames.tests
 [ f ] [ "/funny.directory/file-with-no-extension" file-extension ] unit-test
 [ "" ] [ "/funny.directory/file-with-no-extension." file-extension ] unit-test
 
-! Testing ~/ special pathname
-[ t ] [ "~/" absolute-path home = ] unit-test 
-[ f ] [ "~" absolute-path home = ] unit-test
-[ t ] [ "~/~" absolute-path "/~" home prepend = ] unit-test
-[ t ] [ "~/~/" absolute-path "/~/" home prepend = ] unit-test
+! Testing ~ special pathname
+[ t ] [ os windows? "~\\" "~/" ? absolute-path home = ] unit-test 
+[ t ] [ "~/" home [ normalize-path ] bi@ = ] unit-test 
+
+[ t ] [ "~" absolute-path home = ] unit-test
+[ t ] [ "~" home [ normalize-path ] bi@ = ] unit-test 
+
+[ t ] [ "~" home [ "foo" append-path ] bi@ [ normalize-path ] bi@ = ] unit-test
+[ t ] [ os windows? "~\\~/" "~/~/" ? "~" "~" append-path [ path-components ] bi@ = ] unit-test
+
+
index 911235e01766afb7d01110e8a8262b88fca1787b..c2542f9897419d932473468bf88c3c1063dee373 100644 (file)
@@ -152,7 +152,7 @@ M: string absolute-path
             trim-head-separators vocab-path
             absolute-path
         ] [
-            "~/" ?head [
+            "~" ?head [
                 trim-head-separators home prepend-path
                 absolute-path
         ] [