dfrankland / hyper-tab-icons

💅 Icons in the header tabs for the current running process in Hyper.app.
91 stars 16 forks source link

Apply regex approach #19

Closed aoki closed 7 years ago

aoki commented 7 years ago

I have same problem(#17). This PR is not configurable.

I use pure prompt. It shows process name at the after when I adopt regex instead of atom/fuzzaldrin. I think don't need fuzzy matching.

This regex (?:[\W]+|^)(PROCESS_NAME)(?:[\W]+|$) match below cases. In this case PROCESS_NAME is 'foo'.

> const regex = /(?:[\W]+|^)(foo)(?:[\W]+|$)/
> regex.test('user : ~/work/github foo');
true
> regex.test('user : foo - ~/work/github');
true
> regex.test('foo : user - ~/work/github');
true

pr

Please close this PR If you don't need.

dfrankland commented 7 years ago

I like this for it's simplicity, but what if there's a process that's similar, but doesn't exactly match? I think it's nice if there's a way to match processes that are related, no? Although, fuzzy finding does't work that well either.

For example, nodes would get matched with node even though it's not explicitly listed in the icon classes array.

henrikruscon commented 7 years ago

Problem with this regex is that for example it'll also match with a folder namned node.

dfrankland commented 7 years ago

@henrikdahl good point.

henrikruscon commented 7 years ago

What about this?

It'll still flash the process icon though. When you cd node folder it'll change title for a millisecond to sites: cd node which matches.

aoki commented 7 years ago

It is a very difficult problem... 🤔 How to get process name position in a title using regex pattern (or fuzzy matching)..

One of the proposal, write config for the process position using regex. However position eval and replacement for keyword too hard. Not quite... 😢

aoki commented 7 years ago

We write config like a below. PROCESS_NAME is process name position in a title.

tabIcons: {
  processNameRegex: '(?:[\\W]+|^)PROCESS_NAME(?:[\\W]+|$)'
}

Load config and evaluate with eval (However, I don't like eval...).

> var config = '(?:[\\W]+|^)PROCESS_NAME(?:[\\W]+|$)'
undefined
> var regexText = config.replace('PROCESS_NAME', '(${e})')
undefined
> regexText
"(?:[\W]+|^)(${e})(?:[\W]+|$)"
> eval(`var f = (e) => { return new RegExp(\`${regexText}\`, \'i\'); }`)
undefined
> f
(e) => { return new RegExp(`(?:[\W]+|^)(${e})(?:[\W]+|$)`, 'i'); }
> f('foo')
/(?:[W]+|^)(foo)(?:[W]+|$)/i
jonaswindey commented 7 years ago

Any chance of getting this merged?

dfrankland commented 7 years ago

This should be fixed with hyper-tab-icons@1.1.3 now. See here: https://github.com/dfrankland/hyper-tab-icons#configtabiconsprocessnameregex