-
Notifications
You must be signed in to change notification settings - Fork 0
/
epeco-async
executable file
·83 lines (69 loc) · 2.02 KB
/
epeco-async
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
#!/bin/bash
# -*- mode: sh; coding: utf-8-unix -*-
command_name=$(basename "$0")
function usage_exit() {
cat << EOF >&2
Usage: $command_name [-q query] [file]
$command_name -h
EOF
exit $1
}
query=""
while getopts :hq: opt; do
case $opt in
h)
usage_exit 0
;;
q)
query=$OPTARG
;;
\?)
usage_exit 2
;;
esac
done
shift $((OPTIND - 1))
if [ $# -ne 0 ] && [ $# -ne 1 ]; then
usage_exit 2
fi
function message() {
echo "$command_name: $1" >&2
exit 1
}
if [ $# -eq 1 ] && [ ! -r "$1" ]; then
message '指定したファイルを読み込むことができません'
fi
temp1=$(mktemp -t "$command_name.XXXXXXXXXX")
temp2=$(mktemp -t "$command_name.XXXXXXXXXX")
trap 'rm -f "$temp1" "$temp2"' 0
epeco=$(cat << EOF
(progn
(helm :sources (helm-build-async-source "Epeco"
:candidates-process (lambda ()
(start-process-shell-command "epeco" nil
"tail --pid=$$ -n +1 -f $temp1"))
:candidate-transformer (lambda (candidates)
(cl-loop for c in candidates
when (helm-mm-match c) collect c))
:candidate-number-limit 10000
:action (helm-make-actions
"Output" (lambda (candidate)
(with-temp-buffer
(dolist (cand (helm-marked-candidates))
(insert (format "%s\n" cand)))
(write-region nil nil "$temp2" nil 'nomsg)))))
:input "$query"
:buffer "*helm epeco*")
t)
EOF
)
if [ $# -eq 0 ]; then
cat
else
cat "$1"
fi | cat > "$temp1" & # この行の cat は必要!
emacsclient -e "$epeco" > /dev/null
cat "$temp2"
exec 2> /dev/null
kill $!
exit 0