Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
bash prompt
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German)
View previous topic :: View next topic  
Author Message
ruth
Retired Dev
Retired Dev


Joined: 07 Sep 2003
Posts: 640
Location: M / AN / BY / GER

PostPosted: Thu Sep 09, 2004 12:02 pm    Post subject: bash prompt Reply with quote

hallihallo,

heute möchte ich eigenlich nur meinen bash prompt vorstellen.
manchmal fällt es mir schwer, in einem wust von offenen shells den überblick zu behalten.
deshalb habe ich die folgenden dateien angelegt:
~/.bash_profile
Code:

[ -f "$HOME/.bashrc" ] && . $HOME/.bashrc

die dürfte jeder noch so (ähnlich) haben
und dann noch:
~/.bashrc
Code:

[ -f /etc/profile.d/bash-completion ] && source /etc/profile.d/bash-completion

alias ls='ls --color=auto'
alias nano="nano -w"

function set_prompt {

        local BLACK="\[\033[0;30m\]"
        local BLUE="\[\033[0;34m\]"
        local GREEN="\[\033[0;32m\]"
        local CYAN="\[\033[0;36m\]"
        local RED="\[\033[0;31m\]"
        local PURPLE="\[\033[0;35m\]"
        local BROWN="\[\033[0;33m\]"
        local LIGHT_GRAY="\[\033[0;37m\]"
        local DARK_GRAY="\[\033[1;30m\]"
        local LIGHT_BLUE="\[\033[1;34m\]"
        local LIGHT_GREEN="\[\033[1;32m\]"
        local LIGHT_CYAN="\[\033[1;36m\]"
        local LIGHT_RED="\[\033[1;31m\]"
        local LIGHT_PURPLE="\[\033[1;35m\]"
        local YELLOW="\[\033[1;33m\]"
        local WHITE="\[\033[1;37m\]"
        local NO_COLOUR="\[\033[0m\]"

        if [ "$HOSTNAME" = "leela" ]; then
        local HOST_COLOUR=$GREEN
        elif [ "$HOSTNAME" = "h5877" ]; then
        local HOST_COLOUR=$LIGHT_RED
        fi
        if [ `mount | grep 'noexec' | wc -l` -gt 0 ]; then
        mnt_tmp="${WHITE}[tmp:${LIGHT_GREEN}noexec${WHITE}]${NO_COLOUR}"
        else
                mnt_tmp="${WHITE}[tmp:${LIGHT_RED}exec${WHITE}]${NO_COLOUR}"
        fi

        if [ $UID -eq 0 ]; then
                local user="$WHITE[$LIGHT_RED\u$WHITE@$HOST_COLOUR\h$WHITE]"
        else
                local user="$WHITE[$LIGHT_GREEN\u$WHITE@$HOST_COLOUR\h$WHITE]"
        fi

PS1="${user}\
$mnt_tmp\$NO_COLOUR\
$WHITE($YELLOW\w$WHITE) \\$ $NO_COLOUR"



}

export PROMPT_COMMAND=set_prompt



interessant hier ist der teil:
Code:

        if [ "$HOSTNAME" = "leela" ]; then
        local HOST_COLOUR=$GREEN
        [more_hosts_here]
        elif [ "$HOSTNAME" = "h5694" ]; then
        local HOST_COLOUR=$LIGHT_RED
        [more_hosts_here]
        fi

wie man sieht, heisst meine lokale maschine leela
einer meiner _wichtigen_ rechner heisst h5694, was das für eine maschine ist, das kann man sich denken... ;-)
nun, was ist der effekt?
also, als root auf meiner lokalen maschine sieht das dann so aus:
[root@leela][tmp:exec](~) #

