Skip to content

Commit 9ba73a7

Browse files
committed
✨ Support lua command line options
1 parent 0331bff commit 9ba73a7

File tree

8 files changed

+324
-222
lines changed

8 files changed

+324
-222
lines changed

README.md

+60-47
Original file line numberDiff line numberDiff line change
@@ -32,70 +32,83 @@
3232

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

35-
[luaprompt](https://github.com/dpapavas/luaprompt) is a good REPL of lua.
36-
This project provides:
35+
This project provides some tools related to
36+
[luaprompt](https://github.com/dpapavas/luaprompt):
3737

38-
- A prompt with [powerlevel10k](https://github.com/romkatv/powerlevel10k) style.
38+
## A prompt with [powerlevel10k](https://github.com/romkatv/powerlevel10k) style
3939

4040
![luap](https://user-images.githubusercontent.com/32936898/255322845-c4c6e13c-3b39-4315-b09b-206a1a7783ea.png)
4141

42-
- A wakatime plugin to statistic how much time you write lua in REPL.
43-
44-
![wakatime](https://github.com/wakatime/prompt-style.lua/assets/32936898/b4397806-0ab3-4751-baaa-d9dfed92ace7)
45-
46-
Besides lua's REPL, there are many programs written in lua which provide their
47-
REPLs. This project provides some wrapper scripts to use this plugin for them:
48-
49-
- [neovim](https://neovim.io)
50-
- [luatex](https://www.luatex.org)
51-
- [pandoc](https://pandoc.org)
52-
- [neomutt](https://neomutt.org)
53-
54-
![nvimp](https://github.com/wakatime/prompt-style.lua/assets/32936898/8d0b4863-15c6-4966-b8af-219c9c40c1ae)
55-
56-
Tips: you can skip loading unnecessary plugins in your vimrc by:
57-
58-
```vim
59-
let s:l_flag = 0
60-
for arg in v:argv
61-
if s:l_flag == 1
62-
let g:script_name = fnamemodify(arg, ':t')
63-
break
64-
endif
65-
if arg ==# '-l'
66-
let s:l_flag = 1
67-
endif
68-
endfor
69-
if get(g:, 'script_name', '') ==# 'nvimp'
70-
finish
71-
endif
72-
```
73-
74-
![texluap](https://github.com/wakatime/prompt-style.lua/assets/32936898/96d9f4c1-55fc-4ae3-87b8-7afd29f4ba0e)
75-
76-
![pandocp](https://github.com/wakatime/prompt-style.lua/assets/32936898/b556effe-6be7-4cf9-b612-b1283d6de721)
77-
78-
## Usage
79-
8042
`~/.config/luaprc.lua`:
8143

8244
```lua
8345
local prompt = require "prompt"
84-
local prompt_style = require "prompt-style"
46+
local style = require "prompt.style"
8547

86-
prompt.prompts = { prompt_style.generate_ps1(), " " }
48+
prompt.prompts = { style.generate_ps1(), " " }
8749
```
8850

89-
## Customization
51+
## A wakatime plugin to statistic how much time you write lua in REPL
52+
53+
![wakatime](https://github.com/wakatime/prompt-style.lua/assets/32936898/b4397806-0ab3-4751-baaa-d9dfed92ace7)
9054

9155
If there is a git repository, the project name can be achieved by git. Else use
9256
the base name of current working directory.
93-
You can call `(require "prompt-style").wakatime("wakatime-cli XXX")` to
57+
You can call `(require "prompt.style").wakatime("wakatime-cli XXX")` to
9458
customize it.
9559

9660
See
9761
[![readthedocs](https://shields.io/readthedocs/prompt-stylelua)](https://prompt-stylelua.readthedocs.io).
9862

63+
## REPLs for many programs contains a lua interpreters
64+
65+
### Lua 5.1/LuaJIT
66+
67+
#### [neovim](https://neovim.io)
68+
69+
![cmd](https://github.com/user-attachments/assets/26a34d2e-7db9-412c-beb3-87b8598294f9)
70+
71+
`~/.config/nvim/init.lua`:
72+
73+
```lua
74+
local l_flag = false
75+
for _, arg in ipairs(vim.v.argv) do
76+
if l_flag == true then
77+
vim.g.script_name = vim.fs.basename(arg)
78+
break
79+
end
80+
if arg == "-l" then
81+
l_flag = true
82+
end
83+
end
84+
if vim.g.script_name == "nvimp" then
85+
require"prompt".name = "nvim"
86+
loadfile(vim.fs.joinpath(os.getenv("HOME"), ".config", "luaprc.lua"))()
87+
-- skip loading unnecessary vim plugins
88+
return
89+
end
90+
```
91+
92+
#### luajittex
93+
94+
Refer [luatex](#luatex).
95+
96+
### Lua 5.3
97+
98+
#### luatex
99+
100+
![texluap](https://github.com/wakatime/prompt-style.lua/assets/32936898/96d9f4c1-55fc-4ae3-87b8-7afd29f4ba0e)
101+
102+
#### [neomutt](https://neomutt.org)
103+
104+
Broken in [upstream](https://github.com/neomutt/neomutt/issues/4328)
105+
106+
### Lua 5.4
107+
108+
#### [pandoc](https://pandoc.org)
109+
110+
![pandocp](https://github.com/wakatime/prompt-style.lua/assets/32936898/b556effe-6be7-4cf9-b612-b1283d6de721)
111+
99112
## Install
100113

101114
### [AUR](https://aur.archlinux.org/packages/lua-prompt-style)
@@ -104,8 +117,6 @@ See
104117
paru -S lua{,51,52,53}-prompt-style
105118
```
106119

107-
**NOTE**: REPLs use some specific version of lua.
108-
109120
### [Luarocks](https://luarocks.org/modules/Freed-Wu/prompt-style)
110121

111122
```sh
@@ -116,3 +127,5 @@ luarocks install prompt-style
116127

117128
- [neolua](https://github.com/nvim-neorocks/neorocks): Another lua interpreter
118129
based on neovim like `nvimp`. It doesn't provide a REPL like lua.
130+
- [nlua](https://github.com/mfussenegger/nlua): Another lua interpreter
131+
based on neovim like `nvimp`. It doesn't provide a REPL like lua.

bin/neomuttp

+10-35
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,13 @@
11
#!/usr/bin/env -S sh -c 'neomutt -Belua-source\\ $0'
2-
local string = require "string"
3-
local package = require "package"
4-
local version = string.gsub(_VERSION, ".* ", "")
5-
local path = package.path
6-
local cpath = package.cpath
7-
package.path = package.path .. ";/usr/share/lua/" .. version .. "/?.lua;/usr/share/lua/" .. version .. "/?/init.lua"
8-
local ext = string.match(package.cpath, '([^.]+)[;|$]')
9-
package.cpath = package.cpath .. ";/usr/lib/lua/" .. version .. "/?." .. ext
10-
11-
local prompt = require "prompt"
12-
prompt.name = 'neomutt'
13-
prompt.prompts = { '> ', '>> ' }
14-
prompt.colorize = true
15-
prompt.history = os.getenv('HOME') .. '/.lua_history'
16-
17-
for _, name in ipairs { os.getenv('HOME') .. '/.luaprc.lua',
18-
os.getenv('HOME') .. '/.config/luaprc.lua' } do
19-
local f = io.open(name, "r")
20-
if f ~= nil then
21-
io.close(f)
22-
23-
chunk, message = loadfile(name)
24-
25-
if chunk then
26-
chunk()
27-
else
28-
print(message)
29-
end
30-
31-
break
32-
end
2+
local utils = require "prompt.utils"
3+
4+
utils.init()
5+
-- use ~/.config/neomutt/neomuttrc
6+
-- utils.source_configs()
7+
local args = utils.get_parser():parse(arg)
8+
if args.v then
9+
mutt.command.version()
10+
os.exit(0)
3311
end
34-
35-
package.path = path
36-
package.cpath = cpath
37-
prompt.enter()
12+
utils.process_args(args, parser)
3813
-- ex: filetype=lua

bin/nvimp

+11-35
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,13 @@
11
#!/usr/bin/env -S nvim --headless -l
2-
local string = require "string"
3-
local package = require "package"
4-
local version = string.gsub(_VERSION, ".* ", "")
5-
local path = package.path
6-
local cpath = package.cpath
7-
package.path = package.path .. ";/usr/share/lua/" .. version .. "/?.lua;/usr/share/lua/" .. version .. "/?/init.lua"
8-
local ext = string.match(package.cpath, '([^.]+)[;|$]')
9-
package.cpath = package.cpath .. ";/usr/lib/lua/" .. version .. "/?." .. ext
10-
11-
local prompt = require "prompt"
12-
prompt.name = 'nvim'
13-
prompt.prompts = { '> ', '>> ' }
14-
prompt.colorize = true
15-
prompt.history = os.getenv('HOME') .. '/.lua_history'
16-
17-
for _, name in ipairs { os.getenv('HOME') .. '/.luaprc.lua',
18-
os.getenv('HOME') .. '/.config/luaprc.lua' } do
19-
local f = io.open(name, "r")
20-
if f ~= nil then
21-
io.close(f)
22-
23-
chunk, message = loadfile(name)
24-
25-
if chunk then
26-
chunk()
27-
else
28-
print(message)
29-
end
30-
31-
break
32-
end
2+
local utils = require "prompt.utils"
3+
4+
utils.init()
5+
-- use ~/.config/nvim/init.vim
6+
-- utils.source_configs()
7+
local args = utils.get_parser():parse(arg)
8+
if args.v then
9+
vim.cmd.version()
10+
os.exit(0)
3311
end
34-
35-
package.path = path
36-
package.cpath = cpath
37-
prompt.enter()
12+
utils.process_args(args, parser)
13+
-- ex: filetype=lua

bin/pandocp

+6-35
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,8 @@
11
#!/usr/bin/env -S pandoc -fmarkdown /dev/null --lua-filter
2-
local string = require "string"
3-
local package = require "package"
4-
local version = string.gsub(_VERSION, ".* ", "")
5-
local path = package.path
6-
local cpath = package.cpath
7-
package.path = package.path .. ";/usr/share/lua/" .. version .. "/?.lua;/usr/share/lua/" .. version .. "/?/init.lua"
8-
local ext = string.match(package.cpath, '([^.]+)[;|$]')
9-
package.cpath = package.cpath .. ";/usr/lib/lua/" .. version .. "/?." .. ext
2+
local utils = require "prompt.utils"
103

11-
local prompt = require "prompt"
12-
prompt.name = 'pandoc'
13-
prompt.prompts = { '> ', '>> ' }
14-
prompt.colorize = true
15-
prompt.history = os.getenv('HOME') .. '/.lua_history'
16-
17-
for _, name in ipairs { os.getenv('HOME') .. '/.luaprc.lua',
18-
os.getenv('HOME') .. '/.config/luaprc.lua' } do
19-
local f = io.open(name, "r")
20-
if f ~= nil then
21-
io.close(f)
22-
23-
chunk, message = loadfile(name)
24-
25-
if chunk then
26-
chunk()
27-
else
28-
print(message)
29-
end
30-
31-
break
32-
end
33-
end
34-
35-
package.path = path
36-
package.cpath = cpath
37-
prompt.enter()
4+
utils.init()
5+
utils.source_configs()
6+
local args = utils.get_parser():parse(arg)
7+
utils.process_args(args, parser)
8+
-- ex: filetype=lua

bin/texluajitp

+6-35
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,8 @@
11
#!/usr/bin/env -S luajittex --luaonly
2-
local string = require "string"
3-
local package = require "package"
4-
local version = string.gsub(_VERSION, ".* ", "")
5-
local path = package.path
6-
local cpath = package.cpath
7-
package.path = package.path .. ";/usr/share/lua/" .. version .. "/?.lua;/usr/share/lua/" .. version .. "/?/init.lua"
8-
local ext = string.match(package.cpath, '([^.]+)[;|$]')
9-
package.cpath = package.cpath .. ";/usr/lib/lua/" .. version .. "/?." .. ext
2+
local utils = require "prompt.utils"
103

11-
local prompt = require "prompt"
12-
prompt.name = 'texlua'
13-
prompt.prompts = { '> ', '>> ' }
14-
prompt.colorize = true
15-
prompt.history = os.getenv('HOME') .. '/.lua_history'
16-
17-
for _, name in ipairs { os.getenv('HOME') .. '/.luaprc.lua',
18-
os.getenv('HOME') .. '/.config/luaprc.lua' } do
19-
local f = io.open(name, "r")
20-
if f ~= nil then
21-
io.close(f)
22-
23-
chunk, message = loadfile(name)
24-
25-
if chunk then
26-
chunk()
27-
else
28-
print(message)
29-
end
30-
31-
break
32-
end
33-
end
34-
35-
package.path = path
36-
package.cpath = cpath
37-
prompt.enter()
4+
utils.init()
5+
utils.source_configs()
6+
local args = utils.get_parser():parse(arg)
7+
utils.process_args(args, parser)
8+
-- ex: filetype=lua

bin/texluap

+6-35
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,8 @@
11
#!/usr/bin/env -S luatex --luaonly
2-
local string = require "string"
3-
local package = require "package"
4-
local version = string.gsub(_VERSION, ".* ", "")
5-
local path = package.path
6-
local cpath = package.cpath
7-
package.path = package.path .. ";/usr/share/lua/" .. version .. "/?.lua;/usr/share/lua/" .. version .. "/?/init.lua"
8-
local ext = string.match(package.cpath, '([^.]+)[;|$]')
9-
package.cpath = package.cpath .. ";/usr/lib/lua/" .. version .. "/?." .. ext
2+
local utils = require "prompt.utils"
103

11-
local prompt = require "prompt"
12-
prompt.name = 'texlua'
13-
prompt.prompts = { '> ', '>> ' }
14-
prompt.colorize = true
15-
prompt.history = os.getenv('HOME') .. '/.lua_history'
16-
17-
for _, name in ipairs { os.getenv('HOME') .. '/.luaprc.lua',
18-
os.getenv('HOME') .. '/.config/luaprc.lua' } do
19-
local f = io.open(name, "r")
20-
if f ~= nil then
21-
io.close(f)
22-
23-
chunk, message = loadfile(name)
24-
25-
if chunk then
26-
chunk()
27-
else
28-
print(message)
29-
end
30-
31-
break
32-
end
33-
end
34-
35-
package.path = path
36-
package.cpath = cpath
37-
prompt.enter()
4+
utils.init()
5+
utils.source_configs()
6+
local args = utils.get_parser():parse(arg)
7+
utils.process_args(args, parser)
8+
-- ex: filetype=lua
File renamed without changes.

0 commit comments

Comments
 (0)