Arch 基础安装到日常使用与美化 - Yazi

yazi安装与配置

1、yazi

终端文件管理器和 ranger 一样

官方文档地址:https://yazi-rs.github.io/

1.1、安装

1
sudo pacman -S yazi ffmpegthumbnailer unarchiver jq poppler fd ripgrep fzf zoxide

1.2、配置

参考地址:https://yazi-rs.github.io/docs/tips

1.2.1、全边框

https://github.com/sxyazi/yazi/blob/main/yazi-plugin/preset/components/manager.lua 文件中 Manager:render 函数复制到 ~/.config/yazi/init.lua 中,并打入下面补丁

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
@@ -10,16 +10,28 @@
 		})
 		:split(area)

+	local bar = function(c, x, y)
+		x, y = math.max(0, x), math.max(0, y)
+		return ui.Bar(ui.Rect { x = x, y = y, w = ya.clamp(0, area.w - x, 1), h = math.min(1, area.h) }, ui.Bar.TOP)
+			:symbol(c)
+	end
+
 	return ya.flat {
 		-- Borders
-		ui.Bar(chunks[1], ui.Bar.RIGHT):symbol(THEME.manager.border_symbol):style(THEME.manager.border_style),
-		ui.Bar(chunks[3], ui.Bar.LEFT):symbol(THEME.manager.border_symbol):style(THEME.manager.border_style),
+		ui.Border(area, ui.Border.ALL):type(ui.Border.ROUNDED),
+		ui.Bar(chunks[1], ui.Bar.RIGHT),
+		ui.Bar(chunks[3], ui.Bar.LEFT),

+		bar("┬", chunks[1].right - 1, chunks[1].y),
+		bar("┴", chunks[1].right - 1, chunks[1].bottom - 1),
+		bar("┬", chunks[2].right, chunks[2].y),
+		bar("┴", chunks[2].right, chunks[1].bottom - 1),
+
 		-- Parent
-		Parent:render(chunks[1]:padding(ui.Padding.x(1))),
+		Parent:render(chunks[1]:padding(ui.Padding.xy(1))),
 		-- Current
-		Current:render(chunks[2]),
+		Current:render(chunks[2]:padding(ui.Padding.y(1))),
 		-- Preview
-		Preview:render(chunks[3]:padding(ui.Padding.x(1))),
+		Preview:render(chunks[3]:padding(ui.Padding.xy(1))),
 	}
 end

1.2.2、软链接符号

https://github.com/sxyazi/yazi/blob/main/yazi-plugin/preset/components/status.lua 文件中复制 Status:name 函数添加到 ~/.config/yazi/init.lua 中,并打入下面补丁

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
@@ -42,7 +42,11 @@ function Status:name()
 		return ui.Span("")
 	end

-	return ui.Span(" " .. h.name)
+	local linked = ""
+	if h.link_to ~= nil then
+		linked = " -> " .. tostring(h.link_to)
+	end
+	return ui.Span(" " .. h.name .. linked)
 end

1.2.3、显示用户和用户组

https://github.com/sxyazi/yazi/blob/main/yazi-plugin/preset/components/status.lua 文件中复制 Status:render 函数添加到 ~/.config/yazi/init.lua 中,并打入下面补丁

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
@@ -1,8 +1,22 @@
+function Status:owner()
+	local h = cx.active.current.hovered
+	if h == nil or ya.target_family() ~= "unix" then
+		return ui.Line {}
+	end
+
+	return ui.Line {
+		ui.Span(ya.user_name(h.cha.uid) or tostring(h.cha.uid)):fg("magenta"),
+		ui.Span(":"),
+		ui.Span(ya.group_name(h.cha.gid) or tostring(h.cha.gid)):fg("magenta"),
+		ui.Span(" "),
+	}
+end
+
 function Status:render(area)
 	self.area = area

 	local left = ui.Line { self:mode(), self:size(), self:name() }
-	local right = ui.Line { self:permissions(), self:percentage(), self:position() }
+	local right = ui.Line { self:owner(), self:permissions(), self:percentage(), self:position() }
 	local progress = self:progress(area, right:width())
 	return {
 		ui.Paragraph(area, { left }),

显示用户名和主机名

https://github.com/sxyazi/yazi/blob/main/yazi-plugin/preset/components/header.lua 文件中复制 Header:render 函数添加到 ~/.config/yazi/init.lua 中,并打入下面补丁

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
@@ -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 }),

1.2.4、文件不现实软链接

~/.config/yazi/init.lua 中加入下面函数

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function Folder:highlighted_name(file)
    -- Complete prefix when searching across directories
    local prefix = file:prefix() or ""
    if prefix ~= "" then
        prefix = prefix .. "/"
    end

    -- Range highlighting for filenames
    local highlights = file:highlights()
    local spans = self:highlight_ranges(prefix .. file.name, highlights)

    -- Show symlink target
    if MANAGER.show_symlink and file.link_to ~= nil then
        spans[#spans + 1] = ui.Span(""):italic()
    end

    if highlights == nil or not file:is_hovered() then
        return spans
    end

    local found = file:found()
    if found ~= nil then
        spans[#spans + 1] = ui.Span("  ")
        spans[#spans + 1] = ui.Span(string.format("[%d/%d]", found[1] + 1, found[2])):style(THEME.manager.find_position)
    end
    return spans
end

相关内容

0%