als root auf der grossen maschine so:
[root@h5694][tmp:noexec](~) #
ausserdem wird root immer in rot dargestellt, ein unprivilegierter nutzer in grün
die relativ unwichtigen, weil lokalen maschinen in grün, und die wichtigen, weil bloss nichts verkehrt machen darf maschinen in rot
desweiteren wird der mount-zustand (exec || noexec) des /tmp dateisystems dargestellt; dass man nicht vergisst vor dem ausloggen das /tmp wieder auf grün zu setzen... ;-)
die ürsprüngliche version dieses prompts hat mir mal ein kumpel per mail geschickt; ich hab das dann für mich so angepasst...
hoffe, das ist für ein paar leute von nutzen... ;-)

gruss
rootshell
_________________
"The compiler has tried twice to abort and cannot do so; therefore, compilation will now terminate."
-- IBM PL/I (F) error manual
Back to top
View user's profile Send private message
Minox
Apprentice
Apprentice


Joined: 12 Apr 2004
Posts: 188
Location: Germany / Munich

PostPosted: Thu Sep 09, 2004 12:41 pm    Post subject: Reply with quote

Super grosses Merci ;)

Jetzt brauche ich mir da nicht mehr den Kopf zerbrechen wegen. Ich passe das farblich auch noch aweng an, denn bei mir hat das einen Stich von Italien und ich stehe mehr auf Spanien ;)

Auf jeden Fall: Danke rootshell

MfG
_________________
:!: proud to be 100% M$ free :!:
Back to top
View user's profile Send private message
Macrobiotus
Apprentice
Apprentice


Joined: 06 Oct 2002
Posts: 230

PostPosted: Thu Sep 09, 2004 5:26 pm    Post subject: Reply with quote

Schöne Idee (für Leute die sich mit sowas (buntem) nie beschäftigt haben.
Sieht das eigentlich bei euch auch so aus?

Code:

BROWN='\[\033[0;33m\]'
CYAN='\[\033[0;36m\]'
DARK_GRAY='\[\033[1;30m\]'
GREEN='\[\033[0;32m\]'
HOST_COLOUR='\[\033[1;31m\]'
LIGHT_BLUE='\[\033[1;34m\]'
LIGHT_CYAN='\[\033[1;36m\]'
LIGHT_GRAY='\[\033[0;37m\]'
LIGHT_GREEN='\[\033[1;32m\]'
LIGHT_PURPLE='\[\033[1;35m\]'
LIGHT_RED='\[\033[1;31m\]'
NO_COLOUR='\[\033[0m\]'
PURPLE='\[\033[0;35m\]'
RED='\[\033[0;31m\]'
WHITE='\[\033[1;37m\]'
YELLOW='\[\033[1;33m\]'
[macro@biotus][tmp:exec](~/Bilder/icons) $ ls
audacity.png         firefox.svg           Nautilus2.png    Splash-EvolvingTux.png
beep4.png            gimp.svg              Nautilus.png     web-browser1.svg
blender.png          gnome-gimp.svg        ooo_gulls.svg    web-browser.svg
blender.svg          gnome-terminal.svg    OpenOffice2.png  xmms-rmckenzie.png
cr32-app-kile.png    gthumb.svg            OpenOffice.png   xmms.svg
Digital-Camera1.png  Mozilla-Mail_alt.png  Printer.png
BROWN='\[\033[0;33m\]'
CYAN='\[\033[0;36m\]'
DARK_GRAY='\[\033[1;30m\]'
GREEN='\[\033[0;32m\]'
HOST_COLOUR='\[\033[1;31m\]'
LIGHT_BLUE='\[\033[1;34m\]'
LIGHT_CYAN='\[\033[1;36m\]'
LIGHT_GRAY='\[\033[0;37m\]'
LIGHT_GREEN='\[\033[1;32m\]'
LIGHT_PURPLE='\[\033[1;35m\]'
LIGHT_RED='\[\033[1;31m\]'
NO_COLOUR='\[\033[0m\]'
PURPLE='\[\033[0;35m\]'
RED='\[\033[0;31m\]'
WHITE='\[\033[1;37m\]'
YELLOW='\[\033[1;33m\]'
[macro@biotus][tmp:exec](~/Bilder/icons) $
Back to top
View user's profile Send private message
7maestro7
Tux's lil' helper
Tux's lil' helper


Joined: 10 Aug 2004
Posts: 149
Location: Baden ohne Württemberg

PostPosted: Thu Sep 09, 2004 5:34 pm    Post subject: Reply with quote

was hat es denn mit dem tmp:noexec auf sich....
bzw mit dem mounten von /tmp ich hab da keine Ahnung...
könnte mir jmd mal einen link geben was das soll oder mir das in kurzen worten erklären nur falls jmd langweilig iss...

danke

maestro
Back to top
View user's profile Send private message
Minox
Apprentice
Apprentice


Joined: 12 Apr 2004
Posts: 188
Location: Germany / Munich

PostPosted: Thu Sep 09, 2004 7:22 pm    Post subject: Reply with quote

Ich hab das auch wieder raus genommen mit dem tmp:exec/noexec. Zumindest grept das Script aus der mount list, datei systeme auf denen dateien nicht ausgeführt werden dürfen. Aber da im Befehl "mount" ohne parameter verwendet wird würde er jedes mal wenn ein einziges fs im system das flag noexec hat auf der gesamten shell tmp:noexec anzeigen. Also, entweder ein wenig optimieren oder rausnehmen ;)
_________________
:!: proud to be 100% M$ free :!:
Back to top
View user's profile Send private message
7maestro7
Tux's lil' helper
Tux's lil' helper


