是否有终端插件允许检测和打开文件?

我正在寻找一个终端插件/扩展,它允许我检测终端输出中的文件路径,并通过单击它们在文本编辑器中打开它们。 完美的解决方案将打开给定行的文件。

/home/dell/pcl/2d/include/pcl/2d/impl/keypoint.hpp:233: warning: no uniquely matching class member found for void pcl::keypoint::imageElementMultiply(ImageType &output, ImageType &input1, ImageType &input2) 

在上面的示例中,我可以单击/home/dell/pcl/2d/include/pcl/2d/impl/keypoint.hpp:233 ,我将在第233行打开带有Gedit(或其他)的文件。

不过,我可能需要这样的选择。 AFAIK, gnome-terminal不支持插件。

我正在使用Ubuntu 14.04,gnome-terminal 3.6.2。 我没有测试足够的时间,期待错误。

  1. 下载源代码和构建依赖项

     sudo apt-get build-dep gnome-terminal apt-get source gnome-terminal 
  2. 添加对路径的支持

    src/terminal-screen.h ,为文件路径添加FLAVOR_DEFAULT_TO_FILE枚举类型

     typedef enum { FLAVOR_AS_IS, FLAVOR_DEFAULT_TO_HTTP, FLAVOR_VOIP_CALL, FLAVOR_EMAIL, FLAVOR_LP, FLAVOR_DEFAULT_TO_FILE } TerminalURLFlavour; 

    src/terminal-screen.c ,添加路径正则表达式(它不完美,可能需要一些调整)

     static const TerminalRegexPattern url_regex_patterns[] = { { SCHEME "//(?:" USERPASS "\\@)?" HOST PORT URLPATH, FLAVOR_AS_IS, G_REGEX_CASELESS }, { "(?:www|ftp)" HOSTCHARS_CLASS "*\\." HOST PORT URLPATH , FLAVOR_DEFAULT_TO_HTTP, G_REGEX_CASELESS }, { "(?:callto:|h323:|sip:)" USERCHARS_CLASS "[" USERCHARS ".]*(?:" PORT "/[a-z0-9]+)?\\@" HOST, FLAVOR_VOIP_CALL, G_REGEX_CASELESS }, { "(?:mailto:)?" USERCHARS_CLASS "[" USERCHARS ".]*\\@" HOSTCHARS_CLASS "+\\." HOST, FLAVOR_EMAIL, G_REGEX_CASELESS }, { "(?:news:|man:|info:)[[:alnum:]\\Q^_{|}~!\"#$%&'()*+,./;:=?`\\E]+", FLAVOR_AS_IS, G_REGEX_CASELESS }, { "(?:lp: #)[[:digit:]]+", FLAVOR_LP, G_REGEX_CASELESS }, { "((~/)|(\\.\\./)|(\\./)|(/))+[^\\n\\t\\r\\v\\0 !$`&*()+:]+[^\\n\\t\\r\\v\\0 !$`&*()+:?.,;\"'\\]\\[<>#{}(]", FLAVOR_DEFAULT_TO_FILE, G_REGEX_CASELESS }, }; 

    src/terminal-util.c ,通过添加file:// prefix来组成正确的URL

      switch (flavor) { case FLAVOR_DEFAULT_TO_HTTP: uri = g_strdup_printf ("http://%s", orig_url); break; case FLAVOR_EMAIL: if (g_ascii_strncasecmp ("mailto:", orig_url, 7) != 0) uri = g_strdup_printf ("mailto:%s", orig_url); else uri = g_strdup (orig_url); break; case FLAVOR_VOIP_CALL: case FLAVOR_AS_IS: uri = g_strdup (orig_url); break; case FLAVOR_LP: uri = terminal_util_get_lp_url (orig_url); break; case FLAVOR_DEFAULT_TO_FILE: uri = g_strdup_printf ("file://%s", orig_url); break; default: uri = NULL; g_assert_not_reached (); } 

    src/terminal-window.c ,解析~和相对路径( ../

     static void popup_open_url_callback (GtkAction *action, TerminalWindow *window) { TerminalWindowPrivate *priv = window->priv; TerminalScreenPopupInfo *info = priv->popup_info; if (info == NULL) return; if (info->flavour==FLAVOR_DEFAULT_TO_FILE){ if (info->string[0]=='~') { char* current_dir_full=terminal_util_resolve_relative_path (g_get_home_dir(), &(info->string)[2]); terminal_util_open_url (GTK_WIDGET (window), current_dir_full, info->flavour, gtk_get_current_event_time ()); } else { char* current_dir=terminal_screen_get_current_dir_with_fallback (info->screen); char* current_dir_full=terminal_util_resolve_relative_path (current_dir, info->string); terminal_util_open_url (GTK_WIDGET (window), current_dir_full, info->flavour, gtk_get_current_event_time ()); } } else { terminal_util_open_url (GTK_WIDGET (window), info->string, info->flavour, gtk_get_current_event_time ()); } } 

      show_link = info->string != NULL && (info->flavour == FLAVOR_AS_IS || info->flavour == FLAVOR_DEFAULT_TO_HTTP || info->flavour == FLAVOR_LP || info->flavour == FLAVOR_DEFAULT_TO_FILE ); 

     static gboolean screen_match_clicked_cb (TerminalScreen *screen, const char *match, int flavour, guint state, TerminalWindow *window) { TerminalWindowPrivate *priv = window->priv; if (screen != priv->active_screen) return FALSE; gtk_widget_grab_focus (GTK_WIDGET (screen)); if (flavour==FLAVOR_DEFAULT_TO_FILE){ if (match[0]=='~') { char* current_dir_full=terminal_util_resolve_relative_path (g_get_home_dir(), &(match)[2]); terminal_util_open_url (GTK_WIDGET (window), current_dir_full, flavour, gtk_get_current_event_time ()); } else { char* current_dir=terminal_screen_get_current_dir_with_fallback (screen); char* current_dir_full=terminal_util_resolve_relative_path (current_dir, match); terminal_util_open_url (GTK_WIDGET (window), current_dir_full, flavour, gtk_get_current_event_time ()); } } else { terminal_util_open_url (GTK_WIDGET (window), match, flavour, gtk_get_current_event_time ()); } return TRUE; } 
  3. 构建和安装

     cd gnome-terminal-3.6.2/ ./configure make make install 

只能从终端打开链接(右键单击 – >打开链接),基本上您需要在文件路径前加上完整的URI:

 /home/dell/pcl/2d/include/pcl/2d/impl/keypoint.hpp 

成为(只需添加file://前缀):

 file:///home/dell/pcl/2d/include/pcl/2d/impl/keypoint.hpp 

在此处输入图像描述

注意:此命令将为您提供文件的绝对路径URI:

 echo file://$(readlink -f ) 

个人gedit /home/dell/pcl/2d/include/pcl/2d/impl/keypoint.hpp可能是最好的选择。

Interesting Posts