Skip to content

Commit

Permalink
Add option to use bash\zsh from users’s env #307
Browse files Browse the repository at this point in the history
  • Loading branch information
melonamin committed Apr 16, 2022
1 parent b4ef582 commit 366695d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
14 changes: 12 additions & 2 deletions SwiftBar/PreferencesStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,25 @@ enum TerminalOptions: String, CaseIterable {
}

enum ShellOptions: String, CaseIterable {
case Bash
case Zsh
case Bash = "bash"
case Zsh = "zsh"
case BashEnv = "bash(env)"
case ZshEnv = "zsh(env)"

var envPath: String {
"/usr/bin/env"
}

var path: String {
switch self {
case .Bash:
return "/bin/bash"
case .Zsh:
return "/bin/zsh"
case .BashEnv:
return "bash"
case .ZshEnv:
return "zsh"
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions SwiftBar/Utility/RunScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,15 @@ private extension Process {
executableURL = URL(fileURLWithPath: script)
arguments = args
} else {
executableURL = URL(fileURLWithPath: delegate.prefs.shell.path)
arguments = ["-c", "-l", "\(script.escaped()) \(args.joined(separator: " "))"]
let shell = delegate.prefs.shell
switch shell {
case .Bash, .Zsh:
executableURL = URL(fileURLWithPath: shell.path)
arguments = ["-c", "-l", "\(script.escaped()) \(args.joined(separator: " "))"]
case .BashEnv, .ZshEnv:
executableURL = URL(fileURLWithPath: shell.envPath)
arguments = [shell.path, "-c", "-l", "\(script.escaped()) \(args.joined(separator: " "))"]
}
}

guard let executableURL = executableURL, FileManager.default.fileExists(atPath: executableURL.path) else {
Expand Down

0 comments on commit 366695d

Please sign in to comment.