Trapping window resize in zsh

|

I just learned that zsh can catch window resizes by defining a function named TRAPWINCH. Actually, zsh can trap any signal by defining TRAPSIGNAL-NAME. Anyhow, I use this to set my right prompt. Before I learned this, I set my right prompt to:

RPS1="%30<..<%~%<<"

This would print the current directory on the right, truncating to 30 characters. This works great for 80 column windows, but for larger windows, it's not using the window size efficiently. So, now I can trap the window resize and change the right prompt based on the number of columns. Here's a snippet from my .zshrc.

# Set right side prompt to last current directory, using 3/8 the width
set_rps1()
{
    (( cols = $COLUMNS * 3/8))
    RPS1="%${cols}<..<%~%<<"
}
set_rps1

# Reset right prompt, on window resize
TRAPWINCH ()
{
    set_rps1
}
blog comments powered by Disqus

About this Entry

This page contains a single entry by Dave published on January 25, 2004 9:47 PM.

Deleting spam was the previous entry in this blog.

"I lowered my cholesterol" is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Links

Powered by Movable Type 4.1