aboutsummaryrefslogtreecommitdiff
path: root/ratpoison/window_menu
blob: 60f9af7fc158620a24ed2f5759d1c4b0d5dd3a4f (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
#!/usr/bin/env bash

# Lets you switch between all windows in a way that minimizes keystrokes.

# Two ways to order:
#   - If order=last, the windows are listed in the order that you last visited them in.
#   - If order=sequential, the windows are listed in number order.
order=sequential

# Yes, bash is really necessary, because it's version of printf makes this
# script possible.  Regular bourne shell printf does NOT.

window_index_str=$(ratpoison -c "info" | sed 's/^.*\([0-9]\)(.*$/\1/')
if [ "$window_index_str" = "No window." ]; then
    group_index=$($HOME/.ratpoison/workspace current)
    ratmenu -style dreary -fg "#657b83" -bg "#eee8d5" "No windows in group $group_index" 
/bin/true
else
    ratpoison -c "echo $window_index_str"
    echo "$window_index_str">/tmp/log
    window_index=$[ $window_index_str + 1 ]
    if [ $order = sequential ]; then
        ( printf "ratmenu -style dreary -fg '#657b83' -bg '#eee8d5' -io $window_index \
          \"Select a Window\" /bin/true";
          ratpoison -c "windows %n %n %t" | sort -n | while read w x z; do
            a=$(printf "%3q" $x); b="ratpoison -c \"select $x\"";
            printf " %q\\ %q %q"  "$a" "$z" "$b";
          done; echo \;) | sh
    elif [ $order = last ]; then
        ( printf "ratmenu -style dreary -fg '#657b83' -bg '#eee8d5' -io $window_index \
          \"Select a Window\" /bin/true";
          ratpoison -c "windows %l %n %t" | sort -rn | while read w x z; do
            a=$(printf "%3q" $x); b="ratpoison -c \"select $x\"";
            printf " %q\\ %q %q"  "$a" "$z" "$b";
          done; echo \;) | sh
    fi
fi