xaizek / vifm (License: GPLv2+) (since 2018-12-07)
Vifm is a file manager with curses interface, which provides Vi[m]-like environment for managing objects within file systems, extended with some useful ideas from mutt.
Commit de020c3bfc09ec1dd3fc34dd5e70904eb3a41b72

Added detection of file handlers with GTK+ or libmagic and .desktop files (it works only for :file command).
Author: xaizek
Author date (UTC): 2011-05-26 16:44
Committer name: xaizek
Committer date (UTC): 2011-05-26 16:45
Parent(s): 55846ace3c50c7b81634db44ff9c42ca0cc7e67a
Signing key:
Tree: 12eaaedee007df25d5e8f1904ab3aef35524ca34
File Lines added Lines deleted
ChangeLog 4 1
config.h.in 6 0
configure 56 0
configure.in 12 0
src/Makefile.am 1 0
src/Makefile.in 9 7
src/commands.c 4 1
src/file_info.c 28 28
src/file_magic.c 249 0
src/file_magic.h 12 0
src/fileops.c 1 1
src/menus.c 36 18
src/menus.h 2 1
src/status.h 6 0
src/ui.c 1 1
src/vifm-help.txt 3 0
src/vifm.1 3 0
src/vifm.c 11 0
src/vifm.txt 3 1
src/vifmrc 3 3
File ChangeLog changed (mode: 100644) (index e1e463902..44e20bc98)
65 65
66 66 Added cW command (change only name of file and leave old extension). Added cW command (change only name of file and leave old extension).
67 67
68 Added pushd and popd commands.
68 Added :pushd and :popd commands.
69
70 Added detection of file handlers with GTK+ or libmagic and .desktop files
71 (it works only for :file command).
69 72
70 73 Changed keys input handling. Changed keys input handling.
71 74
File config.h.in changed (mode: 100644) (index f64504114..47de5daca)
27 27 /* Define to 1 if you have the <inttypes.h> header file. */ /* Define to 1 if you have the <inttypes.h> header file. */
28 28 #undef HAVE_INTTYPES_H #undef HAVE_INTTYPES_H
29 29
30 /* use gtk to determine mime type */
31 #undef HAVE_LIBGTK
32
33 /* Define to 1 if you have the `magic' library (-lmagic). */
34 #undef HAVE_LIBMAGIC
35
30 36 /* Define to 1 if you have the <limits.h> header file. */ /* Define to 1 if you have the <limits.h> header file. */
31 37 #undef HAVE_LIMITS_H #undef HAVE_LIMITS_H
32 38
File configure changed (mode: 100755) (index f8102bcf8..609466e34)
... ... fi
13107 13107
13108 13108 LIBS=$LIBS $GUI_LINK_OPTS_TERM LIBS=$LIBS $GUI_LINK_OPTS_TERM
13109 13109
13110
13111 if pkg-config --exists glib-2.0 gtk+-2.0; then
13112 CFLAGS="$CFLAGS $(pkg-config --cflags glib-2.0 gtk+-2.0)"
13113 LIBS="$LIBS $(pkg-config --libs glib-2.0 gtk+-2.0)"
13114
13115 $as_echo "#define HAVE_LIBGTK 1" >>confdefs.h
13116
13117 fi
13118
13119 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for magic_open in -lmagic" >&5
13120 $as_echo_n "checking for magic_open in -lmagic... " >&6; }
13121 if ${ac_cv_lib_magic_magic_open+:} false; then :
13122 $as_echo_n "(cached) " >&6
13123 else
13124 ac_check_lib_save_LIBS=$LIBS
13125 LIBS="-lmagic $LIBS"
13126 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
13127 /* end confdefs.h. */
13128
13129 /* Override any GCC internal prototype to avoid an error.
13130 Use char because int might match the return type of a GCC
13131 builtin and then its argument prototype would still apply. */
13132 #ifdef __cplusplus
13133 extern "C"
13134 #endif
13135 char magic_open ();
13136 int
13137 main ()
13138 {
13139 return magic_open ();
13140 ;
13141 return 0;
13142 }
13143 _ACEOF
13144 if ac_fn_c_try_link "$LINENO"; then :
13145 ac_cv_lib_magic_magic_open=yes
13146 else
13147 ac_cv_lib_magic_magic_open=no
13148 fi
13149 rm -f core conftest.err conftest.$ac_objext \
13150 conftest$ac_exeext conftest.$ac_ext
13151 LIBS=$ac_check_lib_save_LIBS
13152 fi
13153 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_magic_magic_open" >&5
13154 $as_echo "$ac_cv_lib_magic_magic_open" >&6; }
13155 if test "x$ac_cv_lib_magic_magic_open" = xyes; then :
13156 cat >>confdefs.h <<_ACEOF
13157 #define HAVE_LIBMAGIC 1
13158 _ACEOF
13159
13160 LIBS="-lmagic $LIBS"
13161
13162 fi
13163
13164
13165
13110 13166 # Check whether --enable-extended_keys was given. # Check whether --enable-extended_keys was given.
13111 13167 if test "${enable_extended_keys+set}" = set; then : if test "${enable_extended_keys+set}" = set; then :
13112 13168 enableval=$enable_extended_keys; extended_keys=$enableval enableval=$enable_extended_keys; extended_keys=$enableval
File configure.in changed (mode: 100644 -> 100755) (index 631f4d106..302765aa3)
... ... AC_CHECK_LIB(ncursesw, initscr,
71 71 ]) ])
72 72 LIBS=$LIBS $GUI_LINK_OPTS_TERM LIBS=$LIBS $GUI_LINK_OPTS_TERM
73 73
74 dnl checks for mime type detection
75
76 if pkg-config --exists glib-2.0 gtk+-2.0; then
77 CFLAGS="$CFLAGS $(pkg-config --cflags glib-2.0 gtk+-2.0)"
78 LIBS="$LIBS $(pkg-config --libs glib-2.0 gtk+-2.0)"
79 AC_DEFINE([HAVE_LIBGTK], [1], [use gtk to determine mime type])
80 fi
81
82 AC_CHECK_LIB(magic, magic_open)
83
84 dnl handle options
85
74 86 AC_ARG_ENABLE(extended_keys, AC_ARG_ENABLE(extended_keys,
75 87 AS_HELP_STRING( AS_HELP_STRING(
76 88 [--enable-extended-keys], [--enable-extended-keys],
File src/Makefile.am changed (mode: 100644) (index 6e7415720..b9cf11bfe)
... ... vifm_SOURCES = \
21 21 config.c config.h \ config.c config.h \
22 22 dir_stack.c dir_stack.h \ dir_stack.c dir_stack.h \
23 23 file_info.c file_info.h \ file_info.c file_info.h \
24 file_magic.c file_magic.h \
24 25 filelist.c filelist.h \ filelist.c filelist.h \
25 26 fileops.c fileops.h \ fileops.c fileops.h \
26 27 filetype.c filetype.h \ filetype.c filetype.h \
File src/Makefile.in changed (mode: 100644) (index 5cc8e7f19..9bb79254b)
... ... PROGRAMS = $(bin_PROGRAMS)
53 53 am_vifm_OBJECTS = background.$(OBJEXT) bookmarks.$(OBJEXT) \ am_vifm_OBJECTS = background.$(OBJEXT) bookmarks.$(OBJEXT) \
54 54 cmdline.$(OBJEXT) color_scheme.$(OBJEXT) commands.$(OBJEXT) \ cmdline.$(OBJEXT) color_scheme.$(OBJEXT) commands.$(OBJEXT) \
55 55 config.$(OBJEXT) dir_stack.$(OBJEXT) file_info.$(OBJEXT) \ config.$(OBJEXT) dir_stack.$(OBJEXT) file_info.$(OBJEXT) \
56 filelist.$(OBJEXT) fileops.$(OBJEXT) filetype.$(OBJEXT) \
57 keys.$(OBJEXT) main_loop.$(OBJEXT) menu.$(OBJEXT) \
58 menus.$(OBJEXT) modes.$(OBJEXT) normal.$(OBJEXT) \
59 permissions_dialog.$(OBJEXT) registers.$(OBJEXT) \
60 search.$(OBJEXT) signals.$(OBJEXT) sort.$(OBJEXT) \
61 sort_dialog.$(OBJEXT) status.$(OBJEXT) ui.$(OBJEXT) \
62 utils.$(OBJEXT) vifm.$(OBJEXT) visual.$(OBJEXT)
56 file_magic.$(OBJEXT) filelist.$(OBJEXT) fileops.$(OBJEXT) \
57 filetype.$(OBJEXT) keys.$(OBJEXT) main_loop.$(OBJEXT) \
58 menu.$(OBJEXT) menus.$(OBJEXT) modes.$(OBJEXT) \
59 normal.$(OBJEXT) permissions_dialog.$(OBJEXT) \
60 registers.$(OBJEXT) search.$(OBJEXT) signals.$(OBJEXT) \
61 sort.$(OBJEXT) sort_dialog.$(OBJEXT) status.$(OBJEXT) \
62 ui.$(OBJEXT) utils.$(OBJEXT) vifm.$(OBJEXT) visual.$(OBJEXT)
63 63 vifm_OBJECTS = $(am_vifm_OBJECTS) vifm_OBJECTS = $(am_vifm_OBJECTS)
64 64 vifm_LDADD = $(LDADD) vifm_LDADD = $(LDADD)
65 65 am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
 
... ... vifm_SOURCES = \
236 236 config.c config.h \ config.c config.h \
237 237 dir_stack.c dir_stack.h \ dir_stack.c dir_stack.h \
238 238 file_info.c file_info.h \ file_info.c file_info.h \
239 file_magic.c file_magic.h \
239 240 filelist.c filelist.h \ filelist.c filelist.h \
240 241 fileops.c fileops.h \ fileops.c fileops.h \
241 242 filetype.c filetype.h \ filetype.c filetype.h \
 
... ... distclean-compile:
386 387 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/config.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/config.Po@am__quote@
387 388 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dir_stack.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dir_stack.Po@am__quote@
388 389 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/file_info.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/file_info.Po@am__quote@
390 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/file_magic.Po@am__quote@
389 391 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/filelist.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/filelist.Po@am__quote@
390 392 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fileops.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fileops.Po@am__quote@
391 393 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/filetype.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/filetype.Po@am__quote@
File src/commands.c changed (mode: 100644) (index ee173bb58..fa7b88cf8)
... ... execute_builtin_command(FileView *view, cmd_t *cmd)
1392 1392 } }
1393 1393 break; break;
1394 1394 case COM_FILE: case COM_FILE:
1395 show_filetypes_menu(view);
1395 {
1396 int has_argument = (cmd->args != NULL && *cmd->args != '\0');
1397 show_filetypes_menu(view, has_argument, cmd->background);
1398 }
1396 1399 break; break;
1397 1400 case COM_HELP: case COM_HELP:
1398 1401 { {
File src/file_info.c changed (mode: 100644) (index 9c275e741..1d5cb329d)
37 37 void void
38 38 get_perm_string (char * buf, int len, mode_t mode) get_perm_string (char * buf, int len, mode_t mode)
39 39 { {
40 char *perm_sets[] =
40 char *perm_sets[] =
41 41 { "---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx" }; { "---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx" };
42 int u, g, o;
43
44 u = (mode & S_IRWXU) >> 6;
45 g = (mode & S_IRWXG) >> 3;
46 o = (mode & S_IRWXO);
47
48 snprintf (buf, len, "-%s%s%s", perm_sets[u], perm_sets[g], perm_sets[o]);
49
50 if (S_ISLNK (mode))
51 buf[0] = 'l';
52 else if (S_ISDIR (mode))
53 buf[0] = 'd';
54 else if (S_ISBLK (mode))
55 buf[0] = 'b';
56 else if (S_ISCHR (mode))
57 buf[0] = 'c';
58 else if (S_ISFIFO (mode))
59 buf[0] = 'f';
60 else if (S_ISSOCK (mode))
61 buf[0] = 's';
62
63 if (mode & S_ISVTX)
64 buf[9] = (buf[9] == '-') ? 'T' : 't';
65 if (mode & S_ISGID)
66 buf[6] = (buf[6] == '-') ? 'S' : 's';
67 if (mode & S_ISUID)
68 buf[3] = (buf[3] == '-') ? 'S' : 's';
42 int u, g, o;
43
44 u = (mode & S_IRWXU) >> 6;
45 g = (mode & S_IRWXG) >> 3;
46 o = (mode & S_IRWXO);
47
48 snprintf (buf, len, "-%s%s%s", perm_sets[u], perm_sets[g], perm_sets[o]);
49
50 if (S_ISLNK (mode))
51 buf[0] = 'l';
52 else if (S_ISDIR (mode))
53 buf[0] = 'd';
54 else if (S_ISBLK (mode))
55 buf[0] = 'b';
56 else if (S_ISCHR (mode))
57 buf[0] = 'c';
58 else if (S_ISFIFO (mode))
59 buf[0] = 'f';
60 else if (S_ISSOCK (mode))
61 buf[0] = 's';
62
63 if (mode & S_ISVTX)
64 buf[9] = (buf[9] == '-') ? 'T' : 't';
65 if (mode & S_ISGID)
66 buf[6] = (buf[6] == '-') ? 'S' : 's';
67 if (mode & S_ISUID)
68 buf[3] = (buf[3] == '-') ? 'S' : 's';
69 69 } }
70 70
71 71 void void
File src/file_magic.c added (mode: 100644) (index 000000000..eb49fdfff)
1 #include "../config.h"
2
3 #if defined(HAVE_LIBGTK) || defined(HAVE_LIBMAGIC)
4
5 #ifdef HAVE_LIBGTK
6 #include <gtk/gtk.h>
7 #include <glib-2.0/gio/gio.h>
8 #endif
9
10 #ifdef HAVE_LIBMAGIC
11 #include <magic.h>
12 #endif
13
14 #include <sys/dir.h>
15
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19
20 #include "status.h"
21
22 #include "file_magic.h"
23
24 static char* handlers;
25 static size_t handlers_len;
26
27 static int get_gtk_mimetype(const char* filename, char* buf);
28 static int get_magic_mimetype(const char* filename, char* buf);
29 static char * get_handlers(const char* mime_type);
30 static void enum_files(const char* path, const char* mime_type);
31 static void process_file(const char* path, const char* mime_type);
32 static int ends_with(const char* str, const char* suffix);
33 static void expand_desktop(const char* str, char* buf);
34
35 char*
36 get_magic_handlers(const char* file)
37 {
38 char mimetype[128];
39
40 if(get_gtk_mimetype(file, mimetype) == -1)
41 {
42 if(get_magic_mimetype(file, mimetype) == -1)
43 return NULL;
44 }
45
46 return get_handlers(mimetype);
47 }
48
49 static int
50 get_gtk_mimetype(const char* filename, char* buf)
51 {
52 #ifdef HAVE_LIBGTK
53 GFile* file;
54 GFileInfo* info;
55
56 if(!curr_stats.gtk_available)
57 return -1;
58
59 file = g_file_new_for_path(filename);
60 info = g_file_query_info(file, "standard::", G_FILE_QUERY_INFO_NONE, NULL,
61 NULL);
62 if(info == NULL)
63 {
64 g_object_unref(file);
65 return -1;
66 }
67
68 strcpy(buf, g_file_info_get_content_type(info));
69 g_object_unref(info);
70 g_object_unref(file);
71 return 0;
72 #else /* #ifdef HAVE_LIBGTK */
73 return -1;
74 #endif /* #ifdef HAVE_LIBGTK */
75 }
76
77 static int
78 get_magic_mimetype(const char* filename, char* buf)
79 {
80 #ifdef HAVE_LIBMAGIC
81 magic_t magic;
82
83 magic = magic_open(MAGIC_MIME_TYPE);
84 if(magic == NULL)
85 return -1;
86
87 magic_load(magic, NULL);
88
89 strcpy(buf, magic_file(magic, filename));
90
91 magic_close(magic);
92 return 0;
93 #else /* #ifdef HAVE_LIBMAGIC */
94 return -1;
95 #endif /* #ifdef HAVE_LIBMAGIC */
96 }
97
98 char *
99 get_handlers(const char* mime_type)
100 {
101 free(handlers);
102 handlers = NULL;
103 handlers_len = 0;
104
105 enum_files("/usr/share/applications", mime_type);
106 enum_files("/usr/local/share/applications", mime_type);
107
108 return handlers;
109 }
110
111 static void
112 enum_files(const char* path, const char* mime_type)
113 {
114 DIR* dir;
115 struct dirent* dentry;
116 const char* slash = "";
117
118 dir = opendir(path);
119 if(dir == NULL)
120 {
121 perror("opendir");
122 return;
123 }
124
125 if(path[strlen(path) - 1] != '/')
126 slash = "/";
127
128 while((dentry = readdir(dir)) != NULL) {
129 char buf[PATH_MAX];
130
131 if(strcmp(dentry->d_name, ".") == 0)
132 continue;
133 else if (strcmp(dentry->d_name, "..") == 0)
134 continue;
135
136 snprintf(buf, sizeof (buf), "%s%s%s", path, slash, dentry->d_name);
137 if(dentry->d_type == DT_DIR)
138 enum_files(buf, mime_type);
139 else
140 process_file(buf, mime_type);
141 }
142
143 if(closedir(dir) != 0)
144 perror("closedir");
145 }
146
147 static void
148 process_file(const char* path, const char* mime_type)
149 {
150 FILE* f;
151 char *p;
152 char exec_buf[1024] = "";
153 char mime_type_buf[2048] = "";
154 char buf[2048];
155
156 if(!ends_with(path, ".desktop"))
157 return;
158
159 f = fopen(path, "r");
160 if(f == NULL)
161 {
162 perror("fopen");
163 return;
164 }
165
166 while(fgets(buf, sizeof (buf), f) != NULL)
167 {
168 size_t len = strlen(buf);
169
170 if(buf[len - 1] == '\n')
171 buf[len - 1] = '\0';
172
173 if(strncmp(buf, "Exec=", 5) == 0)
174 strcpy(exec_buf, buf);
175 else if (strncmp(buf, "MimeType=", 9) == 0)
176 strcpy(mime_type_buf, buf);
177 }
178
179 fclose(f);
180
181 if(strstr(mime_type_buf, mime_type) == NULL)
182 return;
183 if(exec_buf[0] == '\0')
184 return;
185
186 expand_desktop(exec_buf + 5, buf);
187 p = realloc(handlers, handlers_len + 1 + strlen(buf) + 1);
188 if(p == NULL)
189 return;
190
191 handlers = p;
192 if(handlers_len == 0)
193 *handlers = '\0';
194 else
195 strcat(handlers, ",");
196 handlers_len += 1 + strlen(buf);
197 strcat(handlers, buf);
198 }
199
200 static int
201 ends_with(const char* str, const char* suffix)
202 {
203 size_t str_len = strlen(str);
204 size_t suf_len = strlen(suffix);
205
206 if(str_len < suf_len)
207 return 0;
208 else
209 return (strcmp(suffix, str + str_len - suf_len) == 0);
210 }
211
212 static void
213 expand_desktop(const char* str, char* buf)
214 {
215 int substituted = 0;
216 while(*str != '\0')
217 {
218 if(*str != '%')
219 {
220 *buf++ = *str++;
221 continue;
222 }
223 str++;
224 if(*str == 'c')
225 {
226 substituted = 1;
227 strcpy(buf, "caption");
228 buf += strlen(buf);
229 }
230 else if(strchr("Uuf", *str) != NULL)
231 {
232 substituted = 1;
233 strcpy(buf, "%f");
234 buf += strlen(buf);
235 }
236 str++;
237 }
238 if(substituted)
239 *buf = '\0';
240 else
241 {
242 *buf = ' ';
243 strcpy(buf + 1, "%f");
244 }
245 }
246
247 #endif /* #if defined(HAVE_LIBGTK) || defined(HAVE_LIBMAGIC) */
248
249 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab : */
File src/file_magic.h added (mode: 100644) (index 000000000..7b3bcef14)
1 #if defined(HAVE_LIBGTK) || defined(HAVE_LIBMAGIC)
2
3 #ifndef __MAGIC_H__
4 #define __MAGIC_H__
5
6 char* get_magic_handlers(const char* file);
7
8 #endif
9
10 #endif /* #if defined(HAVE_LIBGTK) || defined(HAVE_LIBMAGIC) */
11
12 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab : */
File src/fileops.c changed (mode: 100644) (index 62d8d02a2..d002142ce)
... ... handle_file(FileView *view, int dont_execute)
291 291
292 292 if(strcmp(filename, "../") == 0) if(strcmp(filename, "../") == 0)
293 293 cd_updir(view); cd_updir(view);
294 else if(change_directory(view, filename) == 0)
294 else if(change_directory(view, filename) == 0)
295 295 { {
296 296 load_dir_list(view, 0); load_dir_list(view, 0);
297 297 moveto_list_pos(view, view->curr_line); moveto_list_pos(view, view->curr_line);
File src/menus.c changed (mode: 100644) (index d71b3f48c..dbfefa69d)
25 25 #include <sys/ioctl.h> #include <sys/ioctl.h>
26 26 #include <signal.h> #include <signal.h>
27 27
28 #include "../config.h"
29
28 30 #include "background.h" #include "background.h"
29 31 #include "bookmarks.h" #include "bookmarks.h"
30 32 #include "cmdline.h" #include "cmdline.h"
31 33 #include "color_scheme.h" #include "color_scheme.h"
32 34 #include "commands.h" #include "commands.h"
33 35 #include "config.h" #include "config.h"
36 #include "file_magic.h"
34 37 #include "filelist.h" #include "filelist.h"
35 38 #include "fileops.h" #include "fileops.h"
36 39 #include "filetype.h" #include "filetype.h"
 
... ... reset_popup_menu(menu_info *m)
149 152 free(m->title); free(m->title);
150 153
151 154 werase(menu_win); werase(menu_win);
152 redraw_window();
153 155 } }
154 156
155 157 void void
 
... ... execute_apropos_cb(FileView *view, menu_info *m)
458 460 } }
459 461 else else
460 462 free(free_this); free(free_this);
461
462 463 } }
463 464
464 465 static void static void
 
