Commit Diff


commit - 8e1fb8d5023e6f5a977b55d5f8cacd7cdec9773f
commit + 7b7a69f2aeeffb5436fd490f2020335b5bf9a121
blob - e09140d922a771d979ee481e4eb31352c4c44407
blob + c69b5a51e53b5caab522d14dd23fec51f52e4d29
--- downloads.c
+++ downloads.c
@@ -81,7 +81,7 @@ end:
 }
 
 struct download *
-enqueue_download(uint32_t id, const char *path)
+enqueue_download(uint32_t id, const char *path, const char *mime_type)
 {
 	struct download *d;
 
@@ -91,6 +91,7 @@ enqueue_download(uint32_t id, const char *path)
 	d->id = id;
 	d->fd = -1;
 	d->path = strdup(path);
+	d->mime_type = strdup(mime_type);
 
 	STAILQ_INSERT_HEAD(&downloads, d, entries);
 
@@ -120,5 +121,5 @@ download_finished(struct download *d)
 	d->fd = -1;
 
 	ui_on_download_refresh();
-	ui_prompt_download_cmd(d->path);
+	ui_prompt_download_cmd(d->path, d->mime_type);
 }
blob - 442aa2d0d5c895e456d12ecac6ccd87f696f4544
blob + 51e987db50d309bea75d1b0b472d9626b44d51ed
--- mailcap.h
+++ mailcap.h
@@ -17,8 +17,6 @@
 #ifndef MAILCAP_H
 #define MAILCAP_H
 
-#define DEFAULT_MIMETYPE "*/*"
-
 struct mailcap {
 	char 			*mime_type;
 	char 			*cmd;
blob - e734c67c3e15caea5107257a1767c691d635744d
blob + bfcedcfedceee6174d1bdf752dac1317d66516e9
--- telescope.c
+++ telescope.c
@@ -41,6 +41,7 @@
 #include "imsgev.h"
 #include "iri.h"
 #include "keymap.h"
+#include "mailcap.h"
 #include "mcache.h"
 #include "minibuffer.h"
 #include "parser.h"
@@ -426,7 +427,7 @@ handle_save_page_path(const char *path, struct tab *ta
 	}
 
 	ui_show_downloads_pane();
-	d = enqueue_download(tab->id, path);
+	d = enqueue_download(tab->id, path, tab->meta);
 	d->fd = fd;
 	ui_send_net(IMSG_PROCEED, d->id, -1, NULL, 0);
 
@@ -1128,6 +1129,8 @@ main(int argc, char * const *argv)
 	global_map.unhandled_input = global_key_unbound;
 	TAILQ_INIT(&minibuffer_map.m);
 
+	init_mailcap();
+
 	if (fs_init() == -1)
 		err(1, "fs_init failed");
 	if (certs_init(certs_file) == -1)
blob - 92616f9dee3cedae427c719c0139cf370e7c09f0
blob + 90515f65cd29ee80b8dfcf1cfc0f0989627a913b
--- telescope.h
+++ telescope.h
@@ -215,12 +215,13 @@ struct download {
 	uint32_t		 id;
 	int			 fd;
 	size_t			 bytes;
+	char 			*mime_type;
 	char			*path;
 	STAILQ_ENTRY(download)	 entries;
 };
 
 void		 recompute_downloads(void);
-struct download	*enqueue_download(uint32_t, const char *);
+struct download	*enqueue_download(uint32_t, const char *, const char *);
 struct download	*download_by_id(uint32_t);
 void 	 	 download_finished(struct download *);
 
blob - 5ba371c90bbcb942f30d8400444939be9917d8c2
blob + 96ee617abc23624ea778b3e78e9935c9e7375fe8
--- ui.c
+++ ui.c
@@ -50,6 +50,7 @@
 #include "ev.h"
 #include "hist.h"
 #include "keymap.h"
+#include "mailcap.h"
 #include "minibuffer.h"
 #include "session.h"
 #include "telescope.h"
@@ -82,7 +83,7 @@ static void		 place_cursor(int);
 static void		 redraw_tab(struct tab*);
 static void		 update_loading_anim(int, int, void*);
 static void		 stop_loading_anim(struct tab*);
-static void 		 exec_external_cmd(const char *, struct tab *);
+static void 		 exec_external_cmd(char **);
 
 static int		 should_rearrange_windows;
 static int		 show_tab_bar;
@@ -1239,13 +1240,15 @@ ui_on_download_refresh(void)
 }
 
 void
-ui_prompt_download_cmd(char *path)
+ui_prompt_download_cmd(char *path, char *mime_type)
 {
-	char cmd[8192];
-
-	snprintf(cmd, sizeof(cmd), "%s %s", external_cmd, path);
+	struct mailcap 	*mc = NULL;
 
-	ui_read("Execute", exec_external_cmd, current_tab, cmd);
+	if ((mc = mailcap_cmd_from_mimetype(mime_type, path)) == NULL)
+		return;
+
+	message("Loaded %s with %s", mime_type, mc->cmd_argv[0]);
+	exec_external_cmd(mc->cmd_argv);
 }
 
 void
@@ -1377,12 +1380,12 @@ ui_end(void)
 }
 
 static void
-exec_external_cmd(const char *cmd, struct tab *tab)
+exec_external_cmd(char **argv)
 {
-	int s;
-	pid_t p;
+	int 	 s;
+	pid_t 	 p;
 
-	if (cmd == NULL)
+	if (argv == NULL)
 		return;
 
 	endwin();
@@ -1392,8 +1395,8 @@ exec_external_cmd(const char *cmd, struct tab *tab)
 		message("failed to fork: %s", strerror(errno));
 		return;
 	case 0:
-		execl("/bin/sh", "sh", "-c", cmd, NULL);
-		warn("exec \"%s\" failed", cmd);
+		execvp(argv[0], argv);
+		warn("execve failed");
 		_exit(1);
 	}
 
blob - fbcce36ac69ef321f6dbbeed10e560f77d5cb8c4
blob + c1ebfb3481771a7f9df065735f436b0f0591f1d4
--- ui.h
+++ ui.h
@@ -145,7 +145,7 @@ void		 ui_main_loop(void);
 void		 ui_on_tab_loaded(struct tab *);
 void		 ui_on_tab_refresh(struct tab *);
 void		 ui_on_download_refresh(void);
-void 		 ui_prompt_download_cmd(char *);
+void 		 ui_prompt_download_cmd(char *, char *);
 void		 ui_remotely_open_link(const char *);
 const char	*ui_keyname(int);
 void		 ui_toggle_side_window(int);