是否有一个可以检测和打开文件的终端插件?

是否有一个可以检测和打开文件的终端插件?

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

/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并使用 Gedit(或其他程序)打开第 233 行的文件。

答案1

我想,我自己可能需要这样的选项。据我所知,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.hFLAVOR_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://前缀组成正确的 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
    

答案2

只能从终端打开链接(右键单击 -> 打开链接),基本上你需要在文件路径前加上完整的 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 <your file>)

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

相关内容