Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Quote what the shell wouldn't read back in a Git command
Țugui Dragoș1204548cd911
diff --git a/Packages/PeelCore/Sources/PeelCore/Terminal/GitSetting.swift b/Packages/PeelCore/Sources/PeelCore/Terminal/GitSetting.swiftindex f1777819..41632014 100644--- a/Packages/PeelCore/Sources/PeelCore/Terminal/GitSetting.swift+++ b/Packages/PeelCore/Sources/PeelCore/Terminal/GitSetting.swift@@ -50,10 +50,7 @@ public enum GitSetting: CaseIterable, Sendable {}public func commands(signingKey: String?) -> [String] {- values(signingKey: signingKey).map { value in- let shown = value.value.contains(" ") ? value.value.quotedForTheShell : value.value- return "git config --global \(value.key) \(shown)"- }+ values(signingKey: signingKey).map { "git config --global \($0.key) \($0.value.wordForTheShell)" }}/// What turning the setting on writes. Signing needs a public key, so without one it writes nothing.diff --git a/Packages/PeelCore/Sources/PeelCore/Terminal/PathBelowHome.swift b/Packages/PeelCore/Sources/PeelCore/Terminal/PathBelowHome.swiftindex 82152bab..76b580e8 100644--- a/Packages/PeelCore/Sources/PeelCore/Terminal/PathBelowHome.swift+++ b/Packages/PeelCore/Sources/PeelCore/Terminal/PathBelowHome.swift@@ -13,8 +13,7 @@ extension URL {/// The path as a command in Terminal takes it: from `~` when it is in the home folder and needs no quoting,/// and otherwise whole, in single quotes.func pathForTheShell(home: URL) -> String {- let plain: (Character) -> Bool = { $0.isASCII && ($0.isLetter || $0.isNumber || "._/-".contains($0)) }- if let below = path(below: home), below.allSatisfy(plain) {+ if let below = path(below: home), below.isPlainForTheShell {return "~/" + below}return path(percentEncoded: false).quotedForTheShell@@ -26,6 +25,16 @@ extension String {var quotedForTheShell: String {"'" + replacing("'", with: "'\\''") + "'"}++ /// The text as one word of a command: as it is when the shell reads it back unchanged, a `~/` in front included,+ /// and otherwise in single quotes.+ var wordForTheShell: String {+ (hasPrefix("~/") ? String(dropFirst(2)) : self).isPlainForTheShell ? self : quotedForTheShell+ }++ fileprivate var isPlainForTheShell: Bool {+ allSatisfy { $0.isASCII && ($0.isLetter || $0.isNumber || "._/-".contains($0)) }+ }}enum ShellCommand {diff --git a/Packages/PeelCore/Tests/PeelCoreTests/GitSettingsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/GitSettingsTests.swiftindex 69453372..d195c997 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/GitSettingsTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/GitSettingsTests.swift@@ -46,6 +46,9 @@ struct GitSettingsTests {])#expect(GitSetting.signCommits.commands(signingKey: "~/.ssh/id_ed25519.pub")[1]== "git config --global user.signingKey ~/.ssh/id_ed25519.pub")+ #expect(GitSetting.signCommits.commands(signingKey: "~/.ssh/o'neil.pub")[1]+ == #"git config --global user.signingKey '~/.ssh/o'\''neil.pub'"#)+ #expect(GitSetting.branchesByDate.commands(signingKey: nil) == ["git config --global branch.sort -committerdate"])}@Test func everySettingTurnsOnAndOffThroughGitAndLeavesNothingBehind() async throws {