-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kitty): Add JIRA hints to kitty terminal
The use of load_env in jira-hints is because environment variables cannot be accessed in the kitty script.
- Loading branch information
Showing
3 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export WORK=false | ||
export WORK_JIRA_URL=https://jira.example.com | ||
export JIRA_URL=$WORK_JIRA_URL | ||
export JIRA_KEYS=PROJ|BUGS | ||
export HOMEBREW_GITHUB_API_TOKEN= | ||
export VULTR_API_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import re | ||
import os | ||
|
||
|
||
def load_env(env_path): | ||
with open(os.path.expanduser(env_path)) as f: | ||
for line in f: | ||
if line.strip() and not line.startswith('#'): | ||
line = line.replace('export ', '').strip() | ||
if '=' in line: | ||
key, value = line.split('=', 1) | ||
os.environ[key.strip()] = value.strip().strip('"\'') | ||
|
||
load_env('~/.dotfiles/.env') | ||
JIRA_URL = os.environ.get('WORK_JIRA_URL') | ||
JIRA_KEYS = os.environ.get('JIRA_KEYS') | ||
|
||
def mark(text, args, Mark, extra_cli_args, *a): | ||
for idx, m in enumerate(re.finditer(f'(?:{JIRA_KEYS})-[0-9]+', text)): | ||
start, end = m.span() | ||
mark_text = text[start:end].replace('\n', '').replace('\0', '') | ||
yield Mark(idx, start, end, mark_text, {}) | ||
|
||
def handle_result(args, data, target_window_id, boss, extra_cli_args, *a): | ||
matches, groupdicts = [], [] | ||
for m, g in zip(data['match'], data['groupdicts']): | ||
if m: | ||
matches.append(m), groupdicts.append(g) | ||
for ticket in matches: | ||
boss.open_url(f'{JIRA_URL}/browse/{ticket}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters