Page MenuHomeDevCentral

Write a Terminator plugin to resolve hashes
Open, NormalPublic

Description

Terminator allows plugins to add capabilities to the terminal.

We can detect hashes and then call resolve-hash with the found exception.

Regexp to detect hash

In the servers log, we use the following regexp for hashes: /\b([0-9a-f]{7,40})\b/g (extracted from servers-log.js).

References

Related Objects

Mentioned In
Python track
Mentioned Here
P384 Terminator plugin

Event Timeline

dereckson triaged this task as Normal priority.Mar 6 2022, 13:13
dereckson created this task.

Hey, I would love to work on this issue but am confused could you help me understand the issue a bit more please.

Hello,

We can chat for this task on IRC if you wish, please ping me on Libera, dereckson my username, and I can show you how the Python code currently works, and how to leverage that for the terminal.

Hi,

This plugin still needs to be written, yes.

I came up with this solution which seems to work as intended :

The plugin detects the hash, make it clickable as a URL, then we can proceed to open the link to the commit page, "resolve-hash" module is responsible for the redirection.

The plugin must be placed here :
~/.config/terminator/plugins/
The plugin needs to be enabled in the global config:
~/.config/terminator/config

Here is the code :

1from terminatorlib.plugin import URLHandler
2import subprocess
3import os
4
5AVAILABLE = ['ResolveHashURLHandler']
6
7class ResolveHashURLHandler(URLHandler):
8
9capabilities = ['url_handler']
10handler_name = 'resolve_hash'
11name = 'Nasqueron Resolve Hash'
12
13# REGEX to detect hashes
14match = r'\b[0-9a-f]{7,40}\b'
15
16def callback(self, url):
17 hash_value = url.strip()
18
19 try:
20 #We define the path to resolve-hash module
21 script_path = os.path.expanduser ("~/bin/resolve-hash")
22
23 result = subprocess.check_output(
24 [script_path, hash_value],
25 stderr=subprocess.STDOUT,
26 text=True
27 )
28 #We clean the result
29 final_url = result.strip()
30
31 # Terminator only opens a navigator is the URL is correct
32 if final_url.startswith('http'):
33 return final_url
34
35 except Exception as e:
36 #if error we return none for terminator to ignore the clic
37 return None
38
39 return None

@dereckson could you test this on your side ?