@@ -8,6 +8,22 @@ local prompt = require "prompt"
88--- @diagnostic disable : deprecated
99if table.unpack == nil then table .unpack = unpack end
1010
11+ --- wakatime
12+ --- @param cmd string
13+ --- @return string
14+ local function wakatime (cmd )
15+ cmd = cmd or " wakatime-cli --write --plugin=repl-lua-wakatime --entity-type=app \
16+ --entity=lua --alternate-language=lua --project=%s"
17+ local s , _ = string.find (cmd , " %s" )
18+ if s ~= nil then
19+ cmd = string.format (cmd ,
20+ string.match (lfs .currentdir (), " [^/]+$" )
21+ )
22+ end
23+ os.execute (cmd )
24+ return " "
25+ end
26+
1127--- get distribution
1228--- @return string
1329local function get_distribution ()
@@ -95,8 +111,9 @@ local function generate_ps1(char, sections)
95111 char = char or " ❯ "
96112 sections = sections or {
97113 --- @diagnostic disable : missing-parameter
98- {" black" , " yellow" , get_icon ()}, {" blue" , " black" , get_version ()},
99- {" white" , " blue" , get_cwd }, {" black" , " white" , get_time }
114+ { " " , " " , wakatime },
115+ { " black" , " yellow" , get_icon () }, { " blue" , " black" , get_version () },
116+ { " white" , " blue" , get_cwd }, { " black" , " white" , get_time }
100117 }
101118 local sep = " "
102119 local format = " %s "
@@ -113,23 +130,26 @@ local function generate_ps1(char, sections)
113130 else
114131 local fg , bg , text = table.unpack (v )
115132 if type (text ) == " function" then text = text () end
116- text = string.format (format , text )
117- if last_bg == " " then
118- ps1 = ps1 .. " %{" .. fg .. " " .. bg .. " bg}" .. text
119- else
120- ps1 = ps1 .. " %{" .. last_bg .. " " .. bg .. " bg}" .. sep ..
121- " %{" .. fg .. " }" .. text
133+ if text ~= " " then
134+ text = string.format (format , text )
135+ if last_bg == " " then
136+ ps1 = ps1 .. " %{" .. fg .. " " .. bg .. " bg}" .. text
137+ else
138+ ps1 = ps1 .. " %{" .. last_bg .. " " .. bg .. " bg}" .. sep ..
139+ " %{" .. fg .. " }" .. text
140+ end
141+ last_bg = bg
122142 end
123- last_bg = bg
124143 end
125144 end
126- ps1 = ps1 .. " %{reset " .. last_bg .. " } "
145+ ps1 = ps1 .. " %{reset " .. last_bg .. " }" .. sep
127146 return ansicolors (ps1 ) .. " \n " .. char
128147 end
129148end
130149
131150--- @export
132151return {
152+ wakatime = wakatime ,
133153 get_distribution = get_distribution ,
134154 get_os = get_os ,
135155 get_icon = get_icon ,
0 commit comments