Created
December 21, 2019 05:07
-
-
Save nin-jat/8f4f6bb0c1aab30b7ea9fb873c1c2074 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This Editor extension adds a Open Terminal shortcut and menu item to the unity editor. | |
// Created by 45Ninjas. | |
// Works for unity 2019.3 running on Linux with Gnome 3.x. | |
// You should be smart enough to make it work for other versions or operating systems. | |
using System.Diagnostics; | |
using UnityEngine; | |
using UnityEditor; | |
using UnityEditor.ShortcutManagement; | |
public class OpenTerminalUtility | |
{ | |
[MenuItem("File/Open Terminal")] | |
[Shortcut("OpenTerminal", null, KeyCode.T, ShortcutModifiers.Action, displayName = "Open Terminal")] | |
public static void OpenTerminal() | |
{ | |
// Create a new process of the gnome-terminal. | |
using (Process newProcess = new Process()) | |
{ | |
// We are using the gnome-terminal executable. | |
newProcess.StartInfo.FileName = "gnome-terminal"; | |
// With the --working-directory argument to set the WD to IO's CWD. | |
newProcess.StartInfo.Arguments = $"--working-directory=\"{System.IO.Directory.GetCurrentDirectory()}\""; | |
// Plop some output into the console, good or bad is better than none. | |
if(newProcess.Start()) | |
UnityEngine.Debug.Log($"Opened gnome-terminal in {System.IO.Directory.GetCurrentDirectory()}"); | |
else | |
UnityEngine.Debug.LogWarning("Unable to start gnome-terminal"); | |
} | |
} | |
} |
Solid work :) This'll come in useful!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ctrl + T or File > Open Terminal opens a new gnome-terminal instance at the editor's current working directory.
Useful for quickly running some git or custom tools for your project.
Requires modern C# so change API Compatibility Level to
.NET Standard 2.0
or higher.Works with unity 2019.3.x on debian based linux distros with gnome-terminal installed.