mirror of
https://github.com/ddworken/hishtory.git
synced 2025-02-08 22:50:44 +01:00
Improve sh config file tweak function to make it stricter with presaving
This commit is contained in:
parent
1d7ba41289
commit
4c912cfaed
@ -424,23 +424,23 @@ func isBashProfileConfigured(homedir string) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func tweakConfigForTests(configContents string) (string, error) {
|
func tweakConfigForTests(configContents string) (string, error) {
|
||||||
madeSubstitution := false
|
substitutionCount := 0
|
||||||
skipLineIndex := -1
|
removedCount := 0
|
||||||
ret := ""
|
ret := ""
|
||||||
split := strings.Split(configContents, "\n")
|
split := strings.Split(configContents, "\n")
|
||||||
for i, line := range split {
|
for i, line := range split {
|
||||||
if strings.Contains(line, "# Background Run") {
|
if strings.Contains(line, "# Background Run") {
|
||||||
ret += strings.ReplaceAll(split[i+1], "# hishtory", "hishtory")
|
ret += strings.ReplaceAll(split[i+1], "# hishtory", "hishtory")
|
||||||
madeSubstitution = true
|
substitutionCount += 1
|
||||||
skipLineIndex = i + 1
|
} else if strings.Contains(line, "# Foreground Run") {
|
||||||
} else if i == skipLineIndex {
|
removedCount += 1
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
ret += line
|
ret += line
|
||||||
}
|
}
|
||||||
ret += "\n"
|
ret += "\n"
|
||||||
}
|
}
|
||||||
if !madeSubstitution {
|
if !(substitutionCount == 2 && removedCount == 2) {
|
||||||
return "", fmt.Errorf("failed to find substitution line in configConents=%#v", configContents)
|
return "", fmt.Errorf("failed to find substitution line in configConents=%#v", configContents)
|
||||||
}
|
}
|
||||||
return ret, nil
|
return ret, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user