LINUX LITE 7.2 FINAL RELEASED - SEE RELEASE ANNOUNCEMENTS SECTION FOR DETAILS


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SOLVED] Terminal emulator & GRUB coloring
#11
Perhaps we could change some colors
Code:
leafpad $HOME/.bashrc
Them adding this to the end
Code:
if [ $USER = 'root' ]; then
    PS1="\[\033[01;31m\]$USER@$HOSTNAME\[\033[0;00m\] \[\033[01;32m\]\w\\$\[\033[0;00m\] "
else
    PS1="\[\033[01;33m\]$USER@$HOSTNAME\[\033[0;00m\] \[\033[01;32m\]\w\\$\[\033[0;00m\] "
fi
[Image: 3hlDmMC.png]
Perhaps white bold would better match the current theme
Code:
if [ $USER = 'root' ]; then
    #If user is root just print the hostname in yellow
    PS1="\[\033[01;33m\]$HOSTNAME\[\033[0;00m\] \[\033[01;32m\]\w\\$\[\033[0;00m\] "
else
    PS1="\[\033[01;97m\]$USER@$HOSTNAME\[\033[0;00m\] \[\033[01;32m\]\w\\$\[\033[0;00m\] "
fi


Reply
#12
Misko, that is a great idea. Having root as either bold or a different color just makes sense.
Reply
#13
I like that idea too, Misko.
Try Linux Beginner Search Engine for answers to Linux questions.
Reply
#14
Code:
I'm surprised people have not been doing this within their profiles.  I've had my terminal colors and PS1 set for years across distros.


Here is my prompt configuration (compilation of various online resources over time):
##################################################
# Fancy PWD display function
##################################################
# The home directory (HOME) is replaced with a ~
# The last pwdmaxlen characters of the PWD are displayed
# Leading partial directory names are striped off
# /home/me/stuff          -> ~/stuff              if USER=me
# /usr/share/big_dir_name -> ../share/big_dir_name if pwdmaxlen=20
##################################################
bash_prompt_command() {
    # How many characters of the $PWD should be kept
    local pwdmaxlen=25


    # Indicate that there has been dir truncation
    local trunc_symbol=".."
    local dir=${PWD##*/}
    pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen ))


    NEW_PWD=${PWD/#$HOME/\~}
    local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen ))


    if [ ${pwdoffset} -gt "0" ]
    then
        NEW_PWD=${NEW_PWD:$pwdoffset:$pwdmaxlen}
        NEW_PWD=${trunc_symbol}/${NEW_PWD#*/}
    fi
}

bash_prompt() {
    case $TERM in
    xterm*|rxvt*)
        local TITLEBAR='\[\033]0;\u:${NEW_PWD}\007\]'
          ;;
    *)
        local TITLEBAR=""
          ;;
    esac


    local NONE="\[\033[0m\]"    # unsets color to term's fg color


    # regular colors
    local K="\[\033[0;30m\]"    # black
    local R="\[\033[0;31m\]"    # red
    local G="\[\033[0;32m\]"    # green
    local Y="\[\033[0;33m\]"    # yellow
    local B="\[\033[0;34m\]"    # blue
    local M="\[\033[0;35m\]"    # magenta
    local C="\[\033[0;36m\]"    # cyan
    local W="\[\033[0;37m\]"    # white


    # empahsized (bolded) colors
    local EMK="\[\033[1;30m\]"
    local EMR="\[\033[1;31m\]"
    local EMG="\[\033[1;32m\]"
    local EMY="\[\033[1;33m\]"
    local EMB="\[\033[1;34m\]"
    local EMM="\[\033[1;35m\]"
    local EMC="\[\033[1;36m\]"
    local EMW="\[\033[1;37m\]"


    # background colors
    local BGK="\[\033[40m\]"
    local BGR="\[\033[41m\]"
    local BGG="\[\033[42m\]"
    local BGY="\[\033[43m\]"
    local BGB="\[\033[44m\]"
    local BGM="\[\033[45m\]"
    local BGC="\[\033[46m\]"
    local BGW="\[\033[47m\]"


    local UC=$W                # user's color


    [ $UID -eq "0" ] && UC=$R  # root's color


    #PS1="$TITLEBAR ${EMG}[${UC}$(date +%H:%M:%S) ${UC}\u${EMB}@${UC}\h ${EMG}\${NEW_PWD}${EMB}]${UC}\\$ ${NONE}"
    PS1="$TITLEBAR ${G}[${C}\d \t \h ${G}\${NEW_PWD}]${UC}\\$ ${NONE}"


    # without colors: PS1="[\u@\h \${NEW_PWD}]\\$ "


    # extra backslash in front of \$ to make bash colorize the prompt
}


PROMPT_COMMAND=bash_prompt_command


bash_prompt


unset bash_prompt
Reply
#15
Great idea, Misko, especially considering newcomers to Linux would be a bit overwhelmed in having to figure that out.

I have configured it myself. BUT I definitely would prefer it coming out of the box this way.

In addition to this and even more important for me would be to implement that broken links are shown in a different color like this:
[Image: r4cDxiq.png]

The last couple of days I have extensively worked with softlinks and it was a huge hassle with the default setting not showing valid and broken links in different colors.

Thanks, riser, for sharing!
Reply
#16
(05-04-2015, 05:02 AM)Jerry link Wrote: Misko, that is a great idea. Having root as either bold or a different color just makes sense.
It's logical.
(05-04-2015, 05:18 PM)gold_finger link Wrote: I like that idea too, Misko.
I think it would be helpfull. Some other distros use this by default.
(05-04-2015, 08:17 PM)riser link Wrote: I'm surprised people have not been doing this within their profiles.  I've had my terminal colors and PS1 set for years across distros.
Here is my prompt configuration (compilation of various online resources over time):
Thanks for sharing riser. +
(05-04-2015, 10:08 PM)LL-user link Wrote: Great idea, Misko, especially considering newcomers to Linux would be a bit overwhelmed in having to figure that out.

I have configured it myself. BUT I definitely would prefer it coming out of the box this way.

In addition to this and even more important for me would be to implement that broken links are shown in a different color like this:

The last couple of days I have extensively worked with softlinks and it was a huge hassle with the default setting not showing valid and broken links in different colors.

Thanks, riser, for sharing!
LL-user everything is customizable. Those who remember DOS would easily adapt. Wink
I think those os us who use the terminal more often would like to have some colors.
Those who don't probably think it's too geeky. Smile
Thanks for your suggestion. We'll see about that.
Reply
#17
I'm just using the default color settings. So the setup only needs one step, i.e. putting the following code into /etc/bash.bashrc:
Code:
if [ -f $HOME/.dir_colors ]; then
  eval $(/usr/bin/dircolors -b $HOME/.dir_colors)
elif [ -f /etc/DIR_COLORS ]; then
  eval $(/usr/bin/dircolors -b /etc/DIR_COLORS)
else
  eval $(/usr/bin/dircolors -b)
fi
Reply
#18
I like that. No need for the eval here though.
Code:
if [ -f $HOME/.dir_colors ]; then
  /usr/bin/dircolors -b $HOME/.dir_colors
elif [ -f /etc/DIR_COLORS ]; then
  /usr/bin/dircolors -b /etc/DIR_COLORS
else
  /usr/bin/dircolors -b
fi
Reply
#19
Have started working on LL 2.6, here is what I have for the root prompt, with a caution:

[Image: bWncATS.png]
Reply
#20
Hi Jerry,

Good idea to give an additional heads up.

I just did a test installation of Fedora and very much like their approach, a one time, extended warning at the beginning:

[Image: 28579407_sudo_message.png]
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)