SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
For those using tput, is there a benefit to using that instead of bash color codes?
tput looks up the terminal type in the terminfo database to work out the correct escape sequence for the capability you request. But pretty much every device you will ever find in the wild (see /etc/DIR_COLORS) implements pretty much every ANSI escape sequence. So pretty much everybody seems to have given up bothering with tput.
tput uses the terminfo database to create those escape sequences for you.
But is there any benefit to doing that over the codes? If I'm understanding you and David correctly, this helps in terminals that may use different escape sequences? But if I'm only using bash, would there be any benefit of using one over the other?
Instead of your locals using tput, I feel this looks cleaner (or at least simpler).
Code:
local blue='\e[34m'
local white='\e[97m'
local red='\e[31m'
local green='\e[32m'
local reset='\e[0m'
In case it's coming across wrong, I'm not trying to play devils advocate or anything, I'm genuinely curious Thanks for any insight!
but it will work on this, provided you stick to simple stuff. (No colour, duh, but bright/dark and inverse/normal and cursor movements will work, and it'll mostly be able to ignore recognisable ANSI sequences that it doesn't implement.) https://en.wikipedia.org/wiki/VT100#...0_terminal.jpg
Anyone who remembers these things will cringe inwardly when you don't use tput, not so much because your laziness is a crime against compatibility -- it must be 20 years since that truly mattered -- but more because you young folk are luckier than you'll ever know, not having to deal with this shit.
further edit: Nevertheless, there are small but important differences between 'linux' (console) and 'xterm'. eg, compare a manpage in a console with the same manpage in an xterm. If you were ever crazy enough that you wanted to faithfully recreate that stupid annoying difference using a shell script, you'd want to use tput.
local blue='\e[34m'
local white='\e[97m'
local red='\e[31m'
local green='\e[32m'
local reset='\e[0m'
and
Code:
local blue='\[$(tput setaf 4)\]'
local white='\[$(tput setaf 7)\]'
local red='\[$(tput setaf 1)\]'
local green='\[$(tput setaf 2)\]'
local reset='\[$(tput sgr0)\]'
equally opaque.
BTW, the \[ and \] aren't in my versions due to tput; they are there so that bash will calculate the length of the prompt correctly.
I've run the tput/no tput versions under OSX and apple managed to not make either of them break. I don't know if apple updates terminfo or not.
Thanks David. So, based on your inputs in this thread and your comments in your code for slackrepo, it seems like you've decided to just move to color codes (colour for you folks over the water ) instead of tput (even though it seems you prefer tput)? With the way our systems are currently, do you see any reasons to use tput over color codes other than the possibility of it breaking on old systems that I'll likely never see again in my life? If there are actual benefits that I'll see, I have no problems switching my methods as I don't use them frequently enough to have anything ingrained yet.
Richard, I suppose both are opaque since neither really tells you what's happening, but I guess looking at Gerado's line, there was so much escaping of characters and the line was so much longer than what it would be with color codes that it just seemed messier to me. Since you're just storing them in variables, it doesn't seem as bad, but if you try to use tput inline, to me, it seems to make it harder to read (not that the color codes are easy).
Thanks David. So, based on your inputs in this thread and your comments in your code for slackrepo, it seems like you've decided to just move to color codes (colour for you folks over the water ) instead of tput (even though it seems you prefer tput)? With the way our systems are currently, do you see any reasons to use tput over color codes other than the possibility of it breaking on old systems that I'll likely never see again in my life? If there are actual benefits that I'll see, I have no problems switching my methods as I don't use them frequently enough to have anything ingrained yet.
Richard, I suppose both are opaque since neither really tells you what's happening, but I guess looking at Gerado's line, there was so much escaping of characters and the line was so much longer than what it would be with color codes that it just seemed messier to me. Since you're just storing them in variables, it doesn't seem as bad, but if you try to use tput inline, to me, it seems to make it harder to read (not that the color codes are easy).
Shrugs YMMV, but at least there is a man page for tput that provides a hint on what the commands do versus finding what the magic prompt escape sequences do.
I'm not interested in making people use tput over the raw codes, but don't ask me to maintain any code containing your raw codes 'cause I'll change 'em.
I like that git prompt. I'll have to start using it.
Also, as far as the checkwinsize, by default, it is turned to off on 14.2. So, if you were running into issues, you probably still want it.
Quote:
Originally Posted by Richard Cranium
Shrugs YMMV, but at least there is a man page for tput that provides a hint on what the commands do versus finding what the magic prompt escape sequences do.
I just google "bash color codes" and it always brings me to this page, so that has made formatting pretty easy.
Quote:
Originally Posted by Richard Cranium
I'm not interested in making people use tput over the raw codes, but don't ask me to maintain any code containing your raw codes 'cause I'll change 'em.
Haha, no worries there. I wasn't trying to get you to change it or anything, just wondering what your rationale for using it was. There's certain things that get ingrained that are just a pain to try and change (especially if there's really no tangible benefit for changing). I was just trying to see if there was a benefit for me to change to using tput. Based on the posts here, it seems either way is fine and there is no massive reason for people to change from one to the other except for personal tastes.
Thanks for yours and David's input on this! It's great to learn things like this
don't ask me to maintain any code containing your raw codes 'cause I'll change 'em.
I completely respect that
Sorry for the off-topicness.
On-topic: shockingly, I always symlink .bash_profile to .bashrc, so that I'm never a victim of the deeply broken stupid conspiracy of inconsistentness between login, openssh, bash, su, chroot, etc. Why fanny about when you can just hit the whole lot with a cluehammer?
further edit: Nevertheless, there are small but important differences between 'linux' (console) and 'xterm'. eg, compare a manpage in a console with the same manpage in an xterm. If you were ever crazy enough that you wanted to faithfully recreate that stupid annoying difference using a shell script, you'd want to use tput.
I've always preferred the way man-pages look on the console and have configured my xterm such as to duplicate the effect. I can actually ctrl-alt-f1/f7 and not notice a difference between the console and a fullscreen xterm (both are using the same sized terminus font and cga colour palate). One big difference is that an xterm with bitmapped fonts supports DEC_DHL which unfortunately the console doesn't which is a shame as I could make good use of that in my scripts/programs (unfortunately there is no terminfo entry for this capability either, so its availability is impossible to test for at runtime).
Where available I use tput rather than raw escape codes because I also date back to the days when you never knew which terminal type you would be running on. Hell, even those that had colours couldn't even agree whether colour 1 was red or blue.
Anyway, back on topic...
I use a ~/.bashrc and have ~/.bash_profile source it. IMO it's the cleanest approach.
The bash invocation configs are just an option that you can use, or not use, to best suit your own needs.
What needs do you have that are not met by the basic system?
tks astrogeek. When I mentioned "improve" I meant maybe to make it better than it already is. the system is ok for me. I just tried to get some information about the advantages of having a .bashrc that is it
Last edited by cezarrangel; 07-25-2016 at 09:13 PM.
you may want to read man bash, look for invocation. It will explain how it is used. Also you may google for typical usage and ideas about it
tks pan64 for suggesting the use of google and also reading man bash. I just tried to get some information besides the use of google and the read of man.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.