-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Frontend-GNOME: implement --execute-command argument
This new argument can be used to execute commands of either a new Smuxi instance or an already running instance. The execute command behaves exactly the same way as the input entry. This is useful for remote automation, e.g.: ssh my-box-with-running-smuxi "smuxi-frontend-gnome '/say hello from the command line'"
- Loading branch information
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* Smuxi - Smart MUltipleXed Irc | ||
* | ||
* Copyright (c) 2005-2008, 2012-2013, 2015 Mirco Bauer <[email protected]> | ||
* Copyright (c) 2005-2008, 2012-2013, 2015, 2023 Mirco Bauer <[email protected]> | ||
* | ||
* Full GPL License: <http://www.gnu.org/licenses/gpl.txt> | ||
* | ||
|
@@ -41,6 +41,7 @@ public static void Main(string[] args) | |
{ | ||
var debug = false; | ||
var link = String.Empty; | ||
var command = String.Empty; | ||
var engine = String.Empty; | ||
var newInstance = false; | ||
var options = new OptionSet(); | ||
|
@@ -76,6 +77,13 @@ public static void Main(string[] args) | |
link = v; | ||
} | ||
); | ||
options.Add( | ||
"execute|execute-command=", | ||
_("Executes the specified command in Smuxi"), | ||
v => { | ||
command = v; | ||
} | ||
); | ||
options.Add( | ||
"new-instance", | ||
_("Starts a new Smuxi instance and ignores an existing one"), | ||
|
@@ -103,6 +111,8 @@ public static void Main(string[] args) | |
Instance.FirstInstance = new CommandLineInterface(); | ||
if (!String.IsNullOrEmpty(link)) { | ||
Instance.FirstInstance.OpenLink(link); | ||
} else if (!String.IsNullOrEmpty(command)) { | ||
Instance.FirstInstance.ExecuteCommand(command); | ||
} | ||
} else { | ||
if (!String.IsNullOrEmpty(link)) { | ||
|
@@ -113,6 +123,14 @@ public static void Main(string[] args) | |
Console.WriteLine(msg); | ||
#endif | ||
Instance.FirstInstance.OpenLink(link); | ||
} else if (!String.IsNullOrEmpty(command)) { | ||
var msg = _("Passing command to already running Smuxi instance..."); | ||
#if LOG4NET | ||
_Logger.Info(msg); | ||
#else | ||
Console.WriteLine(msg); | ||
#endif | ||
Instance.FirstInstance.ExecuteCommand(command); | ||
} else if (!newInstance) { | ||
var msg = _("Bringing already running Smuxi instance to foreground..."); | ||
#if LOG4NET | ||
|
@@ -209,6 +227,22 @@ public void OpenLink(string link) | |
} | ||
} | ||
|
||
public void ExecuteCommand(string cmd) | ||
{ | ||
if (Frontend.Session == null) { | ||
#if LOG4NET | ||
Logger.Warn($"Can't execute '{cmd}' as session isn't ready, ignoring..."); | ||
#endif | ||
return; | ||
} | ||
Gtk.Application.Invoke((o, e) => { | ||
#if LOG4NET | ||
Logger.Info($"Executing '{cmd}'..."); | ||
#endif | ||
Frontend.MainWindow.Entry.ExecuteCommand(cmd); | ||
}); | ||
} | ||
|
||
public override object InitializeLifetimeService() | ||
{ | ||
// live forever | ||
|
This file contains 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