Skip to content

Instantly share code, notes, and snippets.

@nin-jat
Created December 21, 2019 05:07
Show Gist options
  • Save nin-jat/8f4f6bb0c1aab30b7ea9fb873c1c2074 to your computer and use it in GitHub Desktop.
Save nin-jat/8f4f6bb0c1aab30b7ea9fb873c1c2074 to your computer and use it in GitHub Desktop.
// 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");
}
}
}
@nin-jat
Copy link
Author

nin-jat commented Dec 21, 2019

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.

Screenshot from 2019-12-21 12-27-14
image

@DraconInteractive
Copy link

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