summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2012-08-05 14:29:00 +0200
committerhut <hut@lavabit.com>2012-08-05 14:29:00 +0200
commita1be5fc881e1378d5133fa6244e9f72a3dfc5508 (patch)
tree762757b5ecbdcfcd2a7c8a07023d40443acd0c06
parentb0314dd1e836763d864021d7adfb128196186c6a (diff)
downloadranger-a1be5fc881e1378d5133fa6244e9f72a3dfc5508.tar.gz
core.actions: More reliable mimetype checking @ execute_file
This is a result of https://github.com/hut/ranger/issues/43 :

adam8157:
  Hmm... I found this behavior is different between running in Debian Sid
  and Fedora 17.

  Their python version are both 2.7.3, but when you touch a file named
  foo.sh, and press "r", ranger in Fedora 17 displays bash as the first
  opener, then editor and pager, but ranger in Debian Sid displays editor
  first, then pager and bash.

[...]

hut:
  Ok, with your help I found it. Actions.execute_file and
  Actions.draw_possible_programs optimize the process by skipping the call
  to file --mimetype -Lb and using the mime type that the python mimetypes
  library found. The two methods return different mimetypes sometimes.
  Since file is more reliable than the python mimetypes library, I'll
  change it to use file always.
-rw-r--r--ranger/core/actions.py5
1 files changed, 2 insertions, 3 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index 73e8bb67..0d76f2e8 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -292,10 +292,9 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 
 		self.signal_emit('execute.before', keywords=kw)
 		filenames = [f.path for f in files]
-		mimetype = files[0].mimetype if files else None
 		label = kw.get('label', kw.get('app', None))
 		try:
-			return self.rifle.execute(filenames, mode, label, flags, mimetype)
+			return self.rifle.execute(filenames, mode, label, flags, None)
 		finally:
 			self.signal_emit('execute.after')
 
@@ -684,7 +683,7 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 		except:
 			self.ui.browser.draw_info = []
 			return
-		programs = self.rifle.list_commands([target.path], target.mimetype)
+		programs = self.rifle.list_commands([target.path], None)
 		programs = ['%s | %s' % program[0:2] for program in programs]
 		self.ui.browser.draw_info = programs
 
ecorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/*
 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
 * See LICENSE file for license details.
 */

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

#include "dwm.h"

void
error(const char *errstr, ...) {
	va_list ap;
	va_start(ap, errstr);
	vfprintf(stderr, errstr, ap);
	va_end(ap);
	exit(1);
}

static void
bad_malloc(unsigned int size)
{
	fprintf(stderr, "fatal: could not malloc() %d bytes\n",
			(int) size);
	exit(1);
}

void *
emallocz(unsigned int size)
{
	void *res = calloc(1, size);
	if(!res)
		bad_malloc(size);
	return res;
}

void *
emalloc(unsigned int size)
{
	void *res = malloc(size);
	if(!res)
		bad_malloc(size);
	return res;
}

void *
erealloc(void *ptr, unsigned int size)
{
	void *res = realloc(ptr, size);
	if(!res)
		bad_malloc(size);
	return res;
}

char *
estrdup(const char *str)
{
	char *res = strdup(str);
	if(!res)
		bad_malloc(strlen(str));
	return res;
}

void
swap(void **p1, void **p2)
{
	void *tmp = *p1;
	*p1 = *p2;
	*p2 = tmp;
}

void
spawn(Arg *arg)
{
	char **argv = (char **)arg->argv;
	if(!argv || !argv[0])
		return;
	if(fork() == 0) {
		if(fork() == 0) {
			if(dpy)
				close(ConnectionNumber(dpy));
			setsid();
			execvp(argv[0], argv);
			fprintf(stderr, "dwm: execvp %s", argv[0]);
			perror(" failed");
		}
		exit (0);
	}
	wait(0);
}