about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-05-16 23:41:12 +0200
committerMichael Vetter <jubalh@iodoru.org>2020-05-20 10:47:46 +0200
commit03334664fb44ff268f6808a945d5d74d3ed34a70 (patch)
tree97d6d058e9ccc63fead1dcf8e5fc7f2305bb26a0 /src/command
parent083bf34a7763aec7c95282e1b357ee4cf71c49fd (diff)
downloadprofani-tty-03334664fb44ff268f6808a945d5d74d3ed34a70.tar.gz
Actually open the URL
Diffstat (limited to 'src/command')
-rw-r--r--src/command/cmd_defs.c18
-rw-r--r--src/command/cmd_funcs.c20
-rw-r--r--src/command/cmd_funcs.h2
3 files changed, 39 insertions, 1 deletions
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index db55eaf4..398badc0 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -2449,7 +2449,23 @@ static struct cmd_t command_defs[] =
         CMD_EXAMPLES(
             "/software valhalla.edda",
             "/software xmpp.vanaheimr.edda")
-    }
+    },
+
+    { "/urlopen",
+        parse_args, 1, -1, NULL,
+        CMD_NOSUBFUNCS
+        CMD_MAINFUNC(cmd_urlopen)
+        CMD_TAGS(
+            CMD_TAG_CHAT,
+            CMD_TAG_GROUPCHAT)
+        CMD_SYN(
+            "/urlopen <url>")
+        CMD_DESC(
+            "Open the URL")
+        CMD_ARGS(
+            { "<url>",    "URL to open."})
+        CMD_NOEXAMPLES
+    },
 };
 
 static GHashTable *search_index;
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 96f6c372..109043bc 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -8858,3 +8858,23 @@ cmd_slashguard(ProfWin *window, const char *const command, gchar **args)
 
     return TRUE;
 }
+
+gboolean
+cmd_urlopen(ProfWin *window, const char *const command, gchar **args)
+{
+    if (args[0] == NULL) {
+        cons_bad_cmd_usage(command);
+        return TRUE;
+    }
+
+    //TODO: make function. see src/xmpp/avatar.c
+    GString *cmd = g_string_new("");
+
+    g_string_append_printf(cmd, "%s %s > /dev/null 2>&1", "xdg-open", args[0]);
+    cons_show("Calling: %s", cmd->str);
+    FILE *stream = popen(cmd->str, "r");
+
+    pclose(stream);
+    g_string_free(cmd, TRUE);
+    return TRUE;
+}
diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h
index 6f82a88a..a8739974 100644
--- a/src/command/cmd_funcs.h
+++ b/src/command/cmd_funcs.h
@@ -232,4 +232,6 @@ gboolean cmd_correction(ProfWin *window, const char *const command, gchar **args
 gboolean cmd_correct(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_slashguard(ProfWin *window, const char *const command, gchar **args);
 gboolean cmd_serversoftware(ProfWin *window, const char *const command, gchar **args);
+gboolean cmd_urlopen(ProfWin *window, const char *const command, gchar **args);
+
 #endif