Browse code

fzy-tmux: Use named pipe for conveying exit code

On a couple of occasions I've seen the following error being reported by
the fzy-tmux script:
> head: cannot open '/tmp/tmp.qUbDwrPLxQ/ret' for reading: No such file or directory
> /usr/bin/fzy-tmux: line 41: exit: : numeric argument required

The issue seems to be that PATH_FIFO_RET is not yet created but we
already try to read from it, causing the read to fail. With this change
we use a named pipe which we create before the actual tmux invocation,
preventing this case from happening.

Credit for the fix goes to @zsugabubus.

Closes: #143

Daniel Mueller authored on 07/07/2020 01:17:29
Showing 1 changed files
... ...
@@ -23,7 +23,7 @@ main() {
23 23
         fatal "Unable to create a temporary directory"
24 24
     fi
25 25
 
26
-    mkfifo "${PATH_FIFO_IN}" "${PATH_FIFO_OUT}"
26
+    mkfifo "${PATH_FIFO_IN}" "${PATH_FIFO_OUT}" "${PATH_FIFO_RET}"
27 27
 
28 28
     export TMUX=$(_echo "${TMUX}" | cut -d , -f 1,2)
29 29
     eval "tmux \
Browse code

Implement support scripts for `tmux` and `dvtm`

This script adds two scripts that allows spawning a new window/pane in
`tmux` and `dvtm` in which `fzy` will be called.

Options data on the standard input are passed seamlessly, e.g.

$ find -type f | fzy-tmux
$ ag -g '' | fzy-dvtm -l $(tput lines)

Frank LENORMAND authored on 08/02/2017 06:34:18
Showing 1 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,44 @@
1
+#!/bin/sh
2
+
3
+_echo() {
4
+    printf %s\\n "$*"
5
+}
6
+
7
+fatal() {
8
+    _echo "$*" >&2
9
+    exit 1
10
+}
11
+
12
+main() {
13
+    if [ -z "${TMUX}" ]; then
14
+        fatal "No TMUX variable detected in the environment"
15
+    fi
16
+
17
+    readonly PATH_DIR_TMP=$(mktemp -d)
18
+    readonly PATH_FIFO_IN="${PATH_DIR_TMP}/in"
19
+    readonly PATH_FIFO_OUT="${PATH_DIR_TMP}/out"
20
+    readonly PATH_FIFO_RET="${PATH_DIR_TMP}/ret"
21
+
22
+    if [ -z "${PATH_DIR_TMP}" ]; then
23
+        fatal "Unable to create a temporary directory"
24
+    fi
25
+
26
+    mkfifo "${PATH_FIFO_IN}" "${PATH_FIFO_OUT}"
27
+
28
+    export TMUX=$(_echo "${TMUX}" | cut -d , -f 1,2)
29
+    eval "tmux \
30
+        set-window-option synchronize-panes off \\; \
31
+        set-window-option remain-on-exit off \\; \
32
+        split-window \"fzy $* < '${PATH_FIFO_IN}' > '${PATH_FIFO_OUT}' 2>&1; echo $? > '${PATH_FIFO_RET}'\""
33
+
34
+    cat <&0 > "${PATH_FIFO_IN}" &
35
+    cat < "${PATH_FIFO_OUT}"
36
+
37
+    readonly CODE_RET=$(head -n 1 "${PATH_FIFO_RET}")
38
+
39
+    rm -rf "${PATH_DIR_TMP}"
40
+
41
+    exit "${CODE_RET}"
42
+}
43
+
44
+main "$@"