-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathcmd.go
More file actions
57 lines (53 loc) · 1.39 KB
/
Copy pathcmd.go
File metadata and controls
57 lines (53 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package shell
import (
_ "embed"
"strings"
)
//go:embed scripts/omp.lua
var cmdInit string
func (f Features) Cmd() Code {
switch f {
case Transient:
return "transient_enabled = true"
case RPrompt:
return "rprompt_enabled = true"
case FTCSMarks:
return "ftcs_marks_enabled = true"
case Tooltips:
return "enable_tooltips()"
case Upgrade:
return `os.execute(string.format('"%s" upgrade --auto', omp_executable))`
case Notice:
return `if clink.onbeginedit then
local need_notice = true
clink.onbeginedit(function()
if need_notice then
need_notice = false
os.execute(string.format('"%s" notice', omp_executable))
end
end)
else
os.execute(string.format('"%s" notice', omp_executable))
end`
case Streaming:
return "if os.getenv(\"POSH_DISABLE_STREAMING\") == nil then\n serve_enabled = true\nend"
case PromptMark, PoshGit, Azure, LineError, Jobs, CursorPositioning, Async, KeyHandlers, VIMode:
fallthrough
default:
return ""
}
}
func escapeLuaStr(str string) string {
if str == "" {
return str
}
// We only replace a minimal set of special characters with corresponding escape sequences, without adding surrounding quotes.
// That way the result can be later quoted with either single or double quotes in a Lua script.
return strings.NewReplacer(
`\`, `\\`,
"'", `\'`,
`"`, `\"`,
"\n", `\n`,
"\r", `\r`,
).Replace(str)
}