Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # Author: Twily 2015
- # Description: Cut window in half and spawn a terminal in its remaining space
- # Requires: wmctrl, xdotool, xwininfo, urxvt
- # Useage: $ sh ./split.grid
- # (Eg.: Bind script to trigger on hotkey W-s)
- #
- ACT=$(xdotool getactivewindow)
- G=24 # Gap between windows
- D=0 # Decoration height
- M=0 # Border width
- let M=$M*2
- if [ "$D" -gt "0" ]; then D=$(( $D + ( $M / 2 ) )); fi
- unset X Y W H
- eval $(xwininfo -id $ACT |
- sed -n -e "s/^ \+Absolute upper-left X: \+\([0-9]\+\).*/X=\1/p" \
- -e "s/^ \+Absolute upper-left Y: \+\([0-9]\+\).*/Y=\1/p" \
- -e "s/^ \+Width: \+\([0-9]\+\).*/W=\1/p" \
- -e "s/^ \+Height: \+\([0-9]\+\).*/H=\1/p" )
- X=$(( $X - ( $M / 2 ) ))
- Y=$(( $Y - ( $M / 2 ) - $D ))
- if [ "$W" -gt "$H" ]; then
- # Spawn right
- aW=$(( $W / 2 - ( $G / 2 ) - $M ))
- wmctrl -i -r $ACT -e 0,$X,$Y,$aW,$H
- X=$(( $X + $aW + $G + $M ))
- W=$(( $W - $aW - $G - $M ))
- else
- # Spawn below
- aH=$(( $H / 2 - ( $G / 2 ) - ( $M / 2 ) - $D ))
- wmctrl -i -r $ACT -e 0,$X,$Y,$W,$aH
- Y=$(( $Y + $aH + $G + $D + $M ))
- H=$(( $H - $aH - $G - $D - $M ))
- fi
- urxvt -g "1x1+"$X"+"$Y &
- for i in {0..49}; do # timeout
- if ps -p $! >/dev/null; then
- sleep .1
- wmctrl -r :ACTIVE: -e 0,$X,$Y,$W,$H
- break
- fi
- done
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement