fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes AltmanningerDon't print greetings in interactive read in fake-interactive shell3dc36f74b

master
2.5 KiB77 linesraw
1function isolated-tmux-start --wraps fish
2    set -l tmpdir (mktemp -d)
3    cd $tmpdir
4
5    echo 'set -g mode-keys emacs' >.tmux.conf
6
7    function isolated-tmux --inherit-variable tmpdir --wraps tmux
8        # tmux can't handle session sockets in paths that are too long, and macOS has a very long
9        # $TMPDIR, so use a relative path - except macOS doesn't have `realpath --relative-to`...
10        # Luckily, we don't need to call tmux from other directories, so just make sure no one
11        # does by accident.
12        if test $PWD != $tmpdir
13            echo "error: isolated-tmux must always be run from the same directory." >&2
14            return 1
15        end
16        tmux -S .tmux-socket -f .tmux.conf $argv
17    end
18
19    function isolated-tmux-cleanup --on-event fish_exit --inherit-variable tmpdir
20        isolated-tmux kill-server
21        rm -r $tmpdir
22    end
23
24    function tmux-sleep
25        set -q CI && sleep 1
26        or sleep 0.3
27    end
28
29    function sleep-until
30        set -l cmd $argv[1]
31        set -l i 0
32        while [ $i -lt 100 ] && not eval "$cmd" >/dev/null
33            tmux-sleep
34            set i (math $i + 1)
35        end
36        if [ $i -eq 100 ]
37            printf '%s\n' "timeout waiting for $cmd" >&2
38            exit 1
39        end
40    end
41
42    set -l fish (status fish-path)
43    set -l size -x 80 -y 10
44    set -l greeting_file
45    if not test -f $greeting_file
46        printf >$__fish_config_dir/functions/fish_greeting.fish %s \
47            'function fish_greeting; end' 2>/dev/null
48    end
49    isolated-tmux new-session $size -d $fish -C '
50        # This is similar to "tests/interactive.config".
51        function fish_prompt; printf "prompt $status_generation> "; end
52        # No autosuggestion from older history.
53        set fish_history ""
54        # No transient prompt.
55        set fish_transient_prompt 0
56        set -g CDPATH
57    ' $argv
58    # Set the correct permissions for the newly created socket to allow future connections.
59    # This is required at least under WSL or else each invocation will return a permissions error.
60    chmod 777 .tmux-socket
61
62    # Resize window so we can attach to tmux session without changing panel size.
63    isolated-tmux resize-window $size
64
65    if test "$tmux_wait" = false
66        return
67    end
68
69    # Loop a bit, until we get an initial prompt.
70    for i in (seq 50)
71        if test -n "$(isolated-tmux capture-pane -p)"
72            return
73        end
74        sleep .2
75    end
76    echo "error: isolated-tmux-start timed out waiting for non-empty first prompt" >&2
77end