Skip to content

Commit

Permalink
Use WhiskyCmd to fetch bottle shellenv
Browse files Browse the repository at this point in the history
  • Loading branch information
nastys committed Feb 25, 2024
1 parent b8c4536 commit ff94ea3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
3 changes: 2 additions & 1 deletion Whisky/Extensions/Bottle+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check failure on line 30 in Whisky/Extensions/Bottle+Extensions.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Force Unwrapping Violation: Force unwrapping should be avoided (force_unwrapping)
let cmd = "eval \\\"$(\\\"\(whiskyCmd)\\\" shellenv \\\"\(settings.name)\\\")\\\""

let script = """
tell application "Terminal"
Expand Down
29 changes: 25 additions & 4 deletions WhiskyCmd/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ struct Whisky: ParsableCommand {
// Export.self,
Delete.self,
Remove.self,
Run.self
Run.self,
Shellenv.self
/*Install.self,
Uninstall.self*/])
}
Expand Down Expand Up @@ -132,7 +133,7 @@ extension Whisky {
print(error)
}
} else {
print("No bottle called \"\(name)\" found.")
fputs("No bottle called \"\(name)\" found.\n", stderr)
}
}
}
Expand All @@ -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)
}
}
}
Expand All @@ -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
}

Expand All @@ -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.")

Expand Down
26 changes: 13 additions & 13 deletions WhiskyKit/Sources/WhiskyKit/Wine/Wine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ff94ea3

Please sign in to comment.