rename sh2/scripthaus to prompt. maxcommandlen set.

This commit is contained in:
sawka 2022-12-19 17:36:19 -08:00
parent 8624e9c844
commit 35006dfc65
6 changed files with 39 additions and 35 deletions

View File

@ -400,8 +400,8 @@ func main() {
return
}
scHomeDir := scbase.GetScHomeDir()
log.Printf("[scripthaus] homedir = %q\n", scHomeDir)
scHomeDir := scbase.GetPromptHomeDir()
log.Printf("[prompt] homedir = %q\n", scHomeDir)
scLock, err := scbase.AcquireSCLock()
if err != nil || scLock == nil {

View File

@ -42,14 +42,15 @@ const MaxNameLen = 50
const MaxRemoteAliasLen = 50
const PasswordUnchangedSentinel = "--unchanged--"
const DefaultPTERM = "MxM"
const MaxCommandLen = 4096
var ColorNames = []string{"black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "orange"}
var RemoteColorNames = []string{"red", "green", "yellow", "blue", "magenta", "cyan", "white", "orange"}
var RemoteSetArgs = []string{"alias", "connectmode", "key", "password", "autoinstall", "color"}
var WindowCmds = []string{"run", "comment", "cd", "cr", "clear", "sw", "alias", "unalias", "function", "reset"}
var NoHistCmds = []string{"_compgen", "line", "history"}
var GlobalCmds = []string{"session", "screen", "remote", "killserver", "set"}
var WindowCmds = []string{"run", "comment", "cd", "cr", "clear", "sw", "reset"}
var NoHistCmds = []string{"_compgen", "line", "_history", "_killserver"}
var GlobalCmds = []string{"session", "screen", "remote", "set"}
var SetVarNameMap map[string]string = map[string]string{
"tabcolor": "screen.tabcolor",
@ -108,7 +109,7 @@ func init() {
registerCmdFn("cr", CrCommand)
registerCmdFn("_compgen", CompGenCommand)
registerCmdFn("clear", ClearCommand)
registerCmdFn("reset", ResetCommand)
registerCmdFn("reset", RemoteResetCommand)
registerCmdFn("session", SessionCommand)
registerCmdFn("session:open", SessionOpenCommand)
@ -143,9 +144,9 @@ func init() {
registerCmdFn("line:show", LineShowCommand)
registerCmdFn("line:star", LineStarCommand)
registerCmdFn("history", HistoryCommand)
registerCmdFn("_history", HistoryCommand)
registerCmdFn("killserver", KillServerCommand)
registerCmdFn("_killserver", KillServerCommand)
registerCmdFn("set", SetCommand)
}
@ -332,6 +333,9 @@ func EvalCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.
if len(pk.Args) == 0 {
return nil, fmt.Errorf("usage: /eval [command], no command passed to eval")
}
if len(pk.Args[0]) > MaxCommandLen {
return nil, fmt.Errorf("command length too long len:%d, max:%d", len(pk.Args[0]), MaxCommandLen)
}
var historyContext historyContextType
ctxWithHistory := context.WithValue(ctx, historyContextKey, &historyContext)
var update sstore.UpdatePacket
@ -1359,7 +1363,7 @@ func SessionCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (ssto
return update, nil
}
func ResetCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) {
func RemoteResetCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sstore.UpdatePacket, error) {
ids, err := resolveUiIds(ctx, pk, R_Session|R_Screen|R_Window)
if err != nil {
return nil, err

View File

@ -746,9 +746,9 @@ func (msh *MShellProc) writeToPtyBuffer_nolock(strFmt string, args ...interface{
realStr = realStr + "\r\n"
}
if strings.HasPrefix(realStr, "*") {
realStr = "\033[0m\033[31mscripthaus>\033[0m " + realStr[1:]
realStr = "\033[0m\033[31mprompt>\033[0m " + realStr[1:]
} else {
realStr = "\033[0m\033[32mscripthaus>\033[0m " + realStr
realStr = "\033[0m\033[32mprompt>\033[0m " + realStr
}
barr := msh.PtyBuffer.Bytes()
if len(barr) > 0 && barr[len(barr)-1] != '\n' {
@ -955,8 +955,8 @@ func addScVarsToState(state *packet.ShellState) *packet.ShellState {
}
rtn := *state
envMap := shexec.DeclMapFromState(&rtn)
envMap["SCRIPTHAUS"] = &shexec.DeclareDeclType{Name: "SCRIPTHAUS", Value: "1"}
envMap["SCRIPTHAUS_VERSION"] = &shexec.DeclareDeclType{Name: "SCRIPTHAUS_VERSION", Value: scbase.ScriptHausVersion}
envMap["PROMPT"] = &shexec.DeclareDeclType{Name: "PROMPT", Value: "1"}
envMap["PROMPT_VERSION"] = &shexec.DeclareDeclType{Name: "PROMPT_VERSION", Value: scbase.PromptVersion}
rtn.ShellVars = shexec.SerializeDeclMap(envMap)
return &rtn
}
@ -968,8 +968,8 @@ func stripScVarsFromState(state *packet.ShellState) *packet.ShellState {
rtn := *state
rtn.HashVal = ""
envMap := shexec.DeclMapFromState(&rtn)
delete(envMap, "SCRIPTHAUS")
delete(envMap, "SCRIPTHAUS_VERSION")
delete(envMap, "PROMPT")
delete(envMap, "PROMPT_VERSION")
rtn.ShellVars = shexec.SerializeDeclMap(envMap)
return &rtn
}
@ -985,8 +985,8 @@ func stripScVarsFromStateDiff(stateDiff *packet.ShellStateDiff) *packet.ShellSta
if err != nil {
return stateDiff
}
delete(mapDiff.ToAdd, "SCRIPTHAUS")
delete(mapDiff.ToAdd, "SCRIPTHAUS_VERSION")
delete(mapDiff.ToAdd, "PROMPT")
delete(mapDiff.ToAdd, "PROMPT_VERSION")
rtn.VarsDiff = mapDiff.Encode()
return &rtn
}

View File

@ -18,31 +18,31 @@ import (
)
const HomeVarName = "HOME"
const ScHomeVarName = "SCRIPTHAUS_HOME"
const PromptHomeVarName = "PROMPT_HOME"
const SessionsDirBaseName = "sessions"
const SCLockFile = "sh2.lock"
const ScriptHausDirName = "scripthaus"
const ScriptHausAppPathVarName = "SCRIPTHAUS_APP_PATH"
const ScriptHausVersion = "v0.1.0"
const SCLockFile = "prompt.lock"
const PromptDirName = "prompt"
const PromptAppPathVarName = "PROMPT_APP_PATH"
const PromptVersion = "v0.1.0"
var SessionDirCache = make(map[string]string)
var BaseLock = &sync.Mutex{}
// must match js
func GetScHomeDir() string {
scHome := os.Getenv(ScHomeVarName)
func GetPromptHomeDir() string {
scHome := os.Getenv(PromptHomeVarName)
if scHome == "" {
homeVar := os.Getenv(HomeVarName)
if homeVar == "" {
homeVar = "/"
}
scHome = path.Join(homeVar, ScriptHausDirName)
scHome = path.Join(homeVar, PromptDirName)
}
return scHome
}
func MShellBinaryFromPackage(version string, goos string, goarch string) (io.ReadCloser, error) {
appPath := os.Getenv(ScriptHausAppPathVarName)
appPath := os.Getenv(PromptAppPathVarName)
if appPath == "" {
return base.MShellBinaryFromOptDir(version, goos, goarch)
}
@ -64,10 +64,10 @@ func MShellBinaryFromPackage(version string, goos string, goarch string) (io.Rea
}
func AcquireSCLock() (*os.File, error) {
homeDir := GetScHomeDir()
homeDir := GetPromptHomeDir()
err := ensureDir(homeDir)
if err != nil {
return nil, fmt.Errorf("cannot find/create SCRIPTHAUS_HOME directory %q", homeDir)
return nil, fmt.Errorf("cannot find/create PROMPT_HOME directory %q", homeDir)
}
lockFileName := path.Join(homeDir, SCLockFile)
fd, err := os.Create(lockFileName)
@ -92,7 +92,7 @@ func EnsureSessionDir(sessionId string) (string, error) {
if ok {
return sdir, nil
}
scHome := GetScHomeDir()
scHome := GetPromptHomeDir()
sdir = path.Join(scHome, SessionsDirBaseName, sessionId)
err := ensureDir(sdir)
if err != nil {
@ -111,7 +111,7 @@ func ensureDir(dirName string) error {
if err != nil {
return err
}
log.Printf("[scripthaus] created directory %q\n", dirName)
log.Printf("[prompt] created directory %q\n", dirName)
info, err = os.Stat(dirName)
}
if err != nil {

View File

@ -29,7 +29,7 @@ import (
const LineTypeCmd = "cmd"
const LineTypeText = "text"
const LineNoHeight = -1
const DBFileName = "sh2.db"
const DBFileName = "prompt.db"
const DefaultSessionName = "default"
const DefaultWindowName = "default"
@ -75,7 +75,7 @@ var globalDB *sqlx.DB
var globalDBErr error
func GetSessionDBName() string {
scHome := scbase.GetScHomeDir()
scHome := scbase.GetPromptHomeDir()
return path.Join(scHome, DBFileName)
}

View File

@ -2,15 +2,15 @@
```bash
# @scripthaus command dump-schema
sqlite3 /Users/mike/scripthaus/sh2.db .schema > db/schema.sql
sqlite3 /Users/mike/prompt/prompt.db .schema > db/schema.sql
```
```bash
# @scripthaus command opendb
sqlite3 /Users/mike/scripthaus/sh2.db
sqlite3 /Users/mike/prompt/prompt.db
```
```bash
# @scripthaus command build
go build -o ~/scripthaus/local-server cmd/main-server.go
go build -o ~/prompt/local-server cmd/main-server.go
```