... ... execute_locate_cb(FileView *view, menu_info *m)
512 513 free(free_this); free(free_this);
513 514 } }
514 515
516 static void
517 execute_filetype(char *cmd, int background)
518 {
519 if(!background)
520 shellout(cmd, 0);
521 else
522 start_background_job(cmd);
523 }
524
515 525 static void static void
516 526 execute_filetype_cb(FileView *view, menu_info *m) execute_filetype_cb(FileView *view, menu_info *m)
517 527 { {
 
... ... execute_filetype_cb(FileView *view, menu_info *m)
519 529 char *prog_str = get_all_programs_for_file(filename); char *prog_str = get_all_programs_for_file(filename);
520 530 char command[NAME_MAX]; char command[NAME_MAX];
521 531 char *ptr = NULL; char *ptr = NULL;
532 int background = m->extra_data;
522 533
534 #if defined(HAVE_LIBGTK) || defined(HAVE_LIBMAGIC)
535 if(prog_str == NULL)
536 prog_str = get_magic_handlers(filename);
537 #endif
523 538
524 539 if((ptr = strchr(prog_str, ',')) == NULL) if((ptr = strchr(prog_str, ',')) == NULL)
525 540 { {
 
... ... execute_filetype_cb(FileView *view, menu_info *m)
527 542 { {
528 543 int m = 0; int m = 0;
529 544 char *expanded_command = expand_macros(view, prog_str, NULL, &m, 0); char *expanded_command = expand_macros(view, prog_str, NULL, &m, 0);
530 shellout(expanded_command, 0);
545 execute_filetype(expanded_command, background);
531 546 free(expanded_command); free(expanded_command);
532 547 return; return;
533 548 } }
534 549 else else
535 550 { {
536 551 snprintf(command, sizeof(command), "%s %s", prog_str, filename); snprintf(command, sizeof(command), "%s %s", prog_str, filename);
537 shellout(command, 0);
552 execute_filetype(command, background);
538 553 return; return;
539 554 } }
540 555 } }
 
... ... execute_filetype_cb(FileView *view, menu_info *m)
556 571 { {
557 572 int m = 0; int m = 0;
558 573 char *expanded_command = expand_macros(view, prog_copy, NULL, &m, 0); char *expanded_command = expand_macros(view, prog_copy, NULL, &m, 0);
559 shellout(expanded_command, 0);
574 execute_filetype(expanded_command, background);
560 575 free(expanded_command); free(expanded_command);
561 576 free(free_this); free(free_this);
562 577 return; return;
563 578 } }
564 579 else else
565 580 { {
566 snprintf(command, sizeof(command), "%s %s",
567 prog_copy, filename);
568 shellout(command, 0);
581 snprintf(command, sizeof(command), "%s %s", prog_copy, filename);
582 execute_filetype(command, background);
569 583 free(free_this); free(free_this);
570 584 return; return;
571 585 } }
 
... ... execute_filetype_cb(FileView *view, menu_info *m)
577 591 { {
578 592 int m = 0; int m = 0;
579 593 char *expanded_command = expand_macros(view, prog_copy, NULL, &m, 0); char *expanded_command = expand_macros(view, prog_copy, NULL, &m, 0);
580 shellout(expanded_command, 0);
594 execute_filetype(expanded_command, background);
581 595 free(expanded_command); free(expanded_command);
582 596 free(free_this); free(free_this);
583 597 return; return;
 
... ... execute_filetype_cb(FileView *view, menu_info *m)
585 599 else else
586 600 { {
587 601 snprintf(command, sizeof(command), "%s %s", prog_copy, filename); snprintf(command, sizeof(command), "%s %s", prog_copy, filename);
588 shellout(command, 0);
602 execute_filetype(command, background);
589 603 free(free_this); free(free_this);
590 604 return; return;
591 605 } }
 
... ... execute_menu_cb(FileView *view, menu_info *m)
616 630 execute_jobs_cb(view, m); execute_jobs_cb(view, m);
617 631 break; break;
618 632 case LOCATE: case LOCATE:
619 execute_locate_cb(view, m);
620 break;
633 execute_locate_cb(view, m);
621 634 break; break;
622 635 case VIFM: case VIFM:
623 636 break; break;
 
... ... reload_bookmarks_menu_list(menu_info *m)
634 647
635 648 getmaxyx(menu_win, z, len); getmaxyx(menu_win, z, len);
636 649
637
638 650 for (z = 0; z < m->len; z++) for (z = 0; z < m->len; z++)
639 651 { {
640 652 free(m->data[z]); free(m->data[z]);
 
... ... show_commands_menu(FileView *view)
914 926 } }
915 927
916 928 void void
917 show_filetypes_menu(FileView *view)
929 show_filetypes_menu(FileView *view, int force_mime, int background)
918 930 { {
919 931 char *filename = get_current_file_name(view); char *filename = get_current_file_name(view);
920 932 char *prog_str = get_all_programs_for_file(filename); char *prog_str = get_all_programs_for_file(filename);
921 if (prog_str == NULL)
922 {
923 show_error_msg(" Filetype is not set. ",
933
934 #if defined(HAVE_LIBGTK) || defined(HAVE_LIBMAGIC)
935 if(prog_str == NULL || force_mime)
936 prog_str = get_magic_handlers(filename);
937 #endif
938
939 if(prog_str == NULL) {
940 show_error_msg(" Filetype is not set. ",
924 941 "No programs set for this filetype."); "No programs set for this filetype.");
925 942 return; return;
926 943 } }
927 else
944
928 945 { {
929 946 int x = 0; int x = 0;
930 947 int len = 0; int len = 0;
 
... ... show_filetypes_menu(FileView *view)
943 960 m.title = NULL; m.title = NULL;
944 961 m.args = NULL; m.args = NULL;
945 962 m.data = NULL; m.data = NULL;
963 m.extra_data = background;
946 964
947 965 getmaxyx(menu_win, m.win_rows, len); getmaxyx(menu_win, m.win_rows, len);
948 966
File src/menus.h changed (mode: 100644) (index 54e5a066b..0b766d9b7)
... ... typedef struct menu_info
54 54 char *title; char *title;
55 55 char *args; char *args;
56 56 char **data; char **data;
57 int extra_data; /* for filetype background flag */
57 58 /* For user menus only */ /* For user menus only */
58 59 char *get_info_script; /* program + args to fill in menu. */ char *get_info_script; /* program + args to fill in menu. */
59 60 }menu_info; }menu_info;
 
... ... void show_bookmarks_menu(FileView *view);
62 63 void show_commands_menu(FileView *view); void show_commands_menu(FileView *view);
63 64 void show_history_menu(FileView *view); void show_history_menu(FileView *view);
64 65 void show_vifm_menu(FileView *view); void show_vifm_menu(FileView *view);
65 void show_filetypes_menu(FileView *view);
66 void show_filetypes_menu(FileView *view, int force_mime, int background);
66 67 void show_jobs_menu(FileView *view); void show_jobs_menu(FileView *view);
67 68 void show_locate_menu(FileView *view, char *args); void show_locate_menu(FileView *view, char *args);
68 69 void show_apropos_menu(FileView *view, char *args); void show_apropos_menu(FileView *view, char *args);
File src/status.h changed (mode: 100644) (index 0f5cd0bb7..8ae9b1ff0)
19 19 #ifndef __STATUS_H__ #ifndef __STATUS_H__
20 20 #define __STATUS_H__ #define __STATUS_H__
21 21
22 #include "../config.h"
23
22 24 #include <sys/stat.h> #include <sys/stat.h>
23 25
24 26 typedef struct typedef struct
 
... ... typedef struct
42 44 int setting_change; int setting_change;
43 45 int skip_history; int skip_history;
44 46 int save_locations; /* for :wq and ZZ */ int save_locations; /* for :wq and ZZ */
47
48 #ifdef HAVE_LIBGTK
49 int gtk_available; /* for mimetype detection */
50 #endif
45 51 }Status; }Status;
46 52
47 53 extern Status curr_stats; extern Status curr_stats;
File src/ui.c changed (mode: 100644) (index 2fd593145..9dfc76b71)
... ... update_stat_window(FileView *view)
139 139 mvwaddstr(stat_win, 0, cur_x, size_buf); mvwaddstr(stat_win, 0, cur_x, size_buf);
140 140 cur_x += 12; cur_x += 12;
141 141 mvwaddstr(stat_win, 0, cur_x, perm_buf); mvwaddstr(stat_win, 0, cur_x, perm_buf);
142 cur_x += 9;
142 cur_x += 10;
143 143 mvwaddstr(stat_win, 0, cur_x, id_buf); mvwaddstr(stat_win, 0, cur_x, id_buf);
144 144 snprintf(name_buf, sizeof(name_buf), "%d %s filtered", snprintf(name_buf, sizeof(name_buf), "%d %s filtered",
145 145 view->filtered, view->filtered == 1 ? "file" : "files"); view->filtered, view->filtered == 1 ? "file" : "files");
File src/vifm-help.txt changed (mode: 100644) (index a02a900a9..c5c6b22dc)
... ... The basic vi key bindings are used to move through the files and popup
110 110 apropos command. apropos command.
111 111 :com! name action - will overwrite a previously set command. :com! name action - will overwrite a previously set command.
112 112 :delc command_name will remove the command_name user command :delc command_name will remove the command_name user command
113 :f[ile] [mime] - popup menu of programs set for the file type of the current file.
114 When argument passed, show programs set based on file mimetype.
115 Add ' &' in the end of command if you want to start program in background.
113 116 :fil regular_expression pattern will filter the files out of the directory :fil regular_expression pattern will filter the files out of the directory
114 117 listing that match the regular expression. listing that match the regular expression.
115 118 :fil \.o$ - would filter all files ending in .o from the filelist. :fil \.o$ - would filter all files ending in .o from the filelist.
File src/vifm.1 changed (mode: 100644) (index 99fe6ddd1..15e806dd2)
... ... sets a new user command.
218 218 .BI ":delc command_name" .BI ":delc command_name"
219 219 will remove the command_name user command will remove the command_name user command
220 220 .TP .TP
221 .BI ":file [mime]"
222 popup menu of programs set for the file type of the current file. When argument passed, show programs set based on file mimetype.
223 .TP
221 224 .BI ":fil regular_expression pattern" .BI ":fil regular_expression pattern"
222 225 will filter all the files out of the directory listing that match the regular expression. will filter all the files out of the directory listing that match the regular expression.
223 226 .TP .TP
File src/vifm.c changed (mode: 100644) (index aa02ab819..f372833a0)
18 18
19 19 #define VERSION "0.6" #define VERSION "0.6"
20 20
21 #include "../config.h"
22
23 #ifdef HAVE_LIBGTK
24 #include <gtk/gtk.h>
25 #include <glib-2.0/gio/gio.h>
26 #endif
27
21 28 #include <ncurses.h> #include <ncurses.h>
22 29 #include <unistd.h> /* getcwd & sysconf */ #include <unistd.h> /* getcwd & sysconf */
23 30 #include <string.h> /* strncpy */ #include <string.h> /* strncpy */
 
... ... main(int argc, char *argv[])
146 153
147 154 init_status(); init_status();
148 155
156 #ifdef HAVE_LIBGTK
157 curr_stats.gtk_available = gtk_init_check(&argc, &argv);
158 #endif
159
149 160 if(cfg.show_one_window) if(cfg.show_one_window)
150 161 curr_stats.number_of_windows = 1; curr_stats.number_of_windows = 1;
151 162 else else
File src/vifm.txt changed (mode: 100644) (index 800e7eccf..a0e4dcf96)
... ... The builtin commands are:
45 45 :delc[ommand] user_command - remove user_command. :delc[ommand] user_command - remove user_command.
46 46 :e[dit} - will load the selected file or files into vi. :e[dit} - will load the selected file or files into vi.
47 47 :em[pty] - permanently remove files from the ~/.vifm/Trash directory. :em[pty] - permanently remove files from the ~/.vifm/Trash directory.
48 :f[ile] - popup menu of programs set for the file type of the current file.
48 :f[ile] [mime] - popup menu of programs set for the file type of the current file.
49 When argument passed, show programs set based on file mimetype.
50 Add ' &' in the end of command if you want to start program in background.
49 51 :fil[ter] regular_expression - will filter files matching the pattern out of :fil[ter] regular_expression - will filter files matching the pattern out of
50 52 the directory. See |Filters| the directory. See |Filters|
51 53 :h[elp] - show this help file. :h[elp] - show this help file.
File src/vifmrc changed (mode: 100644) (index afd628bc0..bb48d3d2f)
... ... SHOW_FULL=0
81 81
82 82 USE_VIM_HELP=0 USE_VIM_HELP=0
83 83
84 # If you would like to run an executable file when you
84 # If you would like to run an executable file when you
85 85 # press return on the file name set this to 1. # press return on the file name set this to 1.
86 86
87 87 RUN_EXECUTABLE=0 RUN_EXECUTABLE=0
 
... ... FILETYPE=Archive=tar.gz,tgz==tar -tzf %f | less,tar -zxvf %f
129 129
130 130 # For automated FUSE mounts, you must register an extension with FILETYPE=.. # For automated FUSE mounts, you must register an extension with FILETYPE=..
131 131 # in the following format: # in the following format:
132 # FILETYPE=description=extensions=FUSE_MOUNT|some_mount_command using %SOURCE_FILE and %DESTINATION_DIR variables
132 # FILETYPE=description=extensions=consoleviewer=FUSE_MOUNT|some_mount_command using %SOURCE_FILE and %DESTINATION_DIR variables
133 133 # %SOURCE_FILE and %DESTINATION_DIR are filled in by vifm at runtime. # %SOURCE_FILE and %DESTINATION_DIR are filled in by vifm at runtime.
134 134 # A sample line might look like this: # A sample line might look like this:
135 # FILETYPE=FuseZipMount=zip,jar,war,ear=FUSE_MOUNT|fuse-zip %SOURCE_FILE %DESTINATION_DIR
135 # FILETYPE=FuseZipMount=zip,jar,war,ear==FUSE_MOUNT|fuse-zip %SOURCE_FILE %DESTINATION_DIR
136 136
137 137 # The FUSE_HOME directory will be used as a root dir for all FUSE mounts. # The FUSE_HOME directory will be used as a root dir for all FUSE mounts.
138 138 # Unless it exists with write/exec permissions set, vifm will attempt to create it. # Unless it exists with write/exec permissions set, vifm will attempt to create it.
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vifm

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vifm

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master