[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: nice PS1 with /bin/sh
Thank you for your mail, Todd.
Your script worked prefectlly! ;-)
Although there are many tokens that I havn't used before, I'll check
each line and study.
Thank you very much.
-- Original Message --
From: "Todd T. Fries" <todd@fries.net>
Subject: Re: nice PS1 with /bin/sh
Date: Sun, 2 Apr 2000 11:40:39 -0500
Message-ID: <20000402114039.C22351@LightHouse.fries.net>
> But it does not change the prompt for you once you have set it :-(
>
> On Mon, Apr 03, 2000 at 12:44:24AM +0900, Yutaka KAWASE wrote:
> >
> > Hello all,
> >
> > I have been using /usr/local/bin/bash but now tring to get used to
> > /bin/sh.
> >
> > In my .profile, I wrote;
> >
> > PS1="$USER@`hostname`:`echo $PWD | perl -pe 's#^$ENV{HOME}#~#'`$ "
> >
> > and this gives me the prompt of my favorite.
> >
> > However, I don't want to use perl to set up PS1.
> > I think I should use sed instead but don't know how to do that.
> >
> > Any suggestions?
> >
> >
> > --
> > Yutaka KAWASE <yutaka@jpnet.nu>
>
> alias cd=do_cd
>
> do_cd() {
> builtin cd $@
> pwd=${PWD##$HOME}
> [ ${#pwd} -lt ${#PWD} ] && pwd="~$pwd"
> [ "$hostname" ] || hostname=$(hostname)
> PS1="$USER@$hostname:$pwd\$ "
> }
>
> This is really the same as /bin/ksh on OpenBSD, fwiw.
>
> Now personally I add a little 'fun' if it's a terminal:
>
> title() {
> echo "\033]2;$*\007\c"
> }
> icon() {
> echo "\033]1;$*\007\c"
> }
>
> if [ "$TERM" = "xterm" -o "$TERM" = "xterm-color" -o "$TERM" = "screen" ];
> then
> [ "$hostname" ] || hostname=$(hostname)
> PS1="$hostname\$ "
> m=$(uname -m)
> s=$(uname -s)
> r=$(uname -r)
> ver="$m $s $r"
> titleicon='icon "$pwd";title "$pwd $(date +%m%d\ %a\ %r) '$LOGNAME'@'$hostname', '$ver'"'
> do_cd() {
> builtin cd $@
> pwd=${PWD##$HOME}
> [ ${#pwd} -lt ${#PWD} ] && pwd="~$pwd"
> [ "$hostname" ] || hostname=$(hostname)
> PS1="$USER@$hostname:$pwd\$ "
> eval $titleicon
> }
> fi
>
> Yes, you can set the title with screen, with the following .screenrc stuff:
>
> termcap xterm hs@:cs=\E[%i%d;%dr:im=\E[4h:ei=\E[4l
> terminfo xterm hs@:cs=\E[%i%p1%d;%p2%dr:im=\E[4h:ei=\E[4l
> termcap xterm-color hs@:cs=\E[%i%d;%dr:im=\E[4h:ei=\E[4l
> terminfo xterm-color hs@:cs=\E[%i%p1%d;%p2%dr:im=\E[4h:ei=\E[4l
> termcap rxvt hs@:cs=\E[%i%d;%dr:im=\E[4h:ei=\E[4l
> terminfo rxvt hs@:cs=\E[%i%p1%d;%p2%dr:im=\E[4h:ei=\E[4l
>
> register [ "\033:se noai\015a"
> register ] "\033:se ai\015a"
> bind ^] paste [.]
>
> termcap xterm 'hs:ts=\E]2;:fs=\007:ds=\E]1;Screen\007'
> terminfo xterm 'hs:ts=\E]2;:fs=\007:ds=\E]1;Screen\007'
> termcap xterm-color 'hs:ts=\E]2;:fs=\007:ds=\E]1;Screen\007'
> terminfo xterm-color 'hs:ts=\E]2;:fs=\007:ds=\E]1;Screen\007'
> termcap rxvt 'hs:ts=\E]2;:fs=\007:ds=\E]1;Screen\007'
> terminfo rxvt 'hs:ts=\E]2;:fs=\007:ds=\E]1;Screen\007'
>
> >... so that when flipping around to different 'screens' within
> screen, you can see the title of your xterm/rxvt/etc change :-)
>
> You are quite right that perl is not something you want to be
> running from a shell script that gets called alot. Unless you
> have a really fast machine, you will notice this 'overhead'.
> It's almost always faster to do alot of extra things in
> the native shell language than it is to call another program.
> Same comparison as its easier to do extra cpu stuff to avoid
> hitting the hard drive ..
>
> Have fun!
> --
> Todd Fries .. todd@fries.net
--
Yutaka KAWASE <yutaka@oneill.co.jp>