Skip to content

Commit

Permalink
Refactor shell preferences #307
Browse files Browse the repository at this point in the history
  • Loading branch information
melonamin committed Sep 19, 2022
1 parent b39d5dc commit 528de43
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
8 changes: 8 additions & 0 deletions SwiftBar/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, SPUStandardUserDriverDelegat
}
#endif

setDefaultShelf()
// Check if plugin folder exists
var isDir: ObjCBool = false
if let pluginDirectoryPath = prefs.pluginDirectoryResolvedPath,
Expand Down Expand Up @@ -100,6 +101,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, SPUStandardUserDriverDelegat
}
}

func setDefaultShelf() {
let out = try? runScript(to: "dscl", args: [".", "-read", "~/", "UserShell", "|", "awk", "'{print $2}'"])
if let shell = out?.out, shell != "" {
sharedEnv.userLoginShell = shell
}
}

func changePresentationType() {
if preferencesWindowController.window?.isVisible != true && repositoryWindowController?.window?.isVisible != true {
NSApp.setActivationPolicy(.accessory)
Expand Down
15 changes: 4 additions & 11 deletions SwiftBar/PreferencesStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,16 @@ enum TerminalOptions: String, CaseIterable {
enum ShellOptions: String, CaseIterable {
case Bash = "bash"
case Zsh = "zsh"
case BashEnv = "bash(env)"
case ZshEnv = "zsh(env)"

var envPath: String {
"/usr/bin/env"
}
case Default = "default"

var path: String {
switch self {
case .Bash:
return "/bin/bash"
case .Zsh:
return "/bin/zsh"
case .BashEnv:
return "bash"
case .ZshEnv:
return "zsh"
case .Default:
return Environment.shared.userLoginShell
}
}
}
Expand Down Expand Up @@ -132,7 +125,7 @@ class PreferencesStore: ObservableObject {
var stealthMode: Bool {
PreferencesStore.getValue(key: .StealthMode) as? Bool ?? false
}

var collectCrashReports: Bool {
PreferencesStore.getValue(key: .CollectCrashReports) as? Bool ?? false
}
Expand Down
2 changes: 2 additions & 0 deletions SwiftBar/Utility/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Environment {
return formatter
}()

var userLoginShell = "/bin/zsh"

private var systemEnv: [Variables: String] = [
.swiftBar: "1",
.swiftBarVersion: Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "",
Expand Down
10 changes: 2 additions & 8 deletions SwiftBar/Utility/RunScript.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,8 @@ private extension Process {
arguments = args
} else {
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: " "))"]
}
executableURL = URL(fileURLWithPath: shell.path)
arguments = ["-c", "-l", "\(script.escaped()) \(args.joined(separator: " "))"]
}

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

0 comments on commit 528de43

Please sign in to comment.