Skip to content

Commit

Permalink
feat(kitty): Add JIRA hints to kitty terminal
Browse files Browse the repository at this point in the history
The use of load_env in jira-hints is because environment variables
cannot be accessed in the kitty script.
  • Loading branch information
kang8 committed Feb 8, 2025
1 parent de0c69e commit 5a5982b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.example
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=
30 changes: 30 additions & 0 deletions kitty/.config/kitty/jira-hints.py
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}')
2 changes: 2 additions & 0 deletions kitty/.config/kitty/kitty.conf
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,5 @@ map ctrl+shift+r no_op
map cmd+w no_op

cursor_trail 3

map ctrl+shift+p>j kitten hints --customize-processing jira-hints.py

0 comments on commit 5a5982b

Please sign in to comment.