mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-20 20:07:52 +02:00
Make bash support lenient with empty history lines, which seems to happen for the first command or two of new installs
This commit is contained in:
parent
86833a6109
commit
1ff299c86a
@ -412,6 +412,9 @@ func buildHistoryEntry(ctx context.Context, args []string) (*data.HistoryEntry,
|
|||||||
func extractCommandFromArg(ctx context.Context, shell, arg string, isPresave bool) (string, error) {
|
func extractCommandFromArg(ctx context.Context, shell, arg string, isPresave bool) (string, error) {
|
||||||
if shell == "bash" {
|
if shell == "bash" {
|
||||||
cmd, err := getLastCommand(arg)
|
cmd, err := getLastCommand(arg)
|
||||||
|
if cmd == "" {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to build history entry: %w", err)
|
return "", fmt.Errorf("failed to build history entry: %w", err)
|
||||||
}
|
}
|
||||||
@ -583,6 +586,9 @@ func parseCrossPlatformTime(data string) time.Time {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getLastCommand(history string) (string, error) {
|
func getLastCommand(history string) (string, error) {
|
||||||
|
if history == "" {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
split := strings.SplitN(strings.TrimSpace(history), " ", 2)
|
split := strings.SplitN(strings.TrimSpace(history), " ", 2)
|
||||||
if len(split) <= 1 {
|
if len(split) <= 1 {
|
||||||
return "", fmt.Errorf("got unexpected bash history line: %#v, please open a bug at github.com/ddworken/hishtory", history)
|
return "", fmt.Errorf("got unexpected bash history line: %#v, please open a bug at github.com/ddworken/hishtory", history)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user