path.d.elv 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. #elvdoc:var list-separator
  2. #
  3. # OS-specific path list separator. Colon (`:`) on UNIX and semicolon (`;`) on
  4. # Windows. This variable is read-only.
  5. #elvdoc:var separator
  6. #
  7. # OS-specific path separator. Forward slash (`/`) on UNIX and backslash (`\`)
  8. # on Windows. This variable is read-only.
  9. #elvdoc:fn abs
  10. #
  11. # ```elvish
  12. # path:abs $path
  13. # ```
  14. #
  15. # Outputs `$path` converted to an absolute path.
  16. #
  17. # ```elvish-transcript
  18. # ~> cd ~
  19. # ~> path:abs bin
  20. # ▶ /home/user/bin
  21. # ```
  22. #elvdoc:fn base
  23. #
  24. # ```elvish
  25. # path:base $path
  26. # ```
  27. #
  28. # Outputs the last element of `$path`. This is analogous to the POSIX `basename` command. See the
  29. # [Go documentation](https://pkg.go.dev/path/filepath#Base) for more details.
  30. #
  31. # ```elvish-transcript
  32. # ~> path:base ~/bin
  33. # ▶ bin
  34. # ```
  35. #elvdoc:fn clean
  36. #
  37. # ```elvish
  38. # path:clean $path
  39. # ```
  40. #
  41. # Outputs the shortest version of `$path` equivalent to `$path` by purely lexical processing. This
  42. # is most useful for eliminating unnecessary relative path elements such as `.` and `..` without
  43. # asking the OS to evaluate the path name. See the [Go
  44. # documentation](https://pkg.go.dev/path/filepath#Clean) for more details.
  45. #
  46. # ```elvish-transcript
  47. # ~> path:clean ./../bin
  48. # ▶ ../bin
  49. # ```
  50. #elvdoc:fn dir
  51. #
  52. # ```elvish
  53. # path:dir $path
  54. # ```
  55. #
  56. # Outputs all but the last element of `$path`, typically the path's enclosing directory. See the
  57. # [Go documentation](https://pkg.go.dev/path/filepath#Dir) for more details. This is analogous to
  58. # the POSIX `dirname` command.
  59. #
  60. # ```elvish-transcript
  61. # ~> path:dir /a/b/c/something
  62. # ▶ /a/b/c
  63. # ```
  64. #elvdoc:fn ext
  65. #
  66. # ```elvish
  67. # ext $path
  68. # ```
  69. #
  70. # Outputs the file name extension used by `$path` (including the separating period). If there is no
  71. # extension the empty string is output. See the [Go
  72. # documentation](https://pkg.go.dev/path/filepath#Ext) for more details.
  73. #
  74. # ```elvish-transcript
  75. # ~> path:ext hello.elv
  76. # ▶ .elv
  77. # ```
  78. #elvdoc:fn is-abs
  79. #
  80. # ```elvish
  81. # is-abs $path
  82. # ```
  83. #
  84. # Outputs `$true` if the path is an absolute path. Note that platforms like Windows have different
  85. # rules than UNIX like platforms for what constitutes an absolute path. See the [Go
  86. # documentation](https://pkg.go.dev/path/filepath#IsAbs) for more details.
  87. #
  88. # ```elvish-transcript
  89. # ~> path:is-abs hello.elv
  90. # ▶ false
  91. # ~> path:is-abs /hello.elv
  92. # ▶ true
  93. # ```
  94. #elvdoc:fn eval-symlinks
  95. #
  96. # ```elvish
  97. # eval-symlinks $path
  98. # ```
  99. #
  100. # Outputs `$path` after resolving any symbolic links. If `$path` is relative the result will be
  101. # relative to the current directory, unless one of the components is an absolute symbolic link.
  102. # This function calls `path:clean` on the result before outputting it. This is analogous to the
  103. # external `realpath` or `readlink` command found on many systems. See the [Go
  104. # documentation](https://pkg.go.dev/path/filepath#EvalSymlinks) for more details.
  105. #
  106. # ```elvish-transcript
  107. # ~> mkdir bin
  108. # ~> ln -s bin sbin
  109. # ~> path:eval-symlinks ./sbin/a_command
  110. # ▶ bin/a_command
  111. # ```
  112. #elvdoc:fn join
  113. #
  114. # ```elvish
  115. # path:join $path-component...
  116. # ```
  117. #
  118. # Joins any number of path elements into a single path, separating them with an
  119. # [OS specific separator](#path:separator). Empty elements are ignored. The
  120. # result is [cleaned](#path:clean). However, if the argument list is empty or
  121. # all its elements are empty, Join returns an empty string. On Windows, the
  122. # result will only be a UNC path if the first non-empty element is a UNC path.
  123. #
  124. # ```elvish-transcript
  125. # ~> path:join home user bin
  126. # ▶ home/user/bin
  127. # ~> path:join $path:separator home user bin
  128. # ▶ /home/user/bin
  129. # ```
  130. #elvdoc:fn is-dir
  131. #
  132. # ```elvish
  133. # is-dir &follow-symlink=$false $path
  134. # ```
  135. #
  136. # Outputs `$true` if the path resolves to a directory. If the final element of the path is a
  137. # symlink, even if it points to a directory, it still outputs `$false` since a symlink is not a
  138. # directory. Setting option `&follow-symlink` to true will cause the last element of the path, if
  139. # it is a symlink, to be resolved before doing the test.
  140. #
  141. # ```elvish-transcript
  142. # ~> touch not-a-dir
  143. # ~> path:is-dir not-a-dir
  144. # ▶ false
  145. # ~> path:is-dir /tmp
  146. # ▶ true
  147. # ```
  148. #
  149. # @cf path:is-regular
  150. #elvdoc:fn is-regular
  151. #
  152. # ```elvish
  153. # is-regular &follow-symlink=$false $path
  154. # ```
  155. #
  156. # Outputs `$true` if the path resolves to a regular file. If the final element of the path is a
  157. # symlink, even if it points to a regular file, it still outputs `$false` since a symlink is not a
  158. # regular file. Setting option `&follow-symlink` to true will cause the last element of the path,
  159. # if it is a symlink, to be resolved before doing the test.
  160. #
  161. # **Note:** This isn't named `is-file` because a UNIX file may be a "bag of bytes" or may be a
  162. # named pipe, device special file (e.g. `/dev/tty`), etc.
  163. #
  164. # ```elvish-transcript
  165. # ~> touch not-a-dir
  166. # ~> path:is-regular not-a-dir
  167. # ▶ true
  168. # ~> path:is-regular /tmp
  169. # ▶ false
  170. # ```
  171. #
  172. # @cf path:is-dir
  173. #elvdoc:fn temp-dir
  174. #
  175. # ```elvish
  176. # temp-dir &dir='' $pattern?
  177. # ```
  178. #
  179. # Creates a new directory and outputs its name.
  180. #
  181. # The &dir option determines where the directory will be created; if it is an
  182. # empty string (the default), a system-dependent directory suitable for storing
  183. # temporary files will be used. The `$pattern` argument determines the name of
  184. # the directory, where the last star will be replaced by a random string; it
  185. # defaults to `elvish-*`.
  186. #
  187. # It is the caller's responsibility to remove the directory if it is intended
  188. # to be temporary.
  189. #
  190. # ```elvish-transcript
  191. # ~> path:temp-dir
  192. # ▶ /tmp/elvish-RANDOMSTR
  193. # ~> path:temp-dir x-
  194. # ▶ /tmp/x-RANDOMSTR
  195. # ~> path:temp-dir 'x-*.y'
  196. # ▶ /tmp/x-RANDOMSTR.y
  197. # ~> path:temp-dir &dir=.
  198. # ▶ elvish-RANDOMSTR
  199. # ~> path:temp-dir &dir=/some/dir
  200. # ▶ /some/dir/elvish-RANDOMSTR
  201. # ```
  202. #elvdoc:fn temp-file
  203. #
  204. # ```elvish
  205. # temp-file &dir='' $pattern?
  206. # ```
  207. #
  208. # Creates a new file and outputs a [file](language.html#file) object opened
  209. # for reading and writing.
  210. #
  211. # The &dir option determines where the file will be created; if it is an
  212. # empty string (the default), a system-dependent directory suitable for storing
  213. # temporary files will be used. The `$pattern` argument determines the name of
  214. # the file, where the last star will be replaced by a random string; it
  215. # defaults to `elvish-*`.
  216. #
  217. # It is the caller's responsibility to close the file with
  218. # [`file:close`](file.html#file:close). The caller should also remove the file
  219. # if it is intended to be temporary (with `rm $f[name]`).
  220. #
  221. # ```elvish-transcript
  222. # ~> var f = (path:temp-file)
  223. # ~> put $f[name]
  224. # ▶ /tmp/elvish-RANDOMSTR
  225. # ~> echo hello > $f
  226. # ~> cat $f[name]
  227. # hello
  228. # ~> var f = (path:temp-file x-)
  229. # ~> put $f[name]
  230. # ▶ /tmp/x-RANDOMSTR
  231. # ~> var f = (path:temp-file 'x-*.y')
  232. # ~> put $f[name]
  233. # ▶ /tmp/x-RANDOMSTR.y
  234. # ~> var f = (path:temp-file &dir=.)
  235. # ~> put $f[name]
  236. # ▶ elvish-RANDOMSTR
  237. # ~> var f = (path:temp-file &dir=/some/dir)
  238. # ~> put $f[name]
  239. # ▶ /some/dir/elvish-RANDOMSTR
  240. # ```