LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-28-2014, 01:50 AM   #1
steak1987
Member
 
Registered: Jan 2012
Posts: 130

Rep: Reputation: Disabled
Question Quick bash prompt colour question (changing styles)


I have a raspberry pi, which I tried to create a custom MOTD using the following instructions:

http://www.raspberrypi.org/phpBB3/viewtopic.php?t=23440

Code:
pi@raspberrypi:~$ cat ~/.bash_profile 
let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)"
let secs=$((${upSeconds}%60))
let mins=$((${upSeconds}/60%60))
let hours=$((${upSeconds}/3600%24))
let days=$((${upSeconds}/86400))
UPTIME=`printf "%d days, %02dh%02dm%02ds" "$days" "$hours" "$mins" "$secs"`
 
# get the load averages
read one five fifteen rest < /proc/loadavg
 
echo "$(tput setaf 2)
.~~.   .~~.    `date +"%A, %e %B %Y, %r"`
'. \ ' ' / .'   `uname -srmo`$(tput setaf 1)
.~ .~~~..~.
: .~.'~'.~. :   Uptime.............: ${UPTIME}
~ (   ) (   )   Memory.............: `cat /proc/meminfo | grep MemFree | awk {'print $2'}`kB (Free) / `cat /proc/meminfo | grep MemTotal | awk {'print $2'}`kB (Total)
( : '~'.~.'~'   Load Averages......: ${one}, ${five}, ${fifteen} (1, 5, 15 min)
~ .~ (   ) ~.   Running Processes..: `ps ax | wc -l | tr -d " "`
(  : '~' :  )   IP Addresses.......: `/sbin/ifconfig eth0 | /bin/grep "inet addr" | /usr/bin/cut -d ":" -f 2 | /usr/bin/cut -d " " -f 1` and `wget -q -O - http://icanhazip.com/ | tail`
'~ .~~~. ~'    
$(tput sgr0)"

However, that changed the formatting of my bash colours. The image below illustrates my predicament:

http://i.imgur.com/fOogLlk.png

I looked at the instructions on that page:
https://wiki.archlinux.org/index.php/Color_Bash_Prompt

But im not sure which file I need to modify? Just for record, my current bashrc is as follows:

Code:
pi@raspberrypi:~$ cat ~/.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
  # We have color support; assume it's compliant with Ecma-48
  # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
  # a case would tend to support setf rather than setaf.)
  color_prompt=yes
    else
  color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]\w \$\[\033[00m\] '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

export JAVA_HOME="/opt/jdk1.8.0"
export PATH=$PATH:$JAVA_HOME/bin

Where do I make the alterations suggested on the arch page? Which modifications should I make, since im fairly inexperienced to linux and im not sure about syntax in this regard.

Thanks for your time.
 
Old 01-28-2014, 07:37 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
What is the problem with the formatting of your bash colours"? In the terminal window in the linked image there are no colours, formatted or not. The thread subject is about bash prompt colour but neither your .bash_profile nor your .bashrc set any colours ... ?
 
Old 01-28-2014, 07:46 AM   #3
steak1987
Member
 
Registered: Jan 2012
Posts: 130

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by catkin View Post
What is the problem with the formatting of your bash colours"? In the terminal window in the linked image there are no colours, formatted or not. The thread subject is about bash prompt colour but neither your .bash_profile nor your .bashrc set any colours ... ?
Thats the thing, I'm curious as to how I would set the colours as described in the arch page, and where they would go?
 
Old 01-29-2014, 08:18 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
That's one sophisticated solution shown in the Arch WIKI!

Essentially you want something like the
Code:
case ${TERM} in
section in one of the bash start up files. The most popular solution is to put everything in ~/.bashrc and to ensure that ~/.bash_profile sources ~/.bashrc but there are many possibilities. For a full description of bash start up files: http://www.gnu.org/software/bash/man...-Startup-Files

If you are using a terminal or terminal emulator that sets TERM to a value matched by xterm*|rxvt*|Eterm|aterm|kterm|gnome*) then you can simply copy and paste that case statement from the Arch WIKI into you .bashrc. If you don't see a coloured prompt, try starting bash from that command prompt ... and let us know you you got on
 
1 members found this post helpful.
Old 01-29-2014, 09:10 AM   #5
steak1987
Member
 
Registered: Jan 2012
Posts: 130

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by catkin View Post
That's one sophisticated solution shown in the Arch WIKI!

Essentially you want something like the
Code:
case ${TERM} in
section in one of the bash start up files. The most popular solution is to put everything in ~/.bashrc and to ensure that ~/.bash_profile sources ~/.bashrc but there are many possibilities. For a full description of bash start up files: http://www.gnu.org/software/bash/man...-Startup-Files

If you are using a terminal or terminal emulator that sets TERM to a value matched by xterm*|rxvt*|Eterm|aterm|kterm|gnome*) then you can simply copy and paste that case statement from the Arch WIKI into you .bashrc. If you don't see a coloured prompt, try starting bash from that command prompt ... and let us know you you got on
Thanks, I did some reading, and simply came up with a quick and easy (but slightly messy) hack.

http://stackoverflow.com/questions/9...ust-use-bashrc


Basically, I just copied bashrc into bash_profile, ensuring that whatever I log in using, it should follow he "default" bash rules. I generally use gnome terminal, remmina and server auditor on android.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Need quick answer. Changing user directory and changing it to /bin/bash jinsu88 Linux - Newbie 1 01-21-2014 08:34 PM
changing bash prompt JuNNi Programming 11 11-03-2010 09:15 AM
Changing Bash Prompt socks Slackware 11 02-09-2005 06:32 PM
Changing the BASH Prompt Blade_Powers Linux - Newbie 4 03-28-2004 09:21 PM
Changing the BASH prompt? Dravis Linux - Software 2 01-22-2004 09:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:40 PM.

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