summaryrefslogtreecommitdiffstats
path: root/vimote
blob: 1c86be1ec03c1623599428407fe7bfc2b6c06290 (plain)
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
#!/bin/zsh
#set -x

session="uake"
session_file="$HOME/.vim-tmp/vimote-session"

if ! pgrep -x vim &>/dev/null;then 
    lastone=$(( $(tmux list-windows -t $session | tail -1 | awk -F: '{ print $1 }') + 1 ))
    tmux new-window -d -t $session:$lastone "/usr/bin/vim -S $session_file"
    tmux join-pane -s $session:$lastone -p 80
    exit
else
    winum=$(~/bin/tux tnum vim)
fi

if [[ $? != 0 ]];then 
	print "Failed"
        return
fi
#set +x

command=${1:-tabnew}


if [[ $command == down ]];then
    if pidof vim;then
        keys=":mksession! ~/.vim-tmp/vimote-session" 
        tmux send-keys -t $session:$winum 'Escape' $keys 'Enter' 'Escape' ':wqa' 'Enter'
    fi
    exit
fi

keys=""
shift


# Non join commands here
if ! (( $# ));then
    keys="$command"
    tmux send-keys -t $session:$winum 'Escape' $keys 'Enter' 
    #tmux send-keys -t $session:$winum 'Escape' 'Enter'
    exit
fi

for f in [email protected];do
    if [[ -f  ~/.vim-tmp/${f:t}.swp ]];then
        keys=":TabX $f"
    else
        if [[ "$f" == /* ]];then
            prefix=
        else
            prefix="$(pwd)/"
        fi
        f="${prefix}$f"
        if [[ $command == tabnew ]];then
            keys=":tabnew $f"
        elif [[ $command == edit ]];then
            keys=":edit $f"
        fi
    fi
    tmux send-keys -t $session:$winum 'Escape' $keys 'Enter'
done

# Wrong -- dont do it here
tmux join-pane -s $session:$winum -p 75 

#set +x