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 |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
01-28-2014, 01:50 AM
|
#1
|
Member
Registered: Jan 2012
Posts: 130
Rep: 
|
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.
|
|
|
01-28-2014, 07:37 AM
|
#2
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
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 ... ?
|
|
|
01-28-2014, 07:46 AM
|
#3
|
Member
Registered: Jan 2012
Posts: 130
Original Poster
Rep: 
|
Quote:
Originally Posted by catkin
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?
|
|
|
01-29-2014, 08:18 AM
|
#4
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
That's one sophisticated solution shown in the Arch WIKI!
Essentially you want something like the
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.
|
01-29-2014, 09:10 AM
|
#5
|
Member
Registered: Jan 2012
Posts: 130
Original Poster
Rep: 
|
Quote:
Originally Posted by catkin
That's one sophisticated solution shown in the Arch WIKI!
Essentially you want something like the
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.
|
|
|
All times are GMT -5. The time now is 03:40 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|