Skip to content

Commit d01d372

Browse files
committed
✨ Supporting using git to get project name
1 parent 6d80a09 commit d01d372

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ prompt.prompts = { prompt_style.generate_ps1(), " " }
6767

6868
## Customization
6969

70-
By default, It uses the base name of current working directory as your project
71-
name. You can call `(require "prompt-style").wakatime("wakatime-cli XXX")` to
70+
If there is a git repository, the project name can be achieved by git. Else use
71+
the base name of current working directory.
72+
You can call `(require "prompt-style").wakatime("wakatime-cli XXX")` to
7273
customize it.
7374

7475
See

prompt-style.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ local function wakatime(cmd)
1616
"--entity-type=app --entity=lua --alternate-language=lua --project=%s"
1717
local s, _ = string.find(cmd, "%s")
1818
if s ~= nil then
19-
cmd = string.format(cmd,
20-
string.match(lfs.currentdir(), "[^/]+$")
21-
)
19+
local project = io.popen("git rev-parse --show-toplevel 2> /dev/null"):read()
20+
if project == nil then
21+
project = string.match(lfs.currentdir(), "[^/]+$")
22+
end
23+
cmd = string.format(cmd, project)
2224
end
2325
io.popen(cmd)
2426
return ""
@@ -27,7 +29,7 @@ end
2729
---get distribution
2830
---@return string
2931
local function get_distribution()
30-
local line = io.popen("lsb_release -i 2>/dev/null", "r"):read()
32+
local line = io.popen("lsb_release -i 2>/dev/null"):read()
3133
if line == nil then return "linux" end
3234
return string.lower(string.gsub(line, ".*:%s*", ""))
3335
end

0 commit comments

Comments
 (0)