Skip to content

Commit 999fb0d

Browse files
feat: check for individual shell lines and remove them accordingly
1 parent 988e0f1 commit 999fb0d

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Sources/Swiftly/SelfUninstall.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,14 @@ struct SelfUninstall: SwiftlyCommand {
5252
let swiftlyHome = Swiftly.currentPlatform.swiftlyHomeDir(ctx)
5353
let swiftlyBin = Swiftly.currentPlatform.swiftlyBinDir(ctx)
5454

55-
let fishSourceLine = """
55+
let commentLine = """
5656
# Added by swiftly
57-
57+
"""
58+
let fishSourceLine = """
5859
source "\(swiftlyHome / "env.fish")"
5960
"""
6061

6162
let shSourceLine = """
62-
# Added by swiftly
63-
6463
. "\(swiftlyHome / "env.sh")"
6564
"""
6665

@@ -88,11 +87,13 @@ struct SelfUninstall: SwiftlyCommand {
8887
let isFish = path.extension == "fish"
8988
let sourceLine = isFish ? fishSourceLine : shSourceLine
9089
let contents = try String(contentsOf: path, encoding: .utf8)
91-
if contents.contains(sourceLine) {
92-
let updated = contents.replacingOccurrences(of: sourceLine, with: "")
93-
try Data(updated.utf8).write(to: path, options: [.atomic])
90+
let linesToRemove = [sourceLine, commentLine]
91+
var updatedContents = contents
92+
for line in linesToRemove where contents.contains(line) {
93+
updatedContents = updatedContents.replacingOccurrences(of: line, with: "")
94+
try Data(updatedContents.utf8).write(to: path, options: [.atomic])
9495
if verbose {
95-
await ctx.print("\(path) was updated to remove swiftly source line.")
96+
await ctx.print("\(path) was updated to remove swiftly line: \(line)")
9697
}
9798
}
9899
}

0 commit comments

Comments
 (0)