summaryrefslogtreecommitdiffstats
path: root/tux
blob: b19d1261ee483a6fb908f26bb83291870bd1d168 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/zsh

: ${(AA)muxaliases:=${(z)MUXAL}}
: ${(AA)appMap:=${(z)WSETS}}

arg="$1"
if [[ $arg == "tnum" ]];then
        shift
        app="$1"
        session=${appMap[$app]:-uake}

        setopt nonomatch
        if ! tmux list-windows -t $session | /bin/grep -i $app | grep -v grep &>/dev/null;then
            lastone=$(( $(tmux list-windows -t $session | tail -1 | awk -F: '{ print $1 }') + 1 ))
            #PATH="/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/home/raghavendra/bin:/home/raghavendra/bin/libexec"
            PATH="/home/raghavendra/bin/libexec:/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/home/raghavendra/bin"
            if [[ ! -f =$app ]];then
                tmux new-window -d -t $session:$lastone =$muxaliases[$app]
            else
                tmux new-window -d -t $session:$lastone =$app
            fi
            if setopt | /bin/grep interactive | /bin/grep -q grep;then
                tmux join-pane -s $session:$lastone -p 80
            fi
            exit 2
        fi

        winum=$(tmux list-windows -t $session | /bin/grep -i $app | head -1)

        if [[ -z $winum ]];then
            exit 1
        fi

        winum=${winum%:*}

        echo -n $winum 

elif [[ $arg == "tfind" ]];then
        shift
        app=${1:?param}


        winum=$(tmux list-windows | agrep -1  "$app" | head -1)
        winum=${winum%:*}

        tmux select-window -t $winum


elif [[ $arg == "takeme" ]];then
        shift
        app=$1
        for sess in $(tmux list-sessions |awk -F: '{print $1}')
        do
            window=$(tmux list-windows -t $sess | /bin/grep -m 1 -i $app | /bin/grep -v grep | awk -F: '{ print $1 }')
            if [[ -n $window ]];then
                tmux select-window -t $sess:$window
                #echo $sess:$window > /tmp/.tmux-take
                echo -n $sess
                exit
            fi
        done
        exit 1

elif [[ $arg == "tnext" ]];then
       shift
       while :;do
           tmux next-window 
           app=$(tmux display-message -p '#W')
           [[ $app == "zsh" ]] && break
       done
elif [[ $arg == "tprev" ]];then
       shift
       while :;do
           tmux previous-window
           app=$(tmux display-message -p '#W')
           [[ $app == "zsh" ]] && break
       done

elif [[ $arg == "killall" ]];then
    shift
    #vimote down
    killall -w weechat-curses w3m mutt firefox-beta firefox firefox-bin firefox-beta-bin newsbeuter ncmpcpp atop rtorrent 
    #echo "Sure ?"
   #[[ -n $1 ]] || read
    #tmux kill-server
elif [[ $arg == "tbreak" ]];then
        shift
        app=$(tmux display-message -p '#W')


        if [[ -z $app || -z  $appMap[$app] ]];then
            tmux break-pane -d 
            exit
        fi

        if [[ $app == vim ]];then
            vimote :wa 
        fi

        sum1=$(tmux list-windows |  awk -F: '{total+=$1} END {print total}')
        tmux break-pane -d
        sum2=$(tmux list-windows |  awk -F: '{total+=$1} END {print total}')
        window=$(( sum2-sum1 ))
        tmux move-window -d  -s $window -t $appMap[$app]
fi