Speficy -r or --run to run a file as javascript
This commit is contained in:
parent
a12f3d10e0
commit
6cd7e61c61
2 changed files with 25 additions and 11 deletions
|
@ -111,9 +111,9 @@ Running Midori normally works as follows:
|
||||||
You can separate URIS by a pipe (|) as well. They are handled as if you
|
You can separate URIS by a pipe (|) as well. They are handled as if you
|
||||||
provided all URIs as separate arguments.
|
provided all URIs as separate arguments.
|
||||||
|
|
||||||
* $ midori [JAVASCRIPT]
|
* $ midori --run [JAVASCRIPT]
|
||||||
|
|
||||||
If you pass a filename ending with ".js" Midori will attempt to run
|
If you pass the filename of a javascript Midori will attempt to run
|
||||||
the contents of the file as javascript code.
|
the contents of the file as javascript code.
|
||||||
|
|
||||||
|
|
||||||
|
@ -127,6 +127,8 @@ The following arguments are supported if you call Midori from a command line.
|
||||||
+-------+--------------------+------------------------------------------------+
|
+-------+--------------------+------------------------------------------------+
|
||||||
| Short | Long option | Function |
|
| Short | Long option | Function |
|
||||||
+=======+====================+================================================+
|
+=======+====================+================================================+
|
||||||
|
| -r | --run | Run the specified filename as javascript |
|
||||||
|
+-------+--------------------+------------------------------------------------+
|
||||||
| -v | --version | Show version information and exit. |
|
| -v | --version | Show version information and exit. |
|
||||||
+-------+--------------------+------------------------------------------------+
|
+-------+--------------------+------------------------------------------------+
|
||||||
|
|
||||||
|
|
|
@ -1049,6 +1049,7 @@ int
|
||||||
main (int argc,
|
main (int argc,
|
||||||
char** argv)
|
char** argv)
|
||||||
{
|
{
|
||||||
|
gboolean run;
|
||||||
gboolean version;
|
gboolean version;
|
||||||
gchar** uris;
|
gchar** uris;
|
||||||
MidoriApp* app;
|
MidoriApp* app;
|
||||||
|
@ -1056,6 +1057,8 @@ main (int argc,
|
||||||
GError* error;
|
GError* error;
|
||||||
GOptionEntry entries[] =
|
GOptionEntry entries[] =
|
||||||
{
|
{
|
||||||
|
{ "run", 'r', 0, G_OPTION_ARG_NONE, &run,
|
||||||
|
N_("Run the specified filename as javascript"), NULL },
|
||||||
{ "version", 'v', 0, G_OPTION_ARG_NONE, &version,
|
{ "version", 'v', 0, G_OPTION_ARG_NONE, &version,
|
||||||
N_("Display program version"), NULL },
|
N_("Display program version"), NULL },
|
||||||
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &uris,
|
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &uris,
|
||||||
|
@ -1089,6 +1092,7 @@ main (int argc,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Parse cli options */
|
/* Parse cli options */
|
||||||
|
run = FALSE;
|
||||||
version = FALSE;
|
version = FALSE;
|
||||||
uris = NULL;
|
uris = NULL;
|
||||||
error = NULL;
|
error = NULL;
|
||||||
|
@ -1121,16 +1125,24 @@ main (int argc,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Standalone gjs support */
|
/* Standalone gjs support */
|
||||||
if (uris && uris[0] && g_str_has_suffix (uris[0], ".js"))
|
if (run)
|
||||||
{
|
{
|
||||||
js_context = gjs_global_context_new ();
|
if (uris && *uris)
|
||||||
exception = NULL;
|
{
|
||||||
gjs_script_from_file (js_context, uris[0], &exception);
|
js_context = gjs_global_context_new ();
|
||||||
JSGlobalContextRelease (js_context);
|
exception = NULL;
|
||||||
if (!exception)
|
gjs_script_from_file (js_context, *uris, &exception);
|
||||||
return 0;
|
JSGlobalContextRelease (js_context);
|
||||||
printf ("%s - Exception: %s\n", uris[0], exception);
|
if (!exception)
|
||||||
return 1;
|
return 0;
|
||||||
|
g_print ("%s - Exception: %s\n", *uris, exception);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_print ("%s - %s\n", _("Midori"), _("No filename specified"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app = midori_app_new ();
|
app = midori_app_new ();
|
||||||
|
|
Loading…
Reference in a new issue