Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Arranging Terminal windows' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Arranging Terminal windows
Authored by: ubi on Nov 05, '03 12:13:51PM

You wrote: "Now if I could only get Terminal windows to arrange themselves more intelligently..."

I have a possible solution. Terminal.app supports Xterm escape sequences. Using these, I've written the following little C program (the pretty indenting of which the MacOSXHints formatter will now garble--sorry--but it's C so it will *still* compile :-] ):

/* --------------------- Begin xgeom.c ----------------------------- */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

main(int argc, char **argv)
{
int h=24, w=80, x=0, y=0;
if(argc>1)
{
if(argv[1][0]=='-')
{
printf("Usage: %s h [w [x [y]]]\n", argv[0]);
exit(1);
}
h = atoi(argv[1]);
if(argc>2)
{
w = atoi(argv[2]);
if(argc>3)
{
x = atoi(argv[3]);
if(argc>4)
{
y = atoi(argv[4]);
}
printf(";%dt", x, y);
}
}
printf(";%dt", h, w);
}
}
/* --------------------- End xgeom.c ----------------------------- */

Then I define the following (bash-style) aliases:

alias b='xgeom 23 166 1 352'
alias bl='xgeom 23 81 1 352'
alias br='xgeom 23 81 513 352'
alias f='xgeom 52 166 1 1'
alias l='xgeom 52 81 1 1'
alias r='xgeom 52 81 513 1'
alias t='xgeom 23 166 1 1'
alias tl='xgeom 23 81 1 1'
alias tr='xgeom 23 81 513 1'

for bottom, bottom-left, bottom-right, full-screen, left, etc. Now, when I want the terminal window I'm currently in to use the top-left quarter of the screen, I just type "tl" (and the return key of course) and it resizes and repositions itself there. These aliases are set for my 12" PowerBook (1024x768 pixels). You'll need to change them if your screen is different or you use a different font than I do (Monaco Regular 10-point), or a different-height Dock. But it's easy to experiment with xgeom.

Hope this helps.



[ Reply to This | # ]
Arranging Terminal windows
Authored by: stift on Nov 05, '03 12:32:32PM

how do i compile this ?



[ Reply to This | # ]
Compiling xgeom [Arranging Terminal windows]
Authored by: ubi on Nov 05, '03 01:24:27PM

Use gcc to compile. I believe it's on the Panther Developer Tools CD.

gcc -o xgeom xgeom.c

Then put xgeom somewhere in your shell's PATH.



[ Reply to This | # ]
Correction: Arranging Terminal windows
Authored by: ubi on Nov 05, '03 01:13:47PM

Just noticed that my C source didn't copy the escape sequences correctly. The two printf() calls should read as follows:

printf("^[[3;%d;%dt", x, y);
printf("^[[8;%d;%dt", h, w);

where ^[ represents a literal escape. You can enter this in vi by typing Control-V, then hitting the escape key. (Not sure how to do it in emacs.)



[ Reply to This | # ]
Arranging Terminal windows
Authored by: jaysoffian on Nov 05, '03 11:40:14PM
Hmm, gratuitous use of C if you ask me :-)
How about the following sh one-liner for xgeom?

#!/bin/sh
printf '^[[8;%d;%dt^[[3;%d;%dt' $@

You could also define this as shell function in the same place you're setting up your bash aliases.

---
j.


[ Reply to This | # ]

One-liner [Arranging Terminal windows]
Authored by: ubi on Nov 06, '03 12:29:23AM

Thanks for the tip. I never knew about printf as a sh/bash command. Cool. The only thing my C code does better is handle a variable number of arguments. Here's the suggested bash function:

function xgeom { printf '^[[8;%d;%dt^[[3;%d;%dt' $@ ; }



[ Reply to This | # ]
One-liner [Arranging Terminal windows]
Authored by: kmue on Nov 06, '03 04:22:13AM
Nice! Its easier to cut 'n pasta if you use escape codes:

xgeom() { printf '\033[\033[8;%d;%dt\033[\033[3;%d;%dt' $@; }


[ Reply to This | # ]
Code garbling
Authored by: ssevenup on Nov 06, '03 02:34:19PM

The forums will protect your code format if you do this...

To protect special characters such as \, <, and >, please use the [code] and [/code] tags around any XML, UNIX code, AppleScripts, or other code fragments in your submission! Yes, those are square brackets, and remember to set the post mode to 'HTML formatted,' too.

It's displayed along with the Post a Comment window here as I post this.

---
Mark Moorcroft
ELORET Corp. - NASA/Ames RC
Sys. Admin.



[ Reply to This | # ]