Skip to content

Commit

Permalink
docs: add tips for showing username and hostname in header
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Jan 20, 2024
1 parent f35721a commit e724af7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
12 changes: 8 additions & 4 deletions docs/plugins/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,23 @@ Returns the current timestamp, which is a float, the integer part represents the

### `uid()`

Returns the user id of the current user, which is an integer.
Only available on Unix-like systems. Returns the user id of the current user, which is an integer.

### `gid()`

Returns the group id of the current user, which is an integer.
Only available on Unix-like systems. Returns the group id of the current user, which is an integer.

### `user_name()`

Returns the name of the current user, which is a string.
Only available on Unix-like systems. Returns the name of the current user, which is a string if successful; otherwise, `nil`.

### `group_name()`

Returns the name of the current group, which is a string.
Only available on Unix-like systems. Returns the name of the current group, which is a string if successful; otherwise, `nil`.

### `host_name()`

Only available on Unix-like systems. Returns the hostname of the current machine, which is a string if successful; otherwise, `nil`.

## fs

Expand Down
30 changes: 30 additions & 0 deletions docs/tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,33 @@ copy this method to your `~/.config/yazi/init.lua`, and apply the following patc
return {
ui.Paragraph(area, { left }),
```

## Show username and hostname in header

<img src={useBaseUrl("/img/hostname-in-header.png")} width="600" />

You can rewrite the [`Header:render()` method](https://github.com/sxyazi/yazi/blob/main/yazi-plugin/preset/components/header.lua) to achieve this feature,
copy this method to your `~/.config/yazi/init.lua`, and apply the following patch:

```diff
@@ -1,3 +1,10 @@
+function Header:host()
+ if ya.target_family() ~= "unix" then
+ return ui.Line {}
+ end
+ return ui.Span(ya.user_name() .. "@" .. ya.host_name() .. ":"):fg("blue")
+end
+
function Header:render(area)
self.area = area

@@ -6,7 +13,7 @@
:constraints({ ui.Constraint.Percentage(50), ui.Constraint.Percentage(50) })
:split(area)

- local left = ui.Line { self:cwd() }
+ local left = ui.Line { self:host(), self:cwd() }
local right = ui.Line { self:tabs() }
return {
ui.Paragraph(chunks[1], { left }),
```
Binary file added static/img/hostname-in-header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e724af7

Please sign in to comment.