1
/* RunInTerminalAction.cs
3
* GNOME Do is the legal property of its developers, whose names are too numerous
4
* to list here. Please refer to the COPYRIGHT file distributed with this
7
* This program is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
using System.Diagnostics;
27
namespace GNOME.Terminal
29
public class RunInTerminalAction : AbstractAction
31
static string last_command_found;
33
public RunInTerminalAction()
37
public override string Name
39
get { return "Run in Terminal"; }
42
public override string Description
44
get { return "Runs a command in GNOME Terminal."; }
47
public override string Icon
49
get { return "gnome-terminal"; }
52
public override Type[] SupportedItemTypes
62
public override bool SupportsItem (IItem item)
64
if (item is ITextItem) {
65
return CommandLineFoundOnPath ((item as ITextItem).Text);
66
} else if (item is IFileItem) {
67
return FileItem.IsExecutable (item as IFileItem);
72
public override IItem[] Perform (IItem[] items, IItem[] modifierItems)
74
foreach (IItem item in items) {
76
if (item is ITextItem) {
77
cmd = (item as ITextItem).Text;
78
} else if (item is IFileItem) {
79
cmd = (item as IFileItem).Path;
83
Process.Start ("gnome-terminal", "-x " + cmd );
84
} catch (Exception e) {
85
Console.Error.WriteLine ("Could not open gnome-terminal with command {0}: {1}",
92
public static bool CommandLineFoundOnPath (string command_line)
94
string path, command, command_file;
97
if (command_line == null) return false;
99
command = command_line.Trim ();
100
space_position = command.IndexOf (" ");
101
if (space_position > 0) {
102
command = command.Substring (0, space_position);
105
// If this command is the same as the last, yes.
106
if (command == last_command_found) return true;
108
// If the command is found, fine.
109
if (System.IO.File.Exists (command)) {
110
last_command_found = command;
114
// Otherwise, try to find the command file in path.
115
path = System.Environment.GetEnvironmentVariable ("PATH");
117
foreach (string part in path.Split (':')) {
118
command_file = System.IO.Path.Combine (part, command);
119
if (System.IO.File.Exists (command_file)) {
120
last_command_found = command;