-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboco.bash
More file actions
805 lines (679 loc) · 20 KB
/
boco.bash
File metadata and controls
805 lines (679 loc) · 20 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
#!/bin/bash
# Copyright(c) 2019 Blacknon. All rights reserved.
# Use of this source code is governed by an MIT license
# that can be found in the LICENSE file.
# @AUTHOR:
# Blacknon(blacknon@orebibou.com)
# @NOTE:
# Incremental search tool implemented with Bash function.
# @TODO:
# - 出力行の検索、絞り込み機能の追加
# - 正規表現での検索機能
# - Ctrl+Rで切り替えできるようにする
# - 行表示の処理を、最低限の画面更新にしてパフォーマンスを改善する
# - バッファを挟んで、リアルタイムで出力が追加されても対応できるようにする
# - optionでTabで下移動モード(非複数選択モード)への切り替えを行えるようにする
# - 参考url(completeができるようにする)
# - https://github.com/pindexis/qfc/blob/master/bin/qfc.sh
## ----------
# function
## ----------
boco() {
## ----------
# variable
## ----------
# ANSI Escape(Color)
local -r COLOR_NONE=$'\E[0m'
local -r COLOR_RED=$'\E[0;31m'
local -r COLOR_GREEN=$'\E[0;32m'
local -r COLOR_ORANGE=$'\E[0;33m'
local -r COLOR_BLUE=$'\E[0;34m'
local -r COLOR_PURPLE=$'\E[0;35m'
local -r COLOR_CYAN=$'\E[0;36m'
local -r COLOR_LGRAY=$'\E[0;37m'
local -r COLOR_BACK_RED=$'\E[41m'
local -r COLOR_BACK_GREEN=$'\E[42m'
local -r COLOR_BACK_ORANGE=$'\E[43m'
local -r COLOR_BACK_BLUE=$'\E[44m'
local -r COLOR_BACK_PURPLE=$'\E[45m'
local -r COLOR_BACK_CYAN=$'\E[46m'
local -r COLOR_BACK_GRAY=$'\E[47m'
# ANSI Escape(Other)
local -r CURSOR_GET=$'\E[6n'
# local use variables
local input # input key code
local tmp # input key code(2nd)
local data # Get stdin or file data
local array # data to Array(Original)
local view_array # data to Array(Refine data)
local now_cursor_line # Now cursor position in terminal(line)
local now_list_line # now cursor line (in boco list)
local selected_line # now selected line (in boco list. array)
local max_line # VIEW_ARRAY_max_line
local view_max_line # max line in terminal
local scroll_position # boco list scroll position (1st line)
local surplus_line
# option
local flg_p
local search_word
# env
local -r OLD_IFS=${IFS}
local use_perf_mode
local rendered_line_count=0
local prev_search_word
local prev_search_word_lower_array=()
## ----------
# getopts
## ----------
__boco_usage() {
printf '%s\n' "usage:"
printf '%s\n' " -p ... not print control character"
printf '%s\n' " -q {search_word} ... search word"
return 1
}
while getopts :pq: OPT; do
case ${OPT} in
p) flg_p="TRUE" ;;
q) search_word="${OPTARG}" ;;
: | \?)
__boco_usage
return 1
;;
esac
done
shift $((OPTIND - 1))
## ----------
# shopt/setopt
## ----------
# set shopt(get windows size.)
case "${SHELL##*/}" in
bash*)
shopt -s checkwinsize
shopt -s nocasematch
(
:
:
)
;;
zsh*) setopt localoptions ksharrays nocasematch ;;
esac
if [[ -n "${BOCO_PERFORMANCE_MODE}" ]]; then
use_perf_mode="${BOCO_PERFORMANCE_MODE}"
elif [[ -n "${SSH_CONNECTION}" || -n "${SSH_CLIENT}" || -n "${SSH_TTY}" ]]; then
use_perf_mode=1
else
use_perf_mode=0
fi
## ----------
# function
## ----------
# @brief:
# get now cursor positon in terminal.
# @return: now_cursor_line
__get_cursor_position() {
# variable
local old_stty
local cursor
# move tty
exec </dev/tty
old_stty=$(stty -g)
stty raw -echo min 0
# get position data
printf "${CURSOR_GET}" >/dev/tty
case "${SHELL##*/}" in
bash*) IFS=';' read -r -d R -a cursor ;;
zsh*) IFS=';' read -s -d R cursor ;;
esac
IFS=$'\n'
stty "${old_stty}"
cursor="${cursor##*\[}"
cursor="${cursor%;*}"
now_cursor_line=${cursor}
}
# @brief: print data line with ANSI escape code.
# __print_line_position
# ${1} ... add_line
# ${2} ... cursor_line_type(0(current line)|1(selected line)|2(other))
# ${3} ... print_data
__print_line_position() {
# variable
local add_line
local cursor_line_flag
local print_line
local print_data
add_line=${1}
cursor_line_type=${2}
print_line=$((${now_cursor_line} + ${add_line}))
line="${3}"
print_data=${line#*:}
# move cursor
printf "\e["${print_line}";0H" >&2
# print line
if [[ ${cursor_line_type} -eq 0 ]]; then
printf "${COLOR_YELLOW}${COLOR_BACK_BLUE}"'%s'"${COLOR_NONE}\n" "${print_data}" >&2
elif [[ ${cursor_line_type} -eq 1 ]]; then
printf "${COLOR_YELLOW}${COLOR_BACK_GREEN}"'%s'"${COLOR_NONE}\n" "${print_data}" >&2
else
printf "%s\n" "${print_data}" >&2
fi
}
# @brief:
# __print_data
__print_data() {
# variable
local header_text
local header_text_count
local list_range_max
local list_line
local print_data
local cursor_line_type
local output
local clear_count
# move cursor
header_text="QUERY: ${search_word} "
header_text_count=${#header_text}
output=$'\e['"${now_cursor_line}"';0H'
output+=$'\e[2K'"${header_text}"$'\n'
# print line
list_range_max=$((${scroll_position} + ${view_max_line}))
local x=0
for ((i = ${scroll_position}; i < ${list_range_max}; i++)); do
list_line="${view_array_data[${i}]}"
print_data=${list_line#*:}
if [[ ${now_list_line} -eq ${i} ]]; then
cursor_line_type=0
elif __selected_check_in "${list_line%%:*}"; then
cursor_line_type=1
else
cursor_line_type=2
fi
output+=$'\e[2K'
if [[ ${cursor_line_type} -eq 0 ]]; then
output+="${COLOR_YELLOW}${COLOR_BACK_BLUE}${print_data}${COLOR_NONE}"
elif [[ ${cursor_line_type} -eq 1 ]]; then
output+="${COLOR_YELLOW}${COLOR_BACK_GREEN}${print_data}${COLOR_NONE}"
else
output+="${print_data}"
fi
output+=$'\n'
x=$((${x} + 1))
done
clear_count=$((${rendered_line_count} - ${view_max_line}))
for ((i = 0; i < ${clear_count}; i++)); do
output+=$'\e[2K\n'
done
# cursor move to header
output+=$'\e['"${now_cursor_line}"';'"${header_text_count}"'H'
printf '%s' "${output}" >&2
rendered_line_count=${view_max_line}
}
# @brief:
# escape glob pattern chars for fixed-string matching.
__escape_glob() {
local escaped=${1//\\/\\\\}
escaped=${escaped//\*/\\*}
escaped=${escaped//\?/\\?}
escaped=${escaped//\[/\\[}
escaped=${escaped//\]/\\]}
printf '%s' "${escaped}"
}
# @brief:
# convert input string to lower case.
__to_lower() {
case "${SHELL##*/}" in
bash*) printf '%s' "${1,,}" ;;
zsh*) printf '%s' "${1:l}" ;;
*) printf '%s' "${1}" ;;
esac
}
# @brief:
# clear printed data
__clear_print_data() {
local output
# move cursor
output=$'\e['"${now_cursor_line}"';0H'
output+=$'\e[2K'
for ((i = 0; i < ${rendered_line_count}; i++)); do
output+=$'\e[1B\e[2K'
done
# move cursor
output+=$'\e['"${now_cursor_line}"';0H'
printf '%s' "${output}" >&2
rendered_line_count=0
}
# @brief:
# update view array data.
__update_view_array() {
local line
local line_no
local source_line_no
local source_indices
local prev_view_array_index_data
local lower_search_word
local search_word_lower_array
local search_word_pattern_array
local matched
local word
local idx
local start_index=0
local can_refine_from_prev=0
prev_view_array_index_data=("${view_array_index_data[@]}")
# clear view_array_data
view_array_data=()
view_array_index_data=()
lower_search_word=$(__to_lower "${search_word}")
if [[ -n "${search_word}" ]]; then
case "${SHELL##*/}" in
bash*) IFS=" " read -r -a search_word_lower_array <<<"${lower_search_word}" ;;
zsh*) IFS=" " read -r -A search_word_lower_array <<<"${lower_search_word}" ;;
esac
else
search_word_lower_array=()
fi
for word in "${search_word_lower_array[@]}"; do
[[ -z "${word}" ]] && continue
search_word_pattern_array+=("$(__escape_glob "${word}")")
done
if [[ -n "${prev_search_word}" && -n "${search_word}" && "${search_word}" == "${prev_search_word}"* ]]; then
if [[ ${#search_word_pattern_array[@]} -eq ${#prev_search_word_lower_array[@]} && ${#search_word_pattern_array[@]} -gt 0 ]]; then
can_refine_from_prev=1
for ((idx = 0; idx < ${#prev_search_word_lower_array[@]} - 1; idx++)); do
if [[ "${search_word_lower_array[${idx}]}" != "${prev_search_word_lower_array[${idx}]}" ]]; then
can_refine_from_prev=0
break
fi
done
if [[ ${can_refine_from_prev} -eq 1 ]]; then
idx=$((${#search_word_pattern_array[@]} - 1))
if [[ "${search_word_lower_array[${idx}]}" == "${prev_search_word_lower_array[${idx}]}"* ]]; then
start_index=${idx}
source_indices=("${prev_view_array_index_data[@]}")
else
can_refine_from_prev=0
fi
fi
fi
if [[ ${can_refine_from_prev} -eq 0 ]]; then
source_indices=("${prev_view_array_index_data[@]}")
fi
else
source_indices=("${array_index_data[@]}")
fi
for source_line_no in "${source_indices[@]}"; do
line_no=${source_line_no}
line="${array_data[${line_no}]}"
matched=1
for ((idx = ${start_index}; idx < ${#search_word_pattern_array[@]}; idx++)); do
if [[ "${array_data_lower[${line_no}]}" != *"${search_word_pattern_array[${idx}]}"* ]]; then
matched=0
break
fi
done
if [[ ${matched} -eq 1 ]]; then
view_array_data+=("$((line_no + 1)):${line}")
view_array_index_data+=("${line_no}")
fi
done
prev_search_word=${search_word}
prev_search_word_lower_array=("${search_word_lower_array[@]}")
local IFS=${OLD_IFS}
}
# @brief: update max_line
__update_max_line() {
# set max_line
max_line="${#view_array_data[@]}"
view_max_line=${max_line}
# ターミナルの残り行数を見ていたが、固定にするためコメントアウト
# surplus_line=$((${terminal_lines} - ${now_cursor_line}))
# if [ surplus_line <= (terminal_lines/2) ]
# if [[ ${surplus_line} -le $((${terminal_lines} / 2)) ]];then
# surplus_line=$((${terminal_lines} / 2))
# fi
# 出力行数
if [[ "${use_perf_mode}" == "1" ]]; then
surplus_line=12
else
surplus_line=20
fi
if [[ ${surplus_line} -le ${view_max_line} ]]; then
view_max_line="${surplus_line}"
fi
if [[ $((${terminal_lines} - ${view_max_line})) -le ${now_cursor_line} ]]; then
now_cursor_line=$((${terminal_lines} - ${view_max_line}))
fi
if [[ ${max_line} -le ${scroll_position} ]]; then
scroll_position=$((${max_line} - 1))
if [[ ${scroll_position} -lt 0 ]]; then
scroll_position=0
fi
fi
if [[ ${now_list_line} -ge $((${view_max_line})) ]]; then
now_list_line=$((${view_max_line} - 1))
fi
if [[ ${rendered_line_count} -eq 0 ]]; then
for ((i = 0; i < ${view_max_line}; i++)); do
printf "\n" >&2
done
printf "\e[${now_cursor_line};0H" >&2
fi
}
# @brief: scroll up function
__scroll_up() {
now_list_line=$((${now_list_line} - 1))
if [[ ${now_list_line} -lt 0 ]]; then
now_list_line=0
return
fi
# scroll up
list_range_min=${scroll_position}
if [[ ${now_list_line} -lt ${list_range_min} ]]; then
# if scroll up
scroll_position=$((${scroll_position} - 1))
if [[ ${scroll_position} -lt 0 ]]; then
scroll_position=0
fi
__clear_print_data
__print_data
else
local header_text
local header_text_count
local term_line
local unselect_line
header_text="QUERY: ${search_word} "
header_text_count=${#header_text}
term_line=$((${now_list_line} - ${scroll_position}))
# unselect line
unselect_line="${view_array_data[$((${now_list_line} + 1))]}"
if __selected_check_in "${unselect_line%%:*}"; then
__print_line_position $((${term_line} + 2)) 1 "${view_array_data[$((${now_list_line} + 1))]}"
else
__print_line_position $((${term_line} + 2)) 2 "${view_array_data[$((${now_list_line} + 1))]}"
fi
# select line
__print_line_position $((${term_line} + 1)) 0 "${view_array_data[${now_list_line}]}"
# move cursor
printf "\e[${now_cursor_line};${header_text_count}H" >&2
fi
}
# @brief: scroll down function
__scroll_down() {
now_list_line=$((${now_list_line} + 1))
if [[ ${now_list_line} -gt $((${max_line} - 1)) ]]; then
now_list_line=$((${max_line} - 1))
return
fi
# scroll down
local list_range_max=$((${scroll_position} + ${view_max_line}))
if [[ ${now_list_line} -ge ${list_range_max} ]]; then
# if scroll down
scroll_position=$((${scroll_position} + 1))
__clear_print_data
__print_data
else
local header_text
local header_text_count
local term_line
local unselect_line
header_text="QUERY: ${search_word} "
header_text_count=${#header_text}
term_line=$((${now_list_line} - ${scroll_position}))
unselect_line="${view_array_data[$((${now_list_line} - 1))]}"
# unselect line
if __selected_check_in "${unselect_line%%:*}"; then
__print_line_position ${term_line} 1 "${view_array_data[$((${now_list_line} - 1))]}"
else
__print_line_position ${term_line} 2 "${view_array_data[$((${now_list_line} - 1))]}"
fi
# select line
__print_line_position "$((${term_line} + 1))" 0 "${view_array_data[${now_list_line}]}"
# move cursor
printf "\e[${now_cursor_line};${header_text_count}H" >&2
fi
}
# @brief: trap ctrl + c
__trap_2() {
__clear_print_data
local IFS=${OLD_IFS}
return 1
}
# @brief:
# check if number is included in array
__selected_check_in() {
for e in ${selected_line[@]}; do
if [[ ${e} -eq ${1} ]]; then
return 0
fi
done
return 1
}
# @brief: Add element to selected_line
__selected_add() {
selected_line=(${selected_line[@]} $1)
}
# @brief: Delete element to selected_line
__selected_del() {
local new_selected_line=()
for e in ${selected_line[@]}; do
if [[ ! ${e} -eq ${1} ]]; then
new_selected_line=(${new_selected_line[@]} ${e})
fi
done
selected_line=(${new_selected_line[@]})
}
# @brief:
# sort selected_line numerically with shell builtins.
__selected_sort() {
local sorted=()
local value
local i
local inserted
for value in "${selected_line[@]}"; do
inserted=0
for ((i = 0; i < ${#sorted[@]}; i++)); do
if [[ ${value} -lt ${sorted[${i}]} ]]; then
sorted=("${sorted[@]:0:${i}}" "${value}" "${sorted[@]:${i}}")
inserted=1
break
fi
done
if [[ ${inserted} -eq 0 ]]; then
sorted+=("${value}")
fi
done
selected_line=("${sorted[@]}")
}
## ----------
# main
## ----------
# set trap
trap '__trap_2;trap - 2;return 1;' 2
# check -p option
if [[ "${flg_p}" != "TRUE" ]]; then
printf '\033[?7l'
fi
# get data from stdin or file.
if [ -p /dev/stdin ]; then
data="$(</dev/stdin)"
else
data="$(<$@)"
fi
# data to Array
local IFS=$'\n'
local array_data=(${data})
local array_data_lower=()
local array_index_data=()
local view_array_index_data=()
local IFS=${OLD_IFS}
for i in "${!array_data[@]}"; do
array_index_data+=("${i}")
array_data_lower+=("$(__to_lower "${array_data[${i}]}")")
done
prev_search_word=
prev_search_word_lower_array=()
# get cursor positon
__get_cursor_position
# get terminal size
local terminal_lines=$((${LINES} - 1))
local terminal_columns=$((${COLUMNS} - 1))
# update view_array
__update_view_array
# set max_line & VIEW_max_line
__update_max_line
# set now_list_line, selected_line
now_list_line=0
scroll_position=0
selected_line=()
# first print out
__print_data
# get input key loop
local IFS=$'\n'
while true; do
# get input key
case "${SHELL##*/}" in
bash*) read -rsn1 input </dev/tty ;;
zsh*) read -r -s -k 1 input </dev/tty ;;
esac
case "${input}" in
# hundling Escape(\x1B)
$'\x1B')
case "${SHELL##*/}" in
bash*) read -rsn1 -t 0.1 tmp </dev/tty ;;
zsh*) read -r -s -k 1 -t 0.1 tmp </dev/tty ;;
esac
if [[ "${tmp}" == "[" ]]; then
case "${SHELL##*/}" in
bash*) read -rsn1 -t 0.1 tmp </dev/tty ;;
zsh*) read -r -s -k 1 -t 0.1 tmp </dev/tty ;;
esac
case "${tmp}" in
# up key
"A") __scroll_up ;;
# down key
"B") __scroll_down ;;
esac
fi
# Flush "stdin" with 0.1 sec timeout.
case "${SHELL##*/}" in
bash*) read -r -n 5 -t 0.1 ;;
zsh*) read -r -k 5 -t 0.1 ;;
esac
;;
# Delete(Backspace(\x7F)) key
$'\x7F')
# get search word count
local search_word_count=${#search_word}
# 検索ワードの文字数が0より大きい場合、文字を削除して表示を更新する
if [[ ${search_word_count} -gt 0 ]]; then
local search_word_count=$((${search_word_count} - 1))
local search_word=${search_word:0:${search_word_count}}
__update_view_array
__update_max_line
__print_data
fi
;;
# input Space Key
" ")
search_word=${search_word}${input}
__update_view_array
__update_max_line
__print_data
;;
# input Tab key(\x09)
# Toggle multi select.
$'\x09')
# add selected line
local line="${view_array_data[${now_list_line}]}"
if __selected_check_in "${line%%:*}"; then
__selected_del ${line%%:*}
else
__selected_add ${line%%:*}
fi
__clear_print_data
__update_max_line
__print_data
;;
# input Ctrl + A key
# Selected all view lines.
# input Ctrl + R key
# Toggle grep mode(plane <-> regex).
# $'\cr')
# __clear_print_data
# echo "Ctrl + R"
# break
# ;;
# input Enter key
"" | $'\n')
__clear_print_data
local new_selected_line
if [[ ${#selected_line} -eq 0 ]]; then
local line="${view_array_data[${now_list_line}]}"
selected_line=(${line%%:*})
fi
__selected_sort
new_selected_line=("${selected_line[@]}")
for NO in "${new_selected_line[@]}"; do
printf '%s\n' "${array_data[$((${NO} - 1))]}"
done
break
;;
# other key
*)
search_word=${search_word}${input}
__update_view_array
__update_max_line
__print_data
;;
esac
done
# check -p option
if [[ "${flg_p}" != "TRUE" ]]; then
printf '\033[?7h'
fi
local IFS=${OLD_IFS}
}
# @brief:
# history selector for Ctrl-R.
# Uses shell builtins as much as possible to reduce remote latency.
boco_history_select() {
local current_buffer
local selected
local line
local history_lines=()
case "${SHELL##*/}" in
zsh*) setopt localoptions ksharrays ;;
esac
case "${SHELL##*/}" in
bash*)
local -A seen=()
current_buffer=${READLINE_LINE}
;;
zsh*)
typeset -A seen
current_buffer=${BUFFER}
;;
*)
current_buffer=
;;
esac
while IFS= read -r line; do
[[ -z "${line}" ]] && continue
[[ -n "${seen["${line}"]}" ]] && continue
seen["${line}"]=1
history_lines+=("${line}")
done < <(builtin fc -lnr 1)
if [[ ${#history_lines[@]} -eq 0 ]]; then
return 0
fi
selected=$(printf '%s\n' "${history_lines[@]}" | boco -p -q "${current_buffer}")
case "${SHELL##*/}" in
bash*)
READLINE_LINE=${selected}
READLINE_POINT=${#READLINE_LINE}
;;
zsh*)
BUFFER=${selected}
CURSOR=${#BUFFER}
zle redisplay 2>/dev/null
;;
esac
}