-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.go
More file actions
55 lines (52 loc) · 1.84 KB
/
init.go
File metadata and controls
55 lines (52 loc) · 1.84 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
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
)
func zshInitScript(cfg config) string {
bin := "mehshell"
if exe, err := os.Executable(); err == nil {
if resolved, err := filepath.EvalSymlinks(exe); err == nil {
bin = resolved
} else {
bin = exe
}
}
var b strings.Builder
b.WriteString("zmodload zsh/datetime 2>/dev/null\n")
b.WriteString("typeset -gi _mehshell_ts=0\n")
if cfg.InstantPrompt {
b.WriteString("[[ -r \"${XDG_CACHE_HOME:-$HOME/.cache}/mehshell-prompt-cache\" ]] && source \"${XDG_CACHE_HOME:-$HOME/.cache}/mehshell-prompt-cache\"\n")
}
b.WriteString("_mehshell_preexec() { _mehshell_ts=$EPOCHSECONDS }\n")
b.WriteString("_mehshell_precmd() {\n")
b.WriteString(" local e=$? d=0\n")
b.WriteString(" (( _mehshell_ts > 0 )) && d=$(( EPOCHSECONDS - _mehshell_ts ))\n")
b.WriteString(" _mehshell_ts=0\n")
b.WriteString(fmt.Sprintf(" local _out=\"$(%s $e $d $COLUMNS)\"\n", bin))
b.WriteString(" eval \"$_out\"\n")
if cfg.InstantPrompt {
b.WriteString(" print -r -- \"$_out\" >| \"${XDG_CACHE_HOME:-$HOME/.cache}/mehshell-prompt-cache\" 2>/dev/null\n")
}
b.WriteString("}\n")
if cfg.ViMode {
b.WriteString("_mehshell_zle_keymap_select() {\n")
b.WriteString(" [[ $KEYMAP == vicmd ]] && PROMPT=\"${PROMPT/❯/❮}\" || PROMPT=\"${PROMPT/❮/❯}\"\n")
b.WriteString(" zle reset-prompt\n")
b.WriteString("}\n")
b.WriteString("zle -N zle-keymap-select _mehshell_zle_keymap_select\n")
}
if cfg.TransientPrompt {
b.WriteString("_mehshell_accept_line() {\n")
b.WriteString(" PROMPT=$'%F{76}❯%f '\n")
b.WriteString(" zle reset-prompt\n")
b.WriteString(" zle .accept-line\n")
b.WriteString("}\n")
b.WriteString("zle -N accept-line _mehshell_accept_line\n")
}
b.WriteString("preexec_functions+=(_mehshell_preexec)\n")
b.WriteString("precmd_functions+=(_mehshell_precmd)")
return b.String()
}