Skip to content

Instantly share code, notes, and snippets.

@sunya9

sunya9/config

Last active Apr 13, 2020
Embed
What would you like to do?
i3wmで同じワークスペースを選択したときにウィンドウを切り替えていく
# .config/i3/config 例
bindsym $mod+1 exec ~/.config/i3/cycle_windows.sh $ws1
bindsym $mod+Shift+1 exec ~/.config/i3/cycle_windows.sh $ws1 reverse
bindsym $mod+2 exec ~/.config/i3/cycle_windows.sh $ws2
bindsym $mod+Shift+2 exec ~/.config/i3/cycle_windows.sh $ws2 reverse
bindsym $mod+3 exec ~/.config/i3/cycle_windows.sh $ws3
bindsym $mod+Shift+3 exec ~/.config/i3/cycle_windows.sh $ws3 reverse
bindsym $mod+4 exec ~/.config/i3/cycle_windows.sh $ws4
bindsym $mod+Shift+4 exec ~/.config/i3/cycle_windows.sh $ws4 reverse
bindsym $mod+5 exec ~/.config/i3/cycle_windows.sh $ws5
bindsym $mod+Shift+5 exec ~/.config/i3/cycle_windows.sh $ws5 reverse
bindsym $mod+6 exec ~/.config/i3/cycle_windows.sh $ws6
bindsym $mod+Shift+6 exec ~/.config/i3/cycle_windows.sh $ws6 reverse
bindsym $mod+7 exec ~/.config/i3/cycle_windows.sh $ws7
bindsym $mod+Shift+7 exec ~/.config/i3/cycle_windows.sh $ws7 reverse
bindsym $mod+8 exec ~/.config/i3/cycle_windows.sh $ws8
bindsym $mod+Shift+8 exec ~/.config/i3/cycle_windows.sh $ws8 reverse
bindsym $mod+9 exec ~/.config/i3/cycle_windows.sh $ws9
bindsym $mod+Shift+9 exec ~/.config/i3/cycle_windows.sh $ws9 reverse
bindsym $mod+0 exec ~/.config/i3/cycle_windows.sh $ws10
bindsym $mod+Shift+0 exec ~/.config/i3/cycle_windows.sh $ws10 reverse
#!/bin/sh
workspace_name=$1
current_workspace_name=$(i3-msg -t get_workspaces | jq -r '.[] | select(.focused == true) | .name')
if [ -z $2 ]; then
grep_op=A
fallback_command=head
else
grep_op=B
fallback_command=tail
fi
if [ $workspace_name = $current_workspace_name ]; then
current_window_id=$(xdotool getactivewindow)
window_ids=$(i3-msg -t get_tree | jq -r "recurse(.nodes[]) | select(.type == \"workspace\" and .name == \"$workspace_name\") | recurse(.nodes[]) | select(.type == \"con\" and .nodes == []) | .window")
next_window_id=$(echo "$window_ids" | grep -$(echo $grep_op)1 "$current_window_id" | grep -v "$current_window_id")
if [ -z $next_window_id ]; then
next_window_id=$(echo "$window_ids" | $fallback_command -n1)
fi
i3-msg "[id=$next_window_id] focus"
else
i3-msg workspace $workspace_name
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment