Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Don't run the person's .zlogout when asking zsh which prompt it shows

Țugui Dragoșf7b567f44d1a
diff --git a/Packages/PeelCore/Sources/PeelCore/Terminal/ShellSessions.swift b/Packages/PeelCore/Sources/PeelCore/Terminal/ShellSessions.swift
index 80a5fd98..15fc3855 100644
--- a/Packages/PeelCore/Sources/PeelCore/Terminal/ShellSessions.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Terminal/ShellSessions.swift
@@ -58,7 +58,7 @@ public enum ShellSessions: Sendable, Equatable {
"/bin/zsh", ["-l", "-c", #"print -r -- "peel-zdotdir:${ZDOTDIR:-$HOME}""#],
environment: environment, timeout: 10
)
- // The startup files may print too, before the answer and at logout after it.
+ // The startup files may print too.
let marker = "peel-zdotdir:/"
let named: String? = if case .success(let output) = answer, output.status == 0,
let line = output.text.split(separator: "\n").last(where: { $0.hasPrefix(marker) }) {
@@ -95,7 +95,9 @@ public enum ShellSessions: Sendable, Equatable {
if let zdotdir, !zdotdir.isEmpty {
environment["ZDOTDIR"] = (zdotdir as NSString).standardizingPath
}
+ // An interactive login shell reads `.zlogout` as it exits, and nobody is logging out (`man zshoptions`, RCS).
let script = """
+ setopt no_rcs
typeset -g peel_was="$PROMPT"; typeset -ga peel_by=()
for peel_f in $precmd_functions; do
"$peel_f" 2>/dev/null
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ShellSessionsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ShellSessionsTests.swift
index 4a4cc51a..0d5e5235 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/ShellSessionsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/ShellSessionsTests.swift
@@ -10,7 +10,6 @@ struct ShellSessionsTests {
try directory.file(
"home/.zprofile", contents: Data("export ZDOTDIR=\"$HOME/.config/zsh\"\nprint \"said at login\"\n".utf8)
)
- try directory.file("home/.zlogout", contents: Data("print \"said at logout\"\n".utf8))
let zsh = ShellSessions.zsh(startupFile: home.appending(path: ".zshenv"))
let zshrc = await zsh.zshrc(home: home, zdotdir: nil)
@@ -18,6 +17,22 @@ struct ShellSessionsTests {
#expect(zshrc?.path(percentEncoded: false).hasSuffix("home/.config/zsh/.zshrc") == true)
}
+ @Test func askingZshAQuestionRunsNoLogoutFile() async throws {
+ let directory = try TemporaryDirectory()
+ let home = try directory.directory("home")
+ let loggedOut = directory.url.appending(path: "logged-out")
+ let line = "print >> \(loggedOut.path(percentEncoded: false).quotedForTheShell)\n"
+ try directory.file("home/.zlogout", contents: Data(line.utf8))
+ let zsh = ShellSessions.zsh(startupFile: home.appending(path: ".zshenv"))
+
+ let shown = await zsh.promptShown(home: home, zdotdir: nil)
+ let zshrc = await zsh.zshrc(home: home, zdotdir: nil)
+
+ #expect(shown != nil)
+ #expect(zshrc != nil)
+ #expect(!FileManager.default.fileExists(atPath: loggedOut.path(percentEncoded: false)))
+ }
+
@Test func onlyAPeelLaunchdStartedSharesTheSessionsZDOTDIR() {
let environment = ["ZDOTDIR": "/org.example/zsh"]