Skip to content

Commit c295ae5

Browse files
committed
🎨 Improve code by OOP
1 parent 7e74079 commit c295ae5

3 files changed

+26
-40
lines changed

.pre-commit-config.yaml

+14-28
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v4.5.0
4+
rev: v4.6.0
55
hooks:
66
- id: check-added-large-files
77
- id: fix-byte-order-marker
@@ -21,11 +21,11 @@ repos:
2121
- id: check-toml
2222
- id: check-json
2323
- repo: https://github.com/Lucas-C/pre-commit-hooks
24-
rev: v1.5.4
24+
rev: v1.5.5
2525
hooks:
2626
- id: remove-crlf
2727
- repo: https://github.com/codespell-project/codespell
28-
rev: v2.2.6
28+
rev: v2.3.0
2929
hooks:
3030
- id: codespell
3131
additional_dependencies:
@@ -45,11 +45,11 @@ repos:
4545
hooks:
4646
- id: check-mailmap
4747
- repo: https://github.com/rhysd/actionlint
48-
rev: v1.6.26
48+
rev: v1.7.1
4949
hooks:
5050
- id: actionlint
5151
- repo: https://github.com/adrienverge/yamllint
52-
rev: v1.33.0
52+
rev: v1.35.1
5353
hooks:
5454
- id: yamllint
5555
- repo: https://github.com/executablebooks/mdformat
@@ -63,39 +63,25 @@ repos:
6363
- mdformat-toc
6464
- mdformat-deflist
6565
- mdformat-beautysh
66-
- mdformat-black
66+
- mdformat-ruff
6767
- mdformat-config
68+
- mdformat-web
6869
- repo: https://github.com/DavidAnson/markdownlint-cli2
69-
rev: v0.10.0
70+
rev: v0.13.0
7071
hooks:
7172
- id: markdownlint-cli2
7273
additional_dependencies:
7374
- markdown-it-texmath
74-
- repo: https://github.com/psf/black
75-
rev: 23.11.0
75+
- repo: https://github.com/astral-sh/ruff-pre-commit
76+
rev: v0.4.8
7677
hooks:
77-
- id: black
78-
- repo: https://github.com/PyCQA/isort
79-
rev: 5.12.0
80-
hooks:
81-
- id: isort
82-
- repo: https://github.com/pycqa/pydocstyle
83-
rev: 6.3.0
84-
hooks:
85-
- id: pydocstyle
86-
additional_dependencies:
87-
- tomli
78+
- id: ruff
79+
- id: ruff-format
8880
- repo: https://github.com/kumaraditya303/mirrors-pyright
89-
rev: v1.1.335
81+
rev: v1.1.366
9082
hooks:
9183
- id: pyright
92-
- repo: https://github.com/PyCQA/bandit
93-
rev: 1.7.5
94-
hooks:
95-
- id: bandit
96-
additional_dependencies:
97-
- tomli
9884
- repo: https://github.com/lunarmodules/luacheck
99-
rev: v1.1.1
85+
rev: v1.2.0
10086
hooks:
10187
- id: luacheck

prompt-style-0.0.1-0.rockspec

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ build = {
2525
type = "builtin",
2626
modules = {["prompt-style"] = "prompt-style.lua"},
2727
install = {
28+
-- cannot use _VERSION
2829
bin = {
2930
"bin/nvimp",
3031
"bin/texluap",

prompt-style.lua

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---prompt style.
22
local os = require "os"
3-
local string = require "string"
43
local table = require "table"
54
local lfs = require "lfs"
65
local ansicolors = require "ansicolors"
@@ -14,14 +13,14 @@ if table.unpack == nil then table.unpack = unpack end
1413
local function wakatime(cmd)
1514
cmd = cmd or "wakatime-cli --write --plugin=repl-lua-wakatime " ..
1615
"--entity-type=app --entity=lua --alternate-language=lua --project=%s &"
17-
local s, _ = string.find(cmd, "%s")
16+
local s, _ = cmd:find("%s")
1817
if s ~= nil then
1918
local project = io.popen("git rev-parse --show-toplevel 2> /dev/null"):read()
2019
if project == nil then
2120
project = lfs.currentdir()
2221
end
23-
project = string.match(project, "[^/]+$")
24-
cmd = string.format(cmd, project)
22+
project = project:match("[^/]+$")
23+
cmd = cmd:format(project)
2524
end
2625
io.popen(cmd)
2726
return ""
@@ -32,7 +31,7 @@ end
3231
local function get_distribution()
3332
local line = io.popen("lsb_release -i 2>/dev/null"):read()
3433
if line == nil then return "linux" end
35-
return string.lower(string.gsub(line, ".*:%s*", ""))
34+
return line:gsub(".*:%s*", ""):lower()
3635
end
3736

3837
---get os
@@ -41,7 +40,7 @@ local function get_os()
4140
if os.getenv("PREFIX") == "/data/data/com.termux/files/usr" then
4241
return "android"
4342
end
44-
local binary_format = string.match(package.cpath, '([^.]+)[;|$]')
43+
local binary_format = package.cpath:match('([^.]+)[;|$]')
4544
if binary_format == "so" then
4645
return get_distribution()
4746
elseif binary_format == "dll" then
@@ -81,8 +80,8 @@ local function get_version(name, logo, format)
8180
name = name or prompt.name
8281
logo = logo or ""
8382
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+", "")
8685
return logo .. name .. version
8786
end
8887

@@ -99,8 +98,8 @@ end
9998
---get cwd
10099
---@return string
101100
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")
104103
return cwd
105104
end
106105

@@ -125,7 +124,7 @@ local function generate_ps1(char, sections)
125124
local last_bg = ""
126125
for _, v in ipairs(sections) do
127126
if type(v) == "string" then
128-
if string.match(v, "%s") then
127+
if v:match("%s") then
129128
format = v
130129
else
131130
sep = v
@@ -134,7 +133,7 @@ local function generate_ps1(char, sections)
134133
local fg, bg, text = table.unpack(v)
135134
if type(text) == "function" then text = text() end
136135
if text ~= "" then
137-
text = string.format(format, text)
136+
text = format:format(text)
138137
if last_bg == "" then
139138
ps1 = ps1 .. "%{" .. fg .. " " .. bg .. "bg}" .. text
140139
else

0 commit comments

Comments
 (0)