Skip to content

Commit 7ba2b9c

Browse files
committed
📝 Update README.md
Add wakatime
1 parent 6b6adc3 commit 7ba2b9c

File tree

3 files changed

+53
-27
lines changed

3 files changed

+53
-27
lines changed

.pre-commit-config.yaml

Lines changed: 10 additions & 10 deletions
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.4.0
4+
rev: v4.5.0
55
hooks:
66
- id: check-added-large-files
77
- id: fix-byte-order-marker
@@ -25,7 +25,7 @@ repos:
2525
hooks:
2626
- id: remove-crlf
2727
- repo: https://github.com/codespell-project/codespell
28-
rev: v2.2.5
28+
rev: v2.2.6
2929
hooks:
3030
- id: codespell
3131
additional_dependencies:
@@ -37,23 +37,23 @@ repos:
3737
args:
3838
- --msg-filename
3939
- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
40-
rev: 2.7.2
40+
rev: 2.7.3
4141
hooks:
4242
- id: editorconfig-checker
4343
- repo: https://github.com/jumanjihouse/pre-commit-hooks
4444
rev: 3.0.0
4545
hooks:
4646
- id: check-mailmap
4747
- repo: https://github.com/rhysd/actionlint
48-
rev: v1.6.25
48+
rev: v1.6.26
4949
hooks:
5050
- id: actionlint
5151
- repo: https://github.com/adrienverge/yamllint
52-
rev: v1.32.0
52+
rev: v1.33.0
5353
hooks:
5454
- id: yamllint
5555
- repo: https://github.com/executablebooks/mdformat
56-
rev: 0.7.16
56+
rev: 0.7.17
5757
hooks:
5858
- id: mdformat
5959
additional_dependencies:
@@ -66,13 +66,13 @@ repos:
6666
- mdformat-black
6767
- mdformat-config
6868
- repo: https://github.com/DavidAnson/markdownlint-cli2
69-
rev: v0.8.1
69+
rev: v0.10.0
7070
hooks:
7171
- id: markdownlint-cli2
7272
additional_dependencies:
73-
- markdown-it-texmath@0.9.1
73+
- markdown-it-texmath
7474
- repo: https://github.com/psf/black
75-
rev: 23.7.0
75+
rev: 23.11.0
7676
hooks:
7777
- id: black
7878
- repo: https://github.com/PyCQA/isort
@@ -86,7 +86,7 @@ repos:
8686
additional_dependencies:
8787
- tomli
8888
- repo: https://github.com/kumaraditya303/mirrors-pyright
89-
rev: v1.1.322
89+
rev: v1.1.335
9090
hooks:
9191
- id: pyright
9292
- repo: https://github.com/PyCQA/bandit

README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,22 @@
3232

3333
[![luarocks](https://img.shields.io/luarocks/v/Freed-Wu/prompt-style)](https://luarocks.org/modules/Freed-Wu/prompt-style)
3434

35-
[Powerlevel10k](https://github.com/romkatv/powerlevel10k) style for [luaprompt](https://github.com/dpapavas/luaprompt).
36-
Include REPLs for:
35+
[luaprompt](https://github.com/dpapavas/luaprompt) is a good REPL of lua.
36+
This project provides:
37+
38+
- A prompt with [powerlevel10k](https://github.com/romkatv/powerlevel10k) style.
39+
- A wakatime plugin to statistic how much time you write lua in REPL.
40+
41+
![luap](https://user-images.githubusercontent.com/32936898/255322845-c4c6e13c-3b39-4315-b09b-206a1a7783ea.png)
42+
43+
Besides lua's REPL, there are many programs written in lua which provide their
44+
REPLs. This project provides some wrapper scripts to use this plugin for them:
3745

3846
- [neovim](https://neovim.io)
3947
- [luatex](https://www.luatex.org)
4048
- [pandoc](https://pandoc.org)
4149
- [neomutt](https://neomutt.org)
4250

43-
![luap](https://user-images.githubusercontent.com/32936898/255322845-c4c6e13c-3b39-4315-b09b-206a1a7783ea.png)
44-
4551
![nvimp](https://github.com/Freed-Wu/prompt-style.lua/assets/32936898/8d0b4863-15c6-4966-b8af-219c9c40c1ae)
4652

4753
![texluap](https://github.com/Freed-Wu/prompt-style.lua/assets/32936898/96d9f4c1-55fc-4ae3-87b8-7afd29f4ba0e)
@@ -69,7 +75,7 @@ See
6975
### [AUR](https://aur.archlinux.org/packages/lua-prompt-style)
7076

7177
```sh
72-
yay -S lua{,51,52,53}-prompt-style
78+
paru -S lua{,51,52,53}-prompt-style
7379
```
7480

7581
**NOTE**: REPLs use some specific version of lua.
@@ -80,7 +86,7 @@ yay -S lua{,51,52,53}-prompt-style
8086
luarocks install prompt-style
8187
```
8288

83-
## Similar Projects
89+
## Related Projects
8490

8591
- [neolua](https://github.com/nvim-neorocks/neorocks): Another lua interpreter
86-
based on neovim. It doesn't provide a REPL like lua.
92+
based on neovim like `nvimp`. It doesn't provide a REPL like lua.

prompt-style.lua

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ local prompt = require "prompt"
88
---@diagnostic disable: deprecated
99
if 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
1329
local 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
129148
end
130149

131150
---@export
132151
return {
152+
wakatime = wakatime,
133153
get_distribution = get_distribution,
134154
get_os = get_os,
135155
get_icon = get_icon,

0 commit comments

Comments
 (0)