-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
32 lines (29 loc) · 1.3 KB
/
main.go
File metadata and controls
32 lines (29 loc) · 1.3 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
package main
import (
"flag"
"fmt"
)
func main() {
bashHack := flag.Bool("bash-readline-hack", true, "Wraps escape codes in \\x01 and \\x02, so that GNU Readline understands that they have no width")
defaultColor := flag.Int("default", 34, "color for normal directories (ANSI escape codes)")
symlinkColor := flag.Int("symlink", 36, "color for symlinks")
openWriteColor := flag.Int("open-write", 42, "color open write permissions")
sizeBuffer := flag.Int("size-buffer", 10, "how much extra space to leave between the end of the prompt and the middle of the screen")
flag.Parse()
prompt := InitPrompt()
ShadowHome(prompt)
maxPromptSize := GetMaxPromptSize(*sizeBuffer)
charsToCut := GetCharsToCut(prompt, maxPromptSize)
truncationTarget := GetTruncationTarget(prompt, charsToCut)
SetAbbreviations(prompt, truncationTarget)
StylePrompt(prompt, *defaultColor, *symlinkColor, *openWriteColor)
if *bashHack {
// Bash can recognize escape codes in your PS1, but only if they are statically defined
// When `prompter` prints them, Bash doesn't realize it has to explain them to GNU Readline
// If your cursor jumps around when you scroll through your command history
// then there's a bug here.
fmt.Print(ExplainZeroWidthEscapeCodesToGNUReadline(prompt.Format()))
} else {
fmt.Print(prompt.Format())
}
}