Giter Site home page Giter Site logo

hyper-match's Introduction

Hyper Match

WARNING: THIS PROJECT IS DEPRECATED

Hyper v2 now uses xterm.js which supports link detection out of the box.

Mentioned in Awesome Hyper npm

An extension for Hyper that binds commands to patterns detected in the terminal. When a pattern is detected, it is rendered as a hyperlink which will execute your command on click.

Patterns such as urls, email addresses and file paths can be configured to do anything when clicked, for example: open a browser, email client, or file manager.

Inspired by iterm's Triggers. Based on hyperlinks.

Demo

Usage

Install Hyper and add hyper-match to plugins in ~/.hyper.js.

Customizing styles

Add custom styles to termCSS in your ~/.hyper.js.

termCSS: `
    x-screen a {
        color: #ff2e88;
        text-decoration: none;
    }

    x-screen a.hover {
        text-decoration: underline;
    }
`

Configuration

A trigger has the following properties:

  • name: Unique identifier for a trigger
  • pattern: A regular expression
  • strategy: A command to be executed when a link is clicked. hyper-match uses .replace() under the hood to output parameters into the supplied strategy.
    • $&: Inserts the matched substring.
    • $: Inserts the portion of the string that precedes the matched substring.
    • $': Inserts the portion of the string that follows the matched substring.
    • $n: Where n is a positive integer less than 100, inserts the nth parenthesized submatch string, provided the first argument was a RegExp object. Note that this is 1-indexed.
  • options: Regular expression options
  • priority: Defines the weight of a pattern and is used if the pattern conflicts with another
  • linkColor: A CSS color

Example:

module.exports = {
  ...
  config: {
    ...
    'hyper-match': {
        triggers: [
            {
                name: 'date',
                pattern: '^(0[1-9]|1[0-2])[\\/](0[1-9]|[12]\\d|3[01])[\\/](19|20)\\d{2}$',
                options: 'g',
                strategy: 'echo \'$&\' | pbcopy && open "https://calendar.google.com"',
                priority: 1,
                linkColor: '#4285f4',
            },
            {
                name: 'email',
                pattern: '[a-z0-9]+[_a-z0-9\\.-]*[a-z0-9]+@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,4})',
                options: 'gi',
                strategy: 'echo \'$&\' | pbcopy && open "https://mail.google.com"',
                priority: 2,
            },
            {
                name: 'css-color',
                pattern: '#(?:[a-f\\d]{3}){1,2}\\b|rgb\\((?:(?:\\s*0*(?:25[0-5]|2[0-4]\\d|1?\\d?\\d)\\s*,){2}\\s*0*(?:25[0-5]|2[0-4]\\d|1?\\d?\\d)|\\s*0*(?:100(?:\\.0+)?|\\d?\\d(?:\\.\\d+)?)%(?:\\s*,\\s*0*(?:100(?:\\.0+)?|\\d?\\d(?:\\.\\d+)?)%){2})\\s*\\)|hsl\\(\\s*0*(?:360|3[0-5]\\d|[12]?\\d?\\d)\\s*(?:,\\s*0*(?:100(?:\\.0+)?|\\d?\\d(?:\\.\\d+)?)%\\s*){2}\\)|(?:rgba\\((?:(?:\\s*0*(?:25[0-5]|2[0-4]\\d|1?\\d?\\d)\\s*,){3}|(?:\\s*0*(?:100(?:\\.0+)?|\\d?\\d(?:\\.\\d+)?)%\\s*,){3})|hsla\\(\\s*0*(?:360|3[0-5]\\d|[12]?\\d?\\d)\\s*(?:,\\s*0*(?:100(?:\\.0+)?|\\d?\\d(?:\\.\\d+)?)%\\s*){2},)\\s*0*(?:1|0(?:\\.\\d+)?)\\s*\\)',
                options: 'gi',
                strategy: 'echo \'$&\' | pbcopy',
                priority: 1,
            },
        ]
    }
    ...
  }
  ...
}

hyper-match's People

Contributors

danieldelcore avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

hyper-match's Issues

Error: Cannot find module 'babel-runtime/core-js/json/stringify'

The plugin does not work, and I just get this Error in the dev tools:

Error: Cannot find module 'babel-runtime/core-js/json/stringify'
    at Module._resolveFilename (module.js:470)
    at Function.Module._resolveFilename (/Applications/Hyper.app/Contents/Resources/electron.asar/common/reset-search-paths.js:35)
    at Function.Module._load (module.js:418)
    at Function.c._load (bundle.js:1)
    at Module.require (module.js:498)
    at require (internal/module.js:20)
    at Object.<anonymous> (/Users/gbriel/.hyper_plugins/node_modules/hypermatch/lib/index.js:3)
    at Object.<anonymous> (/Users/gbriel/.hyper_plugins/node_modules/hypermatch/lib/index.js:130)
    at Module._compile (module.js:571)
    at Object.Module._extensions..js (module.js:580)

problem with hyper :(

  • OS version and name: macOS high sierra and Windows 10
  • Hyper.app version: 1.4.8 and canary version(2.0.4)

Disables writing in Hyper

Windows 10
22219451_1149860821824173_744382452_o

macOS
screen shot 2017-10-02 at 19 48 30

Cannot open files with trigger pattern

I'm unable to open files that match a trigger pattern using 'open "$&"'.

Video here: https://goo.gl/5wpiR5

I also tried hardcoding the file name in the strategy, like strategy: 'open "$&"' which didn't open the file. Any help would be greatly appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.