Skip to content

Commit 90bcbbf

Browse files
committed
No need to add index to titles when using hits kitten to choose tab/os_window
1 parent 41049e2 commit 90bcbbf

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

kittens/hints/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ def parse_input(text):
324324

325325

326326
def load_custom_processor(customize_processing):
327+
if customize_processing.startswith('::import::'):
328+
import importlib
329+
m = importlib.import_module(customize_processing[len('::import::'):])
330+
return {k: getattr(m, k) for k in dir(m)}
327331
from kitty.constants import config_dir
328332
customize_processing = os.path.expandvars(os.path.expanduser(customize_processing))
329333
if os.path.isabs(customize_processing):

kitty/boss.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ def detach_window(self, *args):
11911191
'Choose a tab to move the window to',
11921192
''
11931193
]
1194-
fmt = '{} {}'
1194+
fmt = ': {1}'
11951195
tab_id_map = {}
11961196
current_tab = self.active_tab
11971197
for i, tab in enumerate(self.all_tabs):
@@ -1206,7 +1206,7 @@ def detach_window(self, *args):
12061206
lines.append(fmt.format(new_idx, 'New OS Window'))
12071207

12081208
def done(data, target_window_id, self):
1209-
done.tab_id = tab_id_map[int(data['match'][0].strip().partition(' ')[0])]
1209+
done.tab_id = tab_id_map[int(data['groupdicts'][0]['index']) + 1]
12101210

12111211
def done2(target_window_id, self):
12121212
if not hasattr(done, 'tab_id'):
@@ -1223,8 +1223,11 @@ def done2(target_window_id, self):
12231223
self._move_window_to(window=target_window, target_tab_id=tab_id)
12241224

12251225
self._run_kitten(
1226-
'hints', args=('--ascending', '--type=regex', r'--regex=(?m)^\s*\d+ .+$',),
1227-
input_data='\r\n'.join(lines).encode('utf-8'), custom_callback=done, action_on_removal=done2)
1226+
'hints', args=(
1227+
'--ascending', '--customize-processing=::import::kitty.choose_entry',
1228+
r'--regex=(?m)^:\s+.+$',
1229+
), input_data='\r\n'.join(lines).encode('utf-8'), custom_callback=done, action_on_removal=done2
1230+
)
12281231

12291232
def detach_tab(self, *args):
12301233
if not args or args[0] == 'new':
@@ -1234,16 +1237,17 @@ def detach_tab(self, *args):
12341237
'Choose an OS window to move the tab to',
12351238
''
12361239
]
1240+
fmt = ': {1}'
12371241
os_window_id_map = {}
12381242
current_os_window = getattr(self.active_tab, 'os_window_id', 0)
12391243
for i, osw in enumerate(self.os_window_map):
12401244
tm = self.os_window_map[osw]
12411245
if current_os_window != osw and tm.active_tab and tm.active_tab:
12421246
os_window_id_map[i + 1] = osw
1243-
lines.append('{} {}'.format(i + 1, tm.active_tab.title))
1247+
lines.append(fmt.format(i + 1, tm.active_tab.title))
12441248
new_idx = len(os_window_id_map) + 1
12451249
os_window_id_map[new_idx] = None
1246-
lines.append('{} {}'.format(new_idx, 'New OS Window'))
1250+
lines.append(fmt.format(new_idx, 'New OS Window'))
12471251

12481252
def done(data, target_window_id, self):
12491253
done.os_window_id = os_window_id_map[int(data['match'][0].partition(' ')[0])]
@@ -1262,5 +1266,8 @@ def done2(target_window_id, self):
12621266
self._move_tab_to(tab=target_tab, target_os_window_id=os_window_id)
12631267

12641268
self._run_kitten(
1265-
'hints', args=('--ascending', '--type=regex', r'--regex=(?m)^\d+ .+$',),
1266-
input_data='\r\n'.join(lines).encode('utf-8'), custom_callback=done, action_on_removal=done2)
1269+
'hints', args=(
1270+
'--ascending', '--customize-processing=::import::kitty.choose_entry',
1271+
r'--regex=(?m)^:\s+.+$',
1272+
), input_data='\r\n'.join(lines).encode('utf-8'), custom_callback=done, action_on_removal=done2
1273+
)

kitty/choose_entry.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python
2+
# vim:fileencoding=utf-8
3+
# License: GPLv3 Copyright: 2019, Kovid Goyal <kovid at kovidgoyal.net>
4+
5+
import re
6+
7+
8+
def mark(text, args, Mark, extra_cli_args, *a):
9+
for idx, m in enumerate(re.finditer(args.regex, text)):
10+
start, end = m.span()
11+
mark_text = text[start:end].replace('\n', '').replace('\0', '')
12+
yield Mark(idx, start, end, mark_text, {'index': idx})

0 commit comments

Comments
 (0)