Joined: 10 Aug 2004
Posts: 149
Location: Baden ohne Württemberg

PostPosted: Thu Sep 09, 2004 7:25 pm    Post subject: Reply with quote

ja rausgenommen hab ichs auch ich wollte nur wissen wieso man tmp auf exec/noexec setzen sollte...
Back to top
View user's profile Send private message
Deever
Veteran
Veteran


Joined: 06 Jul 2002
Posts: 1354
Location: Zürich / Switzerland

PostPosted: Thu Sep 09, 2004 8:09 pm    Post subject: Reply with quote

Alternativ zu alledem kann man screen verwenden und den Hostnamen in der Statuszeile anzeigen. Dann weiß man auch bei anderen Programmen, auf welchem Rechner man gerade arbeitet! ;)

Gruß && HTH!
/dev
Back to top
View user's profile Send private message
Minox
Apprentice
Apprentice


Joined: 12 Apr 2004
Posts: 188
Location: Germany / Munich

PostPosted: Thu Sep 09, 2004 8:23 pm    Post subject: Reply with quote

Macrobiotus wrote:
Schöne Idee (für Leute die sich mit sowas (buntem) nie beschäftigt haben.
Sieht das eigentlich bei euch auch so aus?

Nein eigentlich nicht. Wirst wohl was in der bashrc falsch eingetragen haben. Oder beim copy/paste was kaputt gegangen.
_________________
:!: proud to be 100% M$ free :!:
Back to top
View user's profile Send private message
Macrobiotus
Apprentice
Apprentice


Joined: 06 Oct 2002
Posts: 230

PostPosted: Thu Sep 09, 2004 9:24 pm    Post subject: Reply with quote

Quote:
Wirst wohl was in der bashrc falsch eingetragen haben. Oder beim copy/paste was kaputt gegangen.


So wars, danke :roll:
Back to top
View user's profile Send private message
Pamino
Apprentice
Apprentice


Joined: 07 Apr 2004
Posts: 281
Location: 127.0.0.1

PostPosted: Thu Sep 09, 2004 9:52 pm    Post subject: Reply with quote

Kann mal bitte jemand seine .bashrc ohne das exec posten? Ich mach da irgendwas falsch :D
Und gibt es eine Möglichkeit statt dem Pfad einfach nur den Ordnernamen in dem man sich befindet anzeigen zu lassen? Wird sonst manchmal zu lang.... den Kompletten Pfad hatte ich sonst immer in der titelleiste und in .bashrc stand nur source /etc/profile. Wie kann ich wieder den Pfad in der Leiste anzeigen lassen?
Edit: Das temp hab ich doch entfernen können ^^
Edit2: Wenn ich das hinzufüge....
if [ "$SHELL" = '/bin/bash' ] || [ "$SHELL" = '/bin/sh' ]
then
if [ "$TERM" = 'xterm' ]
then
PROMPT_COMMAND='echo -ne "\033]0; ${PWD}\007"'
fi
fi
...dann hab ich in xterm wieder meine alte Titelleiste. Fehlt nur noch der Ordername statt Pfad zur Perfektion....da hab ich aber leider keine idee
Back to top
View user's profile Send private message
Minox
Apprentice
Apprentice


Joined: 12 Apr 2004
Posts: 188
Location: Germany / Munich

PostPosted: Thu Sep 09, 2004 10:14 pm    Post subject: Reply with quote

Pamino wrote:
Kann mal bitte jemand seine .bashrc ohne das exec posten? Ich mach da irgendwas falsch :D


Lösche einfach den Teil:
Code:
        if [ `mount | grep 'noexec' | wc -l` -gt 0 ]; then
        mnt_tmp="${WHITE}[tmp:${LIGHT_GREEN}noexec${WHITE}]${NO_COLOUR}"
        else
                mnt_tmp="${WHITE}[tmp:${LIGHT_RED}exec${WHITE}]${NO_COLOUR}"
        fi


MfG
_________________
:!: proud to be 100% M$ free :!:
Back to top
View user's profile Send private message
marc
Apprentice
Apprentice


Joined: 13 Jan 2003
Posts: 290

PostPosted: Thu Sep 09, 2004 10:15 pm    Post subject: Reply with quote

Code:
export PS1="\033[1;34m\]\u@\h \033[00m\] \t  \033[32m\]\w   \033[1;35m\]\$(/bin/ls -1a | /usr/bin/wc -l | /bin/sed 's: ::g') Einträge \033[00m\]\n\$ \033[00m\]"


alias ls="ls --color"
alias dir="dir --color"
alias su="su -"


Für root habe ich die in /etc/profile geändert. root soll ja schliesslich "erkannt" werden.
Back to top
View user's profile Send private message
sirro
Veteran
Veteran


Joined: 20 Jul 2003
Posts: 1472
Location: aachen.nrw.de.eu

PostPosted: Fri Sep 10, 2004 7:08 am    Post subject: Reply with quote

7maestro7 wrote:
ja rausgenommen hab ichs auch ich wollte nur wissen wieso man tmp auf exec/noexec setzen sollte...

Vorteil: ein (großer?) Teil Exploits laufen ins leere, da diese exec voraussetzen
Nachteil: Manche "normalen" Installer tuns auch nichtmehr. Wer nur mit portage arbeitet sollte damit kein Problem haben ;-)
Back to top
View user's profile Send private message
toskala
Advocate
Advocate


