3

I prefer to set tabs 4 however this may have some side effects, such as for example ls out put may look not properly aligned. How might I configure the terminal / cat to use four spaces for tabs for cat only?

Should I just alias / wrap cat to something that sets tabs 4, runs /bin/cat, then sets it back? My thinking is that this route is less preferable since in fact I would like this behaviour for less, diff, and other utilities.

4

The curses program tabs will allow you to change what the terminal believes to be the width of a ^I. This would make a simple script

tabs -4
cat "$@"
tabs -8

However, the processing of tab characters on terminals is notoriously wonky and I'm of the impression that you should never mess with them. I suggest using expand as in:

expand -4 "$@"

which is actually closer to what you intend.


added in reply to comment:

Far too many scripts count on cat meaning /bin/cat which explicitly does not change tabs. I'm not sure if you mean to replace or supersede /bin/cat, but you shouldn't. Better would be:

alias tcat='expand -4'

or

function tcat() {
    expand -4 "$@"
}

or similar.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.