-
-
Notifications
You must be signed in to change notification settings - Fork 816
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added readme and canonical_path + fixed dirname.
- Loading branch information
Daniel Kongsgaard
authored and
Daniel Kongsgaard
committed
Sep 23, 2023
1 parent
0870727
commit 47ab375
Showing
4 changed files
with
133 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
title: wezterm.basename | ||
tags: | ||
- utility | ||
- filesystem | ||
--- | ||
# `wezterm.basename(path)` | ||
|
||
{{since('nightly')}} | ||
|
||
This function returns a string containing the basename of the given path. | ||
The function does not check whether the given path actually exists. | ||
Due to limitations in the lua bindings, all of the paths | ||
must be able to be represented as UTF-8 or this function will generate an | ||
error. | ||
|
||
Note: This function is similar to the shell command basename, but it behaves | ||
slightly different in some edge case. E.g. `wezterm.basename 'foo.txt/.//'` | ||
returns `'foo.txt` since trailing `/`s are ignored and so is one `.`. | ||
But `wezterm.basename 'foo.txt/..'` returns `'..'`. This behaviour comes | ||
from Rust's [`std::path::PathBuf`](https://doc.rust-lang.org/nightly/std/path/struct.PathBuf.html#method.file_name). | ||
|
||
```lua | ||
local wezterm = require 'wezterm' | ||
local basename = wezterm.basename | ||
|
||
wezterm.log_info( 'baz.txt = ' .. basename '/foo/bar/baz.txt' ) | ||
``` | ||
|
||
See also [dirname](dirname.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
title: wezterm.canonical_path | ||
tags: | ||
- utility | ||
- filesystem | ||
--- | ||
# `wezterm.canonical_path(path)` | ||
|
||
{{since('nightly')}} | ||
|
||
This function returns a string with the canonical form of a path if it exists. | ||
The returned path is in absolute form with all intermediate components normalized | ||
and symbolic links resolved. | ||
Due to limitations in the lua bindings, all of the paths | ||
must be able to be represented as UTF-8 or this function will generate an | ||
error. | ||
|
||
The function can for example be used get the correct absolute path for a path | ||
in a different format. | ||
```lua | ||
local wezterm = require 'wezterm' | ||
local canonical_path = wezterm.canonical_path | ||
|
||
wezterm.log_error( wezterm.home_dir .. ' = ' canonical_path( wezterm.home_dir .. "/.") ) | ||
``` | ||
|
||
Another common use case is to find the absolute path of a symlink. E.g., Dropbox is usually | ||
symlinked to `$HOME/Dropbox` on macOS, but is located at `$HOME/Library/CloudStorage/Dropbox`. | ||
```lua | ||
local wezterm = require 'wezterm' | ||
local canonical_path = wezterm.canonical_path | ||
local home_dir = wezterm.home_dir | ||
|
||
wezterm.log_error( home_dir .. '/Library/CloudStorage/Dropbox' .. ' = ' .. canonical_path( home_dir .. "/Dropbox") ) | ||
``` | ||
|
||
See also [glob](glob.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
title: wezterm.dirname | ||
tags: | ||
- utility | ||
- filesystem | ||
--- | ||
# `wezterm.dirname(path)` | ||
|
||
{{since('nightly')}} | ||
|
||
This function returns a string containing the dirname of the given path. | ||
The function does not check whether the given path actually exists. | ||
Due to limitations in the lua bindings, all of the paths | ||
must be able to be represented as UTF-8 or this function will generate an | ||
error. | ||
|
||
Note: This function is similar to the shell command dirname, but it might | ||
behave slightly different in some edge case. | ||
|
||
```lua | ||
local wezterm = require 'wezterm' | ||
local dirname = wezterm.dirname | ||
|
||
wezterm.log_error( '/foo/bar = ' .. dirname '/foo/bar/baz.txt' ) | ||
``` | ||
|
||
If you want only the directory name and not the full path, you can use | ||
`basename` and `dirname` together. E.g.: | ||
```lua | ||
local wezterm = require 'wezterm' | ||
local basename = wezterm.basename | ||
local dirname = wezterm.dirname | ||
|
||
wezterm.log_error( 'bar = ' .. basename(dirname '/foo/bar/baz.txt') ) | ||
``` | ||
|
||
See also [basename](basename.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters