others/termgeometry.sh

31 lines
999 B
Bash
Executable File

#!/bin/sh
## This script is useful only for terminals that adjust their size in relation to the size of the text and that define their geometry in columns and rows ##
# termgeometry.sh by @root_informatica.
## usage ##
# 1- Open a terminal, adjust its size however you want.
# 2- Run the script and it will center it and output its geometry to stdout
FW=$(pfw) # focused window
RW=$(wattr w $(lsw -r)) # root width
RH=$(wattr h $(lsw -r)) # root height
FWW=$(wattr w $FW) # focused window width
FWH=$(wattr h $FW) # focused window height
CENTERX=$(((RW - FWW) / 2)) # center xcalcuate
CENTERY=$(((RH - FWH) / 2)) # center y calculate
wtp $CENTERX $CENTERY $FWW $FWH $FW # center the window
columns=$(tput cols) # terminal columns
rows=$(tput lines) # terminal rows
xoff=$(wattr x $FW) # terminal xoff
yoff=$(wattr y $FW) # terminal yoff
# print the output
printf "
-g ${columns}x${rows}+${xoff}+${yoff}
"