Joined: 14 Dec 2002
Posts: 2080
Location: hamburg, germany

PostPosted: Tue Sep 28, 2004 7:29 am    Post subject: Reply with quote

oha, nice one, rootshell ;)

mal kucken wie ich das verwurschtel ;)
_________________
adopt an unanswered post
erst denken, dann posten
Back to top
View user's profile Send private message
equinox0r
l33t
l33t


Joined: 18 Feb 2004
Posts: 614

PostPosted: Wed Sep 29, 2004 8:11 am    Post subject: Reply with quote

ich hab bei mir mal geschaut ich hab die standard .screenrc etwas modifiziert damit sie auch meinen anforderungen gerecht wird ;)

das funktioniert auch alles soweit nur dass der prompt innerhalb vom screen ziemlich zerschossen ist.
Vorher-Nachher:
Code:
[8:58:48]}[equinox@dude.zion ]
[/data/home/equinox] $ screen

\[\033[1;32m\][\[\033[1;37m\]\t\[\033[1;32m\]]}[\[\033[1;37m\]\u\[\033[1;32m\]@\[\033[1;37m\]dude.zion \[\033[1;32m\]]\n\[\033[1;32m\][\[\033[1;37m\]\w\[\033[1;32m\]]\[\033[00m\] $ 


in meiner ~/.screenrc steht:
Code:
hardstatus alwayslastline "%{wk}%H %{wk}%?%-Lw%?%{wb}%n*%f %t%?(%u)%?%{wk}%?%+Lw%? %{dk}%= %{ck}%Y-%m-%d %{ck}%c"


und schlussendlich meine .bashrc (der relevante teil):
Code:
host_name=`hostname -f`
PROMPT="${mask}[${usercol}\t${mask}]}\
[${white}\u${mask}@${white}${host_name}${mask}]\n\
${mask}[${white}\w${mask}]\
${normal} \$ "

test -z "$PROFILEREAD" && . /etc/profile

if [ "$TERM" == "screen" ]; then
        SCREEN_AUTO=`echo -n -e "\033k\033\134"`
        PS1='$PROMPT $SCREEN_AUTO'
else
        PS1=$PROMPT
fi

export DISPLAY LESS PS1


wie krieg ich das richtig hin?
_________________
AMD 2400+ XP | 1024 MB RAM | ATI Radeon 9600Pro
Gentoo Base System version 1.4.16 | Portage 2.0.51.19 | 2.6.11-gentoo-r9 Kernel
Back to top
View user's profile Send private message
appro
Tux's lil' helper
Tux's lil' helper


Joined: 21 Jul 2003
Posts: 144
Location: Germany/Rosenheim

PostPosted: Wed Sep 29, 2004 5:39 pm    Post subject: Bash-Prompt Reply with quote

Ich denke mal du willst aus
Code:
PS1='$PROMPT $SCREEN_AUTO'
ein
Code:
PS1="$PROMPT $SCREEN_AUTO"
machen :)
Ist die Uhrzeit im Prompt nicht sinnlos, wenn du sie schon im screen unten rechts hast?
Back to top
View user's profile Send private message
Lukas_Drude
n00b
n00b


Joined: 24 Sep 2006
Posts: 21

PostPosted: Mon Oct 02, 2006 9:52 pm    Post subject: Reply with quote

Ich habe mal die Anweisungen befolgt, die abgewandelte Promt funktioniert auch in der Konsole (STRG + F1 bis F4), aber leider weder mit xterm noch mit aterm oder Eterm. Wenn ich dann aber "export PROMPT_COMMAND=set_prompt" eingebe, dann funktioniert alles so, wie es sein soll.

Jetzt würde mir einfallen, dass die Konsolen beim starten gleich den Befehl mit ausführen sollen (mit alias?), aber das ist sicher nicht die angedachte Lösung.

Sicherheitshalber hab ich die http://crs-abi-2006.de/multi/.bashrc nochmal hochgeladen.
Back to top
View user's profile Send private message
Lukas_Drude
n00b
n00b


Joined: 24 Sep 2006
Posts: 21

PostPosted: Mon Oct 09, 2006 10:02 pm    Post subject: Reply with quote

Die Frage hat sich geklärt. Alles steht jetzt in /etc/bash/bashrc und /etc/profile sourced ersteres, so ist alles abgedeckt.
Back to top
View user's profile Send private message
Moorenkopf
Apprentice
Apprentice


Joined: 18 Apr 2004
Posts: 189
Location: NRW

PostPosted: Mon Oct 09, 2006 10:38 pm    Post subject: Re: bash prompt Reply with quote

ruth wrote:
Code:

alias ls='ls --color=auto'
alias nano="nano -w"

Du könntest statt dem nano-Alias auch einfach die Zeile set nowrap aus der /etc/nanorc auskommentieren. </klugscheiß>

Ansonsten, nette Idee :)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum