View previous topic :: View next topic |
Author |
Message |
sinisterdomestik l33t
Joined: 28 Aug 2003 Posts: 685 Location: Texas
|
Posted: Tue Oct 31, 2006 5:40 am Post subject: terminal question |
|
|
so ive been searching the forums and gentoo-wiki for the last 45 mins and i KNOW its on here somewhere, bc thats where i found it last time, but whats the link so that i can change my terminal to show the entire path in console
eg: instead of
it would say something like Quote: | root@BlackBeauty: /home/sinister | and reg user would be Quote: | sinister@BlackBeauty: /home/sinister/ |
_________________ Thou shalt NEVER speak of removing thine Linux |
|
Back to top |
|
|
erik258 Advocate
Joined: 12 Apr 2005 Posts: 2650 Location: Twin Cities, Minnesota, USA
|
Posted: Tue Oct 31, 2006 6:01 am Post subject: your answer |
|
|
your answer can easily be deduced from the PS1 environment variable, affectionately known by myself as "that variable that affects the look of the prompt". What do you want to bet there's a better name out there somewhere? But i don't want to spend 45 minutes looking for that.
anyways, running "echo $PS1" as regular user give us
Code: | dan@descartes ~ $ echo $PS1
\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\]
dan@descartes ~ $ cd /usr/src/linux
dan@descartes /usr/src/linux $ |
and as you can see, we get the full path. but for root...
Code: | \[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\]
descartes ~ # cd /usr/src/linux
descartes linux # |
as you can see, you need to change that uppercase W to a lowercase w. the easiest way to do this for root would probably set it in /root/.bashrc by appending this:
Code: |
export PS1="\[\033[01;33m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\]"
|
now here's a question: what are all the \[\033[01;33m\] things? I know they must be some kind of escape code for the terminal (at least i am guessing the terminal's what gets it) because
1) they're too obscure to have anything to do with anything recent, but terminal standards are ancient ; and
2) they work at the virtual console and in xterm.
or maybe the'yre for bash. anyway, i know the last number can be set to one of the 16 "original" colors (you know the ones i mean) but which code is which is kind of odd. and i think the 01; part is telling it to go bold on that as well. but i haven't experimented to recently or soberly, so your results may vary.
anyway, there's your answer, as well as some of my own musings. enjoy! _________________ Configuring a Firewall? Try my iptables configuration
LinuxCommando.com is my blog for linux-related scraps and tidbits. Stop by for a visit! |
|
Back to top |
|
|
desultory Bodhisattva
Joined: 04 Nov 2005 Posts: 9410
|
Posted: Tue Oct 31, 2006 6:25 am Post subject: |
|
|
The reference you seek is likely man 1 bash or man 1 ksh or man 1 tcsh.
Given bash as the shell, export PS1="\u@\H \w \$" would be what you are asking for, so long as you do not seek color.
erik258 wrote: | your answer can easily be deduced from the PS1 environment variable, affectionately known by myself as "that variable that affects the look of the prompt". What do you want to bet there's a better name out there somewhere? But i don't want to spend 45 minutes looking for that.
|
Perhaps "prompt string 1"?
As for the supposition on the escape sequences, good guess. You might find this excerpt from bash(1) elucidating.
Quote: | \[
begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
\]
end a sequence of non-printing characters |
Last edited by desultory on Tue Oct 31, 2006 6:52 am; edited 1 time in total |
|
Back to top |
|
|
Dlareh Advocate
Joined: 06 Aug 2005 Posts: 2102
|
Posted: Tue Oct 31, 2006 6:26 am Post subject: |
|
|
If you actually see "localhost", you probably need to edit /etc/conf.d/hostname _________________ "Mr Thomas Edison has been up on the two previous nights discovering 'a bug' in his phonograph." --Pall Mall Gazette (1889)
Are we THERE yet? |
|
Back to top |
|
|
sinisterdomestik l33t
Joined: 28 Aug 2003 Posts: 685 Location: Texas
|
Posted: Tue Oct 31, 2006 5:08 pm Post subject: |
|
|
thank you for the help, so far, so good, just need some tweaking is all....as for the localhost part, i edited conf.d/hostname to BlackBeauty but nothing...is there another file im missing that needs to be edited?? _________________ Thou shalt NEVER speak of removing thine Linux |
|
Back to top |
|
|
JROCK2004 Guru
Joined: 02 Mar 2004 Posts: 450 Location: PA
|
Posted: Tue Oct 31, 2006 5:18 pm Post subject: |
|
|
after the change did you log out and log back in? |
|
Back to top |
|
|
sinisterdomestik l33t
Joined: 28 Aug 2003 Posts: 685 Location: Texas
|
Posted: Tue Oct 31, 2006 5:21 pm Post subject: |
|
|
yeah...i still get for root and Quote: | sinister@localhost ~ $ | for reg user
/EDIT
ok, scratch that....its to early in the morning...i restarted the comp and the localhost is fixed....just have to fix the prompt part now. _________________ Thou shalt NEVER speak of removing thine Linux |
|
Back to top |
|
|
JROCK2004 Guru
Joined: 02 Mar 2004 Posts: 450 Location: PA
|
Posted: Tue Oct 31, 2006 5:56 pm Post subject: |
|
|
can you post .bashrc? |
|
Back to top |
|
|
sinisterdomestik l33t
Joined: 28 Aug 2003 Posts: 685 Location: Texas
|
Posted: Tue Oct 31, 2006 6:18 pm Post subject: |
|
|
Quote: | BlackBeauty ~ # vim .bashrc
# Set up PATH depending on whether we're root or a normal user.
# There's no real reason to exclude sbin paths from the normal user,
# but it can make tab-completion easier when they aren't in the
# user's PATH to pollute the executable namespace.
#
# It is intentional in the following line to use || instead of -o.
# This way the evaluation can be short-circuited and calling whoami is
# avoided.
if [ "$EUID" = "0" ] || [ "$USER" = "root" ] ; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${ROOTPATH}"
else
PATH="/usr/local/bin:/usr/bin:/bin:${PATH}"
fi
export PATH
unset ROOTPATH
# Extract the value of EDITOR
[ -z "$EDITOR" ] && EDITOR="`. /etc/rc.conf 2>/dev/null; echo $EDITOR`"
[ -z "$EDITOR" ] && EDITOR="/bin/nano"
export EDITOR
if [ -n "${BASH_VERSION}" ] ; then
# Newer bash ebuilds include /etc/bash/bashrc which will setup PS1
# including color. We leave out color here because not all
# terminals support it.
if [ -f /etc/bash/bashrc ] ; then
# Bash login shells run only /etc/profile
# Bash non-login shells run only /etc/bash/bashrc
# Since we want to run /etc/bash/bashrc regardless, we source it
# from here. It is unfortunate that there is no way to do
# this *after* the user's .bash_profile runs (without putting
# it in the user's dot-files), but it shouldn't make any
# difference.
. /etc/bash/bashrc
else
PS1='\[\033[01;32m\]\u@\h:\[\033[01;34m\]\w\$\[\033[00m\]'
fi
else
# Setup a bland default prompt. Since this prompt should be useable
# on color and non-color terminals, as well as shells that don't
# understand sequences such as \h, don't put anything special in it.
PS1="`whoami`@`uname -n | cut -f1 -d.` \$ "
fi
for sh in /etc/profile.d/*.sh ; do
if [ -r "$sh" ] ; then
. "$sh"
fi
done
unset sh
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
alias ls='ls --color=auto -a'
alias c=clear
alias ll='ls -l'
alias grep='grep --color=auto'
source .bash_profile |
_________________ Thou shalt NEVER speak of removing thine Linux |
|
Back to top |
|
|
Dlareh Advocate
Joined: 06 Aug 2005 Posts: 2102
|
Posted: Tue Oct 31, 2006 8:24 pm Post subject: |
|
|
I guess what you want is:
Code: | PS1='\[\033[01;32m\]\u@\h:\[\033[01;34m\]$PWD \$\[\033[00m\] ' |
in /root/.bashrc and /home/yourusername/.bashrc
make sure you replace or put it after any other PS1 lines.
Alternatively, put it in /etc/bash/bashrc if you want this to affect all users, but note that new versions of baselayout will want to replace this file later, so you have to preserve your changes across config file updates (with etc-update or dispatch-conf, etc).
---
Here's the .bashrc prompt stuff I've been using for about 2 years, in case it interests you:
Code: | ######### COLOR PROMPT SECTION ##########
# Set colorful PS1 only on colorful terminals.
# dircolors --print-database uses its own built-in database
# instead of using /etc/DIR_COLORS. Try to use the external file
# first to take advantage of user additions.
# use_color=false
#safe_term=${TERM//[^[:alnum:]]/.} # sanitize TERM
#
#if [[ -f /etc/DIR_COLORS ]]; then
# grep -q "^TERM ${safe_term}" /etc/DIR_COLORS && use_color=true
#elif [ -x /usr/bin/dircolors ] && dircolors --print-database | grep -q "^TERM ${safe_term}"; then
# use_color=true
#fi
# brashly override the above since most things seem to support colors these days,
# including BSD which the above linux-centric checks will not detect.
use_color=true
if ${use_color}; then
PHOST="${HOSTNAME%%.*}"
if [[ "$EUID" == 0 ]]; then # root user -> red all uppercase HOSTNAME
# PHOST = pre-formatted, DHOST = colorized
PHOST="$(echo ${HOSTNAME%%.*} | tr '[:lower:]' '[:upper:]')"
DHOST="\[\033[01;31m\]${PHOST}"
PS1="${DHOST} \[\033[01;34m\]\${PWD/\$HOME/~} # \[\033[00m\]"
else if [[ "$EUID" == 1000 ]]||[[ "$USER" == "dlareh" ]]||[[ "$USER" == "lare" ]]; then
# main user -> green regular case hostname
DHOST="\[\033[01;32m\]${HOSTNAME%%.*}"
else # some other user -> yellow/orangeish regular case hostname
DHOST="\[\033[01;33m\]${HOSTNAME%%.*}"
fi
PS1="${DHOST} \[\033[01;34m\]\${PWD/\$HOME/~} \$ \[\033[00m\]"
fi
else # we don't have colors
if [[ $EUID == 0 ]]; then
PS1='root@${HOSTNAME} $PWD # '
else
PS1='${USER}@${HOSTNAME} ${PWD##*/} \$ '
fi
fi
######### END COLOR PS1 STUFF #########
PROMPT_COMMAND=_setprompt
function _setprompt {
wintitle "${PHOST}:${PWD/#$HOME/~}"
}
function wintitle {
# Change the window title of screens and xterms
case $TERM in
xterm*|rxvt|Eterm|eterm)
echo -ne "\e]0;$@\007"
;;
screen*)
echo -ne "\e]0;$@\007"
echo -ne "\ek$@\e\\"
;;
esac
} |
_________________ "Mr Thomas Edison has been up on the two previous nights discovering 'a bug' in his phonograph." --Pall Mall Gazette (1889)
Are we THERE yet? |
|
Back to top |
|
|
sinisterdomestik l33t
Joined: 28 Aug 2003 Posts: 685 Location: Texas
|
Posted: Wed Nov 01, 2006 1:33 am Post subject: |
|
|
got it working...thanks _________________ Thou shalt NEVER speak of removing thine Linux |
|
Back to top |
|
|
|