LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 07-22-2016, 09:41 AM   #16
55020
Senior Member
 
Registered: Sep 2009
Location: Yorks. W.R. 167397
Distribution: Slackware
Posts: 1,307
Blog Entries: 4

Rep: Reputation: Disabled

Quote:
Originally Posted by bassmadrigal View Post
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.
 
1 members found this post helpful.
Old 07-22-2016, 12:03 PM   #17
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
tput uses the terminfo database to create those escape sequences for you.
 
Old 07-22-2016, 12:25 PM   #18
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
Quote:
Originally Posted by Richard Cranium View Post
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!
 
Old 07-22-2016, 02:37 PM   #19
55020
Senior Member
 
Registered: Sep 2009
Location: Yorks. W.R. 167397
Distribution: Slackware
Posts: 1,307
Blog Entries: 4

Rep: Reputation: Disabled
Sure, that's simpler, cleaner and easier to understand.

But if you fall into a time machine and arrive at the early 1980s, it won't work on this
https://en.wikipedia.org/wiki/ADM-3A...Adm3aimage.jpg

and it won't work on this
https://en.wikipedia.org/wiki/TeleVi...25Terminal.jpg

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.

edit: by the way, here's some of my actual code.
https://github.com/idlemoor/slackrep...ctions.sh#L362

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.

Last edited by 55020; 07-22-2016 at 03:03 PM.
 
3 members found this post helpful.
Old 07-22-2016, 04:19 PM   #20
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
Maybe it's just me, but I find
Code:
    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.
 
1 members found this post helpful.
Old 07-22-2016, 05:17 PM   #21
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
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).

Because
Code:
PS1="\\[$(tput setaf 1)\\]\\u@\\h:\\w # \\[$(tput sgr0)\\]"
is the same as
Code:
PS1='\e[31m\u@\h:\w\ $ \e[0m'
 
Old 07-22-2016, 06:51 PM   #22
mralk3
Slackware Contributor
 
Registered: May 2015
Distribution: Slackware
Posts: 1,900

Rep: Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050
Here is my .bashrc. I haven't changed it for quite a while. Not fancy like the rest of ya, KISS.

Code:
# Show git branch
# Auto-complete git commands
source /usr/share/doc/git-2.9.0/contrib/completion/git-prompt.sh
source /usr/share/doc/git-2.9.0/contrib/completion/git-completion.bash

export PATH="$PATH:/usr/sbin:/sbin:$HOME/bin:$HOME/.rvm/bin"

# Git prompt
PS1='[\u@\h \w$(__git_ps1 " (%s)")]\$ '

# Fix terminal window resizes (still necessary?)
shopt -s checkwinsize

export EDITOR=vim
export VISUAL=vim
export MAKEFLAGS=${MAKEFLAGS:--j8}

# Needed for chromium to work
# with privoxy proxy
export http_proxy="http://127.0.0.1:8118"
export https_proxy="https://127.0.0.1:8118"
export HTTP_PROXY=$http_proxy
export HTTPS_PROXY=$https_proxy
 
1 members found this post helpful.
Old 07-22-2016, 09:50 PM   #23
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: McKinney, Texas
Distribution: Slackware64 15.0
Posts: 3,858

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
Quote:
Originally Posted by bassmadrigal View Post
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).

Because
Code:
PS1="\\[$(tput setaf 1)\\]\\u@\\h:\\w # \\[$(tput sgr0)\\]"
is the same as
Code:
PS1='\e[31m\u@\h:\w\ $ \e[0m'

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.
 
2 members found this post helpful.
Old 07-22-2016, 11:49 PM   #24
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
Quote:
Originally Posted by mralk3 View Post
Here is my .bashrc. I haven't changed it for quite a while. Not fancy like the rest of ya, KISS.

Code:
# Show git branch
# Auto-complete git commands
source /usr/share/doc/git-2.9.0/contrib/completion/git-prompt.sh
source /usr/share/doc/git-2.9.0/contrib/completion/git-completion.bash

--snip--

# Git prompt
PS1='[\u@\h \w$(__git_ps1 " (%s)")]\$ '

# Fix terminal window resizes (still necessary?)
shopt -s checkwinsize

--snip--
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 View Post
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 View Post
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
 
1 members found this post helpful.
Old 07-23-2016, 04:43 AM   #25
55020
Senior Member
 
Registered: Sep 2009
Location: Yorks. W.R. 167397
Distribution: Slackware
Posts: 1,307
Blog Entries: 4

Rep: Reputation: Disabled
Quote:
Originally Posted by bassmadrigal View Post
I just google "bash color codes"
I just google "ansi escape sequences" and I usually end up at https://en.wikipedia.org/wiki/ANSI_escape_code

Quote:
Originally Posted by Richard Cranium View Post
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?
 
Old 07-23-2016, 04:55 AM   #26
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018
Quote:
Originally Posted by 55020 View Post
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.

Last edited by GazL; 12-02-2017 at 12:38 PM.
 
1 members found this post helpful.
Old 07-23-2016, 05:08 AM   #27
Reedych
Member
 
Registered: Jul 2016
Location: Earth
Distribution: Slackware64 14.2
Posts: 37

Rep: Reputation: Disabled
http://bashrcgenerator.com can make your own PS1 like this, but it's not very functional

Last edited by Reedych; 07-23-2016 at 05:10 AM.
 
Old 07-25-2016, 08:57 PM   #28
cezarrangel
Member
 
Registered: Dec 2011
Posts: 77

Original Poster
Rep: Reputation: Disabled
duplicate post

Last edited by cezarrangel; 07-25-2016 at 09:11 PM. Reason: duplicate post
 
Old 07-25-2016, 08:58 PM   #29
cezarrangel
Member
 
Registered: Dec 2011
Posts: 77

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
Define "improve".

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.
 
Old 07-25-2016, 09:16 PM   #30
cezarrangel
Member
 
Registered: Dec 2011
Posts: 77

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bashrc file LinuxUser101 Linux - Newbie 4 04-14-2008 07:55 PM
Bashrc file Gins Linux - General 19 09-06-2005 03:19 PM
can't the file bashrc Paxmaster Linux - Software 10 01-02-2005 06:58 AM
where is the .bashrc file??? xenia Linux - Newbie 8 05-08-2004 12:11 PM
bashrc file Linvilidiot Linux - Newbie 3 03-11-2004 04:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 12:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration