From ff94ea3cd7ac9b317c2179f2a2214b205aa33464 Mon Sep 17 00:00:00 2001 From: nastys Date: Sun, 25 Feb 2024 10:03:18 +0100 Subject: [PATCH] Use WhiskyCmd to fetch bottle shellenv --- Whisky/Extensions/Bottle+Extensions.swift | 3 ++- WhiskyCmd/Main.swift | 29 ++++++++++++++++++--- WhiskyKit/Sources/WhiskyKit/Wine/Wine.swift | 26 +++++++++--------- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/Whisky/Extensions/Bottle+Extensions.swift b/Whisky/Extensions/Bottle+Extensions.swift index 48783e760..a8b4fe173 100644 --- a/Whisky/Extensions/Bottle+Extensions.swift +++ b/Whisky/Extensions/Bottle+Extensions.swift @@ -27,7 +27,8 @@ extension Bottle { } func openTerminal() { - let cmd = Wine.generateTerminalEnvironmentCommand(bottle: self) + let whiskyCmd = Bundle.main.url(forResource: "WhiskyCmd", withExtension: nil)!.path(percentEncoded: false) + let cmd = "eval \\\"$(\\\"\(whiskyCmd)\\\" shellenv \\\"\(settings.name)\\\")\\\"" let script = """ tell application "Terminal" diff --git a/WhiskyCmd/Main.swift b/WhiskyCmd/Main.swift index bdab84509..d3bcc5c01 100644 --- a/WhiskyCmd/Main.swift +++ b/WhiskyCmd/Main.swift @@ -33,7 +33,8 @@ struct Whisky: ParsableCommand { // Export.self, Delete.self, Remove.self, - Run.self + Run.self, + Shellenv.self /*Install.self, Uninstall.self*/]) } @@ -132,7 +133,7 @@ extension Whisky { print(error) } } else { - print("No bottle called \"\(name)\" found.") + fputs("No bottle called \"\(name)\" found.\n", stderr) } } } @@ -152,7 +153,7 @@ extension Whisky { bottlesList.paths.removeAll(where: { $0 == bottleToRemove.url }) print("Removed \"\(name)\".") } else { - print("No bottle called \"\(name)\" found.") + fputs("No bottle called \"\(name)\" found.\n", stderr) } } } @@ -169,7 +170,7 @@ extension Whisky { let bottles = bottlesList.loadBottles() guard let bottle = bottles.first(where: { $0.settings.name == bottleName }) else { - print("A bottle with that name doesn't exist.") + fputs("A bottle with that name doesn't exist.\n", stderr) return } @@ -179,6 +180,26 @@ extension Whisky { } } + struct Shellenv: ParsableCommand { + static var configuration = CommandConfiguration(abstract: "Prints export statements for a Bottle for eval.") + + @Argument var bottleName: String + + mutating func run() throws { + var bottlesList = BottleData() + let bottles = bottlesList.loadBottles() + + guard let bottle = bottles.first(where: { $0.settings.name == bottleName }) else { + fputs("A bottle with that name doesn't exist.\n", stderr) + return + } + + let envCmd = Wine.generateTerminalEnvironmentCommand(bottle: bottle) + print(envCmd) + + } + } + struct Install: ParsableCommand { static var configuration = CommandConfiguration(abstract: "Install Whisky dependencies.") diff --git a/WhiskyKit/Sources/WhiskyKit/Wine/Wine.swift b/WhiskyKit/Sources/WhiskyKit/Wine/Wine.swift index da982133c..fa9d47ef2 100644 --- a/WhiskyKit/Sources/WhiskyKit/Wine/Wine.swift +++ b/WhiskyKit/Sources/WhiskyKit/Wine/Wine.swift @@ -123,23 +123,23 @@ public class Wine { public static func generateTerminalEnvironmentCommand(bottle: Bottle) -> String { var cmd = """ -export PATH=\\\"\(GPTKInstaller.binFolder.path):$PATH\\\" -export WINE=\\\"wine64\\\" -alias wine=\\\"wine64\\\" -alias winecfg=\\\"wine64 winecfg\\\" -alias msiexec=\\\"wine64 msiexec\\\" -alias regedit=\\\"wine64 regedit\\\" -alias regsvr32=\\\"wine64 regsvr32\\\" -alias wineboot=\\\"wine64 wineboot\\\" -alias wineconsole=\\\"wine64 wineconsole\\\" -alias winedbg=\\\"wine64 winedbg\\\" -alias winefile=\\\"wine64 winefile\\\" -alias winepath=\\\"wine64 winepath\\\" +export PATH=\"\(GPTKInstaller.binFolder.path):$PATH\" +export WINE=\"wine64\" +alias wine=\"wine64\" +alias winecfg=\"wine64 winecfg\" +alias msiexec=\"wine64 msiexec\" +alias regedit=\"wine64 regedit\" +alias regsvr32=\"wine64 regsvr32\" +alias wineboot=\"wine64 wineboot\" +alias wineconsole=\"wine64 wineconsole\" +alias winedbg=\"wine64 winedbg\" +alias winefile=\"wine64 winefile\" +alias winepath=\"wine64 winepath\" """ let env = constructWineEnvironment(for: bottle, environment: constructWineEnvironment(for: bottle)) for environment in env { - cmd += "\nexport \(environment.key)=\\\"\(environment.value)\\\"" + cmd += "\nexport \(environment.key)=\"\(environment.value)\"" } return cmd