@@ -52,15 +52,14 @@ struct SelfUninstall: SwiftlyCommand {
52
52
let swiftlyHome = Swiftly . currentPlatform. swiftlyHomeDir ( ctx)
53
53
let swiftlyBin = Swiftly . currentPlatform. swiftlyBinDir ( ctx)
54
54
55
- let fishSourceLine = """
55
+ let commentLine = """
56
56
# Added by swiftly
57
-
57
+ """
58
+ let fishSourceLine = """
58
59
source " \( swiftlyHome / " env.fish " ) "
59
60
"""
60
61
61
62
let shSourceLine = """
62
- # Added by swiftly
63
-
64
63
. " \( swiftlyHome / " env.sh " ) "
65
64
"""
66
65
@@ -88,11 +87,13 @@ struct SelfUninstall: SwiftlyCommand {
88
87
let isFish = path. extension == " fish "
89
88
let sourceLine = isFish ? fishSourceLine : shSourceLine
90
89
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] )
94
95
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) " )
96
97
}
97
98
}
98
99
}
0 commit comments