mirror of
https://github.com/wavetermdev/backup.git
synced 2026-08-05 13:57:07 -07:00
zsh fixes (zmodload, k8s, new var type, track zsh prompt) (#473)
* checkpoint. track zmodloads, get the expanded PS1 value, change how we store and deal with 'prompt vars', add commands to track k8s context * fix some warnings, change IsPVar to IsExtVar, checkpoint * parse zmodloads into state * restore zmodloads, be more careful around readonly variable setting to avoid errors
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"bytes"
|
||||
"crypto/sha1"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
@@ -400,7 +401,7 @@ func DecodeStringArray(barr []byte) ([]string, error) {
|
||||
return rtn, nil
|
||||
}
|
||||
|
||||
func EncodedStringArrayHasFirstKey(encoded []byte, firstKey string) bool {
|
||||
func EncodedStringArrayHasFirstVal(encoded []byte, firstKey string) bool {
|
||||
firstKeyBytes := NullEncodeStr(firstKey)
|
||||
if !bytes.HasPrefix(encoded, firstKeyBytes) {
|
||||
return false
|
||||
@@ -411,6 +412,18 @@ func EncodedStringArrayHasFirstKey(encoded []byte, firstKey string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// on encoding error returns ""
|
||||
// this is used to perform logic on first value without decoding the entire array
|
||||
func EncodedStringArrayGetFirstVal(encoded []byte) string {
|
||||
sepIdx := bytes.IndexByte(encoded, nullEncodeSepByte)
|
||||
if sepIdx == -1 {
|
||||
str, _ := NullDecodeStr(encoded)
|
||||
return str
|
||||
}
|
||||
str, _ := NullDecodeStr(encoded[0:sepIdx])
|
||||
return str
|
||||
}
|
||||
|
||||
// encodes a string, removing null/zero bytes (and separators '|')
|
||||
// a zero byte is encoded as "\0", a '\' is encoded as "\\", sep is encoded as "\s"
|
||||
// allows for easy double splitting (first on \x00, and next on "|")
|
||||
@@ -520,3 +533,22 @@ func CombineStrArrays(sarr1 []string, sarr2 []string) []string {
|
||||
}
|
||||
return rtn
|
||||
}
|
||||
|
||||
func QuickJson(v interface{}) string {
|
||||
barr, _ := json.Marshal(v)
|
||||
return string(barr)
|
||||
}
|
||||
|
||||
func QuickParseJson[T any](s string) T {
|
||||
var v T
|
||||
_ = json.Unmarshal([]byte(s), &v)
|
||||
return v
|
||||
}
|
||||
|
||||
func StrArrayToMap(sarr []string) map[string]bool {
|
||||
m := make(map[string]bool)
|
||||
for _, s := range sarr {
|
||||
m[s] = true
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user