1
1
--- prompt style.
2
2
local os = require " os"
3
- local string = require " string"
4
3
local table = require " table"
5
4
local lfs = require " lfs"
6
5
local ansicolors = require " ansicolors"
@@ -14,14 +13,14 @@ if table.unpack == nil then table.unpack = unpack end
14
13
local function wakatime (cmd )
15
14
cmd = cmd or " wakatime-cli --write --plugin=repl-lua-wakatime " ..
16
15
" --entity-type=app --entity=lua --alternate-language=lua --project=%s &"
17
- local s , _ = string. find (cmd , " %s" )
16
+ local s , _ = cmd : find (" %s" )
18
17
if s ~= nil then
19
18
local project = io.popen (" git rev-parse --show-toplevel 2> /dev/null" ):read ()
20
19
if project == nil then
21
20
project = lfs .currentdir ()
22
21
end
23
- project = string. match (project , " [^/]+$" )
24
- cmd = string. format (cmd , project )
22
+ project = project : match (" [^/]+$" )
23
+ cmd = cmd : format (project )
25
24
end
26
25
io.popen (cmd )
27
26
return " "
32
31
local function get_distribution ()
33
32
local line = io.popen (" lsb_release -i 2>/dev/null" ):read ()
34
33
if line == nil then return " linux" end
35
- return string.lower ( string. gsub (line , " .*:%s*" , " " ))
34
+ return line : gsub (" .*:%s*" , " " ): lower ( )
36
35
end
37
36
38
37
--- get os
@@ -41,7 +40,7 @@ local function get_os()
41
40
if os.getenv (" PREFIX" ) == " /data/data/com.termux/files/usr" then
42
41
return " android"
43
42
end
44
- local binary_format = string.match ( package.cpath , ' ([^.]+)[;|$]' )
43
+ local binary_format = package.cpath : match ( ' ([^.]+)[;|$]' )
45
44
if binary_format == " so" then
46
45
return get_distribution ()
47
46
elseif binary_format == " dll" then
@@ -81,8 +80,8 @@ local function get_version(name, logo, format)
81
80
name = name or prompt .name
82
81
logo = logo or " "
83
82
format = format or " %s "
84
- name = string. format( format , name )
85
- local version = string. gsub (_VERSION , " .*%s+" , " " )
83
+ name = format : format ( name )
84
+ local version = _VERSION : gsub (" .*%s+" , " " )
86
85
return logo .. name .. version
87
86
end
88
87
99
98
--- get cwd
100
99
--- @return string
101
100
local function get_cwd ()
102
- local cwd = string.gsub ( lfs .currentdir (), os.getenv (" HOME" ) or " " , " ~" )
103
- cwd = string. gsub (cwd , " [^/]+$" , " %%{bright}%0" )
101
+ local cwd = lfs .currentdir (): gsub ( os.getenv (" HOME" ) or " " , " ~" )
102
+ cwd = cwd : gsub (" [^/]+$" , " %%{bright}%0" )
104
103
return cwd
105
104
end
106
105
@@ -125,7 +124,7 @@ local function generate_ps1(char, sections)
125
124
local last_bg = " "
126
125
for _ , v in ipairs (sections ) do
127
126
if type (v ) == " string" then
128
- if string. match (v , " %s" ) then
127
+ if v : match (" %s" ) then
129
128
format = v
130
129
else
131
130
sep = v
@@ -134,7 +133,7 @@ local function generate_ps1(char, sections)
134
133
local fg , bg , text = table.unpack (v )
135
134
if type (text ) == " function" then text = text () end
136
135
if text ~= " " then
137
- text = string. format( format , text )
136
+ text = format : format ( text )
138
137
if last_bg == " " then
139
138
ps1 = ps1 .. " %{" .. fg .. " " .. bg .. " bg}" .. text
140
139
else
0 commit comments