]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/zsh-navigation-tools/znt-usetty-wrapper
initial
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / zsh-navigation-tools / znt-usetty-wrapper
1 emulate -L zsh
2
3 zmodload zsh/curses
4
5 test_fd0() {
6     true <&0
7 }
8
9 local restore=0 FD
10
11 # Reattach to terminal
12 if [ ! -t 0 ]; then
13     # Check if can reattach to terminal in any way
14     if [[ ! -c /dev/tty && ! -t 2 ]]; then
15         echo "No terminal available (no /dev/tty and no terminal at stderr)"
16         return 1
17     fi
18
19     if test_fd0 2>/dev/null; then
20         exec {FD}<&0
21         restore=2
22     else
23         restore=1
24     fi
25
26     if [[ ! -c /dev/tty ]]; then
27         exec <&2
28     else
29         exec </dev/tty
30     fi
31 fi
32
33 # Run the command
34 "$@"
35
36 # Restore FD state
37 (( restore == 1 )) && exec <&-
38 (( restore == 2 )) && exec <&$FD && exec {FD}<&-
39
40 # vim: set filetype=zsh: