Browse Source

Launch bash as a login shell; Set startup directory to be the home directory

Miguel de Icaza 4 years ago
parent
commit
12ce12a779

+ 7 - 2
Sources/SwiftTerm/LocalProcess.swift

@@ -166,8 +166,9 @@ public class LocalProcess {
      * - Parameter executable: The executable to launch inside the pseudo terminal, defaults to /bin/bash
      * - Parameter args: an array of strings that is passed as the arguments to the underlying process
      * - Parameter environment: an array of environment variables to pass to the child process, if this is null, this picks a good set of defaults from `Terminal.getEnvironmentVariables`.
+     * - Parameter execName: If provided, this is used as the Unix argv[0] parameter, otherwise, the executable is used as the args [0], this is used when the intent is to set a different process name than the file that backs it.
      */
-    public func startProcess(executable: String = "/bin/bash", args: [String] = [], environment: [String]? = nil)
+    public func startProcess(executable: String = "/bin/bash", args: [String] = [], environment: [String]? = nil, execName: String? = nil)
      {
         if running {
             return
@@ -175,7 +176,11 @@ public class LocalProcess {
         var size = delegate.getWindowSize ()
     
         var shellArgs = args
-        shellArgs.insert(executable, at: 0)
+        if let firstArgName = execName {
+            shellArgs.insert (firstArgName, at: 0)
+        } else {
+            shellArgs.insert(executable, at: 0)
+        }
         
         var env: [String]
         if environment == nil {

+ 3 - 2
Sources/SwiftTerm/Mac/MacLocalTerminalView.swift

@@ -134,10 +134,11 @@ public class LocalProcessTerminalView: TerminalView, TerminalViewDelegate, Local
      * - Parameter executable: The executable to launch inside the pseudo terminal, defaults to /bin/bash
      * - Parameter args: an array of strings that is passed as the arguments to the underlying process
      * - Parameter environment: an array of environment variables to pass to the child process, if this is null, this picks a good set of defaults from `Terminal.getEnvironmentVariables`.
+     * - Parameter execName: If provided, this is used as the Unix argv[0] parameter, otherwise, the executable is used as the args [0], this is used when the intent is to set a different process name than the file that backs it.
      */
-    public func startProcess(executable: String = "/bin/bash", args: [String] = [], environment: [String]? = nil)
+    public func startProcess(executable: String = "/bin/bash", args: [String] = [], environment: [String]? = nil, execName: String? = nil)
     {
-        process.startProcess(executable: executable, args: args, environment: environment)
+        process.startProcess(executable: executable, args: args, environment: environment, execName: execName)
     }
     
     /**

+ 2 - 2
TerminalApp/MacTerminal/ViewController.swift

@@ -95,9 +95,9 @@ class ViewController: NSViewController, LocalProcessTerminalViewDelegate, NSUser
         ViewController.lastTerminal = terminal
         terminal.processDelegate = self
         terminal.feed(text: "Welcome to SwiftTerm")
-        terminal.startProcess ()
+        FileManager.default.changeCurrentDirectoryPath (FileManager.default.homeDirectoryForCurrentUser.path)
+        terminal.startProcess (executable: "/bin/bash", execName: "-bash")
         view.addSubview(terminal)
-        
         logging = NSUserDefaultsController.shared.defaults.bool(forKey: "LogHostOutput")
         updateLogging ()
     }