Topic: https://brettterpstra.com/2015/02/20/shell-trick-printf-rules/
hide preview

What's next? verify your email address for reply notifications!

Nate Cavanaugh 10y, 1d ago

Thanks for posting this, I really dig the "right" command. One thing to note, though that I've found is that it seems as though bash (might be others) is caching the $(tput cols) call to just that once.
This falls apart when you resize the window. Instead, you can move it into a function, like so:


function right {
printf '%*s' $(tput cols) "$@"
}

I hope that helps anyone else who runs into the same issue :)

hide preview

What's next? verify your email address for reply notifications!

Shane 10y, 26d ago

For zsh users the printf builtin does not have -v, but you can use the alternative

_hr=$(printf "%*s" $(tput cols)) && echo ${_hr// /${1--}}

Thanks for sharing your ideas Brett,
Shane

hide preview

What's next? verify your email address for reply notifications!