Revert all commits since v0.223 to enable me to release a patch on top of v0.223

This commit is contained in:
David Dworken
2023-09-28 21:49:37 -07:00
parent d18747e639
commit 6d5a86a8bb
17 changed files with 254 additions and 567 deletions

View File

@@ -144,11 +144,8 @@ func presaveHistoryEntry(ctx context.Context) {
}
// Augment it with os.Args
shellName := os.Args[2]
cmd, err := extractCommandFromArg(ctx, shellName, os.Args[3])
lib.CheckFatalError(err)
entry.Command = cmd
if strings.HasPrefix(" ", entry.Command) || strings.TrimSpace(entry.Command) == "" {
entry.Command = trimTrailingWhitespace(os.Args[3])
if strings.HasPrefix(" ", entry.Command) || entry.Command == "" {
// Don't save commands that start with a space
return
}
@@ -157,6 +154,11 @@ func presaveHistoryEntry(ctx context.Context) {
entry.StartTime = time.Unix(startTime, 0).UTC()
entry.EndTime = time.Unix(0, 0).UTC()
// Skip saving references to presaving
if strings.Contains(entry.Command, "presaveHistoryEntry") || strings.Contains(entry.Command, "__history_control_r") {
return
}
// And persist it locally.
db := hctx.GetDb(ctx)
err = lib.ReliableDbCreate(db, *entry)
@@ -379,11 +381,34 @@ func buildHistoryEntry(ctx context.Context, args []string) (*data.HistoryEntry,
entry.EndTime = time.Now().UTC()
// command
cmd, err := extractCommandFromArg(ctx, shell, args[4])
if err != nil {
return nil, err
if shell == "bash" {
cmd, err := getLastCommand(args[4])
if err != nil {
return nil, fmt.Errorf("failed to build history entry: %w", err)
}
shouldBeSkipped, err := shouldSkipHiddenCommand(ctx, args[4])
if err != nil {
return nil, fmt.Errorf("failed to check if command was hidden: %w", err)
}
if shouldBeSkipped || strings.HasPrefix(cmd, " ") {
// Don't save commands that start with a space
return nil, nil
}
cmd, err = maybeSkipBashHistTimePrefix(cmd)
if err != nil {
return nil, err
}
entry.Command = cmd
} else if shell == "zsh" || shell == "fish" {
cmd := trimTrailingWhitespace(args[4])
if strings.HasPrefix(cmd, " ") {
// Don't save commands that start with a space
return nil, nil
}
entry.Command = cmd
} else {
return nil, fmt.Errorf("tried to save a hishtory entry from an unsupported shell=%#v", shell)
}
entry.Command = cmd
if strings.TrimSpace(entry.Command) == "" {
// Skip recording empty commands where the user just hits enter in their terminal
return nil, nil
@@ -392,38 +417,6 @@ func buildHistoryEntry(ctx context.Context, args []string) (*data.HistoryEntry,
return entry, nil
}
func extractCommandFromArg(ctx context.Context, shell, arg string) (string, error) {
if shell == "bash" {
cmd, err := getLastCommand(arg)
if err != nil {
return "", fmt.Errorf("failed to build history entry: %w", err)
}
shouldBeSkipped, err := shouldSkipHiddenCommand(ctx, arg)
if err != nil {
return "", fmt.Errorf("failed to check if command was hidden: %w", err)
}
if shouldBeSkipped || strings.HasPrefix(cmd, " ") {
// Don't save commands that start with a space
return "", nil
}
cmd, err = maybeSkipBashHistTimePrefix(cmd)
if err != nil {
return "", err
}
return cmd, nil
} else if shell == "zsh" || shell == "fish" {
cmd := trimTrailingWhitespace(arg)
if strings.HasPrefix(cmd, " ") {
// Don't save commands that start with a space
return "", nil
}
return cmd, nil
} else {
return "", fmt.Errorf("tried to save a hishtory entry from an unsupported shell=%#v", shell)
}
}
func trimTrailingWhitespace(s string) string {
return strings.TrimSuffix(strings.TrimSuffix(s, "\n"), " ")
}