@@ -4,6 +4,8 @@ local string = require "string"
4
4
local table = require " table"
5
5
local lfs = require " lfs"
6
6
local ansicolors = require " ansicolors"
7
+ local prompt = require " prompt"
8
+ --- @diagnostic disable : deprecated
7
9
if table.unpack == nil then table .unpack = unpack end
8
10
9
11
--- get distribution
@@ -52,12 +54,17 @@ local function get_icon()
52
54
end
53
55
54
56
--- get version
57
+ --- @param name string
55
58
--- @param logo string
59
+ --- @param format string
56
60
--- @return string
57
- local function get_version (logo )
58
- logo = logo or " "
61
+ local function get_version (name , logo , format )
62
+ name = name or prompt .name
63
+ logo = logo or " "
64
+ format = format or " %s "
65
+ name = string.format (format , name )
59
66
local version = string.gsub (_VERSION , " .*%s+" , " " )
60
- return logo .. version
67
+ return logo .. name .. version
61
68
end
62
69
63
70
--- get time
@@ -79,18 +86,21 @@ local function get_cwd()
79
86
end
80
87
81
88
--- generate ps1.
89
+ -- `name` is for `get_version()`
82
90
-- `sections` is an array whose element is like `{ "white", "blue", get_cwd }`
83
91
-- and its order determine the order of prompt sections.
84
92
-- `sep` is separator. `char` is the last character like `> `
85
93
-- `format` determine the space and by default is ' %s '.
94
+ --- @param name string
86
95
--- @param sections { 1: integer , 2: integar , 3: string | function (): string } []
87
96
--- @param sep string
88
97
--- @param char string
89
98
--- @param format string
90
99
--- @return function (): string
91
- local function generate_ps1 (sections , sep , char , format )
100
+ local function generate_ps1 (name , sections , sep , char , format )
101
+ name = name or prompt .name
92
102
sections = sections or {
93
- {" black" , " yellow" , get_icon ()}, {" blue" , " black" , get_version ()},
103
+ {" black" , " yellow" , get_icon ()}, {" blue" , " black" , get_version (name )},
94
104
{" white" , " blue" , get_cwd }, {" black" , " white" , get_time }
95
105
}
96
106
sep = sep or " "
0 commit comments