Jump to content

nifty prompts...


Recommended Posts

Ok, I've seen some pretty cool looking prompts for terminals that obviously aren't the default, and was wondering what the easiest way of setting them is. i know it has to do with either .bashrc, .bash_profile, or the respective settings for the shell you choose, but I haven't figured out exactly how it works (tried looking at how it's set in these files but i'm either thinking wrong or too darn lazy to figure it out)

 

anyone have a short and quick way of doing this? as an example, say I want my prompt to look like:

+login pwd-->

 

and just as an added bonus, what if I want there to be a banner at the top of every new terminal I open? say some neat ascii art (i would assume this might be part of MOTD, but that only seems to appear for login sessions through telnet or ssh, not a usual pts terminal)

 

any help would be greatly appreciated :)

 

*waits patiently for aru to pop his head in* :unsure:

Link to comment
Share on other sites

:lol:

 

Well, after you visited Steve Scrimpshire's links, I'm sure you'll be able to do what you wanted.

 

Just as an example here is my prompt code (nothing from another world); it is on my ~/.bashrc:

 

# Prompt

unset PROMPT_COMMAND

case $TERM in

   *term|rxvt)

      TERM=xterm 

      PS1="[e]2;u@h wae ~$ " 

     ;;

   *) PS1='u@h w$ ';;

esac

export PS1 TERM

 

You'll have to figure out what does that and when :mrgreen:

 

About your MOTD 'feature' this is what I do to remind me what should I have done and I must do soon (again, bashrc):

MOTD () { 

   TODOFILE="${HOME}/.TODO";

   [ -f $TODOFILE ] && ( echo "Tareas pendientes:";

       cat -n $TODOFILE ) 

       || echo "No hay tareas pendientes";

   echo ""

}



...



case "$(tty)" in

   *pts*) MOTD;;

   *vc*) MOTD;; 

#   "not a tty") :;;

   *) :;;

esac

Link to comment
Share on other sites

This is the one I like in my ~/.bashrc file:

if [ "$TERM" = "linux" ]

then

 #we're on the system console or maybe telnetting in

 export PS1="[e[32;1m]u@H > [e[0m]"

else

export PS1="[e]2;u   w   dae[32;1m]$[e[0m] "

fi

 

In my /root/.bashrc:

if [ "$TERM" = "linux" ]

then

 #we're on the system console or maybe telnetting in

 export PS1="[e[32;1m]u@H > [e[0m]"

else

export PS1="[e]2;u   w   dae[31;1m]#[e[0m] "

fi

 

The reason there is a conditional statement is if you are in a virtual terminal or telnetting in, you won't have a title bar and the export PS1 with the titlebar stuff gives you annoying console beeps when you type.

It makes my prompt green for my regular user and red for root. It puts all that extra stuff (username, full working directory, and date) in the titlebar, so I have more room for words in the terminal.

Link to comment
Share on other sites

  • 2 months later...
note to self, remember to use google  :banghead:  

 

what can i say, i got lazy

 

Don't worry, you're the board slacker aren't you??

 

Oh wait have you lost your slacker status?

 

And those links are great, especially the autogenerator. Thanks!

 

James

Link to comment
Share on other sites

About your MOTD 'feature' this is what I do to remind me what should I have done and I must do soon  (again, bashrc):

<!--QuoteEBegin--><!--QuoteEBegin-->MOTD () { <!--QuoteEBegin--><!--QuoteEBegin-->    TODOFILE="${HOME}/.TODO";<!--QuoteEBegin--><!--QuoteEBegin-->    [ -f $TODOFILE ] && ( echo "Tareas pendientes:";<!--QuoteEBegin--><!--QuoteEBegin-->        cat -n $TODOFILE ) <!--QuoteEBegin--><!--QuoteEBegin-->        || echo "No hay tareas pendientes";<!--QuoteEBegin--><!--QuoteEBegin-->    echo ""<!--QuoteEBegin--><!--QuoteEBegin-->}<!--QuoteEBegin--><!--QuoteEBegin--><!--QuoteEBegin--><!--QuoteEBegin-->...<!--QuoteEBegin--><!--QuoteEBegin--><!--QuoteEBegin--><!--QuoteEBegin-->case "$(tty)" in<!--QuoteEBegin--><!--QuoteEBegin-->    *pts*) MOTD;;<!--QuoteEBegin--><!--QuoteEBegin-->    *vc*) MOTD;; <!--QuoteEBegin--><!--QuoteEBegin-->#   "not a tty") :;;<!--QuoteEBegin--><!--QuoteEBegin-->    *) :;;<!--QuoteEBegin--><!--QuoteEBegin-->esac<!--QuoteEBegin--><!--QuoteEBegin-->

 

Well, I've just noticed this thread after rcxau's bump, so as I've evolved my MOTD since my last post, here is what I do now.

 

I'm using the gnomecal program as my 'agenda', but I want to know which are the jobs to be done during the day w/o having to open gnomecal each time. So which moment is better to have a reminder than when I login or when I just open a new terminal.

 

Calling gnomecal with --events or --todo will in some manner do the trick, but only under X. As I wanted a bit more formated output and, ofcourse, the reminder output even when I'm not in X, here is what I do:

 

In my ~/.bashrc I have:

MOTD () {

   # Jobs to be done during the day (programed in gnomecal).

   # If we aren't in X don't call gnomecal, just proccess it's archive directly using ~/bin/cal.py

   if [ "$DISPLAY" == "" ]; then

       ~/bin/cal.py # runs old_but_modified agenda script.

       return $?    # exit the function

   fi



   # If we are under X, use complet output, events + TODOs;)

   EVENTOS=$(gnomecal --events)

   TAREAS=$(gnomecal --todo)



   if [ "${EVENTOS}" != "" ]; then

       printf "Tareas programadas para hoy:n----------------------------n"

       echo "$EVENTOS" | python <(cat <<- EOF

import re,sys

#findall genera una lista de tuples (hora_i, hora_f, resumen) xa cada evento.

for evento in re.findall('([0-9:]+) -- ([0-9:]+)n[ ]*(.*)n',sys.stdin.read()):

       print "[%s-%s] %s" % (evento)

EOF

       ); echo 

   else

       printf "No hay nada programado para hoy.nn"

   fi

   if [ "${TAREAS}" != "" ]; then

       printf "TODO:n-----n%snn" "$TAREAS"

   fi

}



[...]



case "$(tty)" in

   *pts*) MOTD;; # Terminal Virtual

   *vc*) MOTD;; # Consola Virtual

#   "not a tty") :;;

   *) :;;

esac

 

When I'm not under X (no clean way to launch gnomecal), the called script is ~/bin/cal.py:

 

#! /usr/bin/python

"""Saca por pantalla las tareas programadas para el dia.



Usa fichero tipo gnomecal



PROTOTIPO



$Id: cal.py,v 1.2 2003/07/17 13:56:26 aru Exp aru $"""

import time, re



def decode(data):

   """Decodifica unos caracteres horribles que salen en el output normal

   

   La codifcación es: =F3 que en python equivale a xf3, osease: ó

   TODO: reescribir esto de manera más elegante

   """

   chars={ '=E1':'á', '=E9':'é', '=ED':'í', '=F3':'ó', '=FA':'ú', 

           '=C1':'Á', '=C9':'É', '=CD':'Í', '=D3':'Ó', '=DA':'Ú',

           '=F1':'ñ', '=D1':'Ñ', '=0A':'r' }



   for key in chars.keys():

       if data.find(key) > -1:

           data=re.sub(key, chars[key], data)



   return data



def listEvents(data):

   """Genera listado de eventos gnomecal desde datos leidos de gnomecal"""

   

   all_eventos = []

   ev_ini, ev_fin = "BEGIN:VEVENT", r"END:VEVENT" # inicio y final de evento.

   RE = re.compile(ev_ini+r'.*?'+ev_fin, re.S|re.M|re.I)



   all_eventos = re.findall(RE,data) # listado de TODOS los eventos.

   return all_eventos



def selectEvents(data, regex):

   """Selecciona en función de regex datos del listado de eventos"""



   eventos = []

   for evento in listEvents(data):  # selecciona evento segun regex.

       if evento.find(regex) > -1:

           eventos.append(formatEvent(evento))  # formato de salida.

   eventos.sort()

   return eventos

   

def formatEvent(evento):

   """Transforma un evento gnomecal en la salida YYYYMMDD [HH:MM] resumen"""

   # Formatos de salida (output): 

   o_str = "%s-%s %s"

   o_hora_i, o_hora_f = "%Y%m%d [%H:%M", "%H:%M]"

   

   evento=decode(evento)

   

   # DATE => time tuple:

   date_fmt = '%Y%m%dT%H%M%S'

   re_horas = re.compile('DTSTART:(.*T.*)rnDTEND:(.*T.*)r')

   hora_i, hora_f = re.findall(re_horas, evento)[0]

   HORAi = time.strptime(hora_i, date_fmt)

   HORAf = time.strptime(hora_f, date_fmt)

   

   # Resumen evento:

   re_resumen_ev=re.compile("SUMMARY.*?:(.*?)r")

   resumen=''.join(re.findall(re_resumen_ev, evento))



   if len(resumen) > 60:

       resumen = resumen[:60] + "..."

   return o_str % (time.strftime(o_hora_i, HORAi),

                   time.strftime(o_hora_f, HORAf),        

                   resumen) 



def tareasSi(listado):

   """Output cuando hay tareas para hoy."""

   

   HOY=time.strftime("%d-%m-%Y")

   head = "Tareas programadas para hoy (%s):" % HOY

   print head+'n'+'-'*len(head)

   for item in listado:

       print item[9:]

   print



def tareasNo():

   """Output cuando no hay tareas para hoy."""

   

   print "No hay tareas programadas para hoy."

   

if __name__ == "__main__":

   FILE="/home/aru/.gnome/user-cal.vcf"  # fichero formato gnomecal

   reHOY=time.strftime("DTSTART:%Y%m%dT") # formato yyyymmddT (gnomecal)



   # abrimos y leemos el fichero

   buffer=open(FILE,'r')

   caldata=buffer.read()

   buffer.close()



   EVENTOS=selectEvents(caldata, reHOY)

   if len(EVENTOS) > 0: # Hay tareas programadas?

       tareasSi(EVENTOS)

   else:

       tareasNo()

 

Here are a couple of output examples:

 

In an xterm:

Tareas programadas para hoy:

----------------------------

[08:30-09:00] Visitar Cruzcampo S.A.

[10:30-11:00] Preparar dossier ayuntamiento.

[15:00-15:30] Comida con jefes



TODO:

-----

[aru]: Hacer listado de empresas



~$

 

On a console:

 

Mandrake Linux release 8.1 (Vitamin) para ChitiPC (i586)

Kernel 2.4.19-35mdk on an i586 / tty1

chitipc login: aru

Password:

Last login: Wed Aug 13 12:52:30 on :0

You have new mail.

Tareas programadas para hoy (13-08-2003):

-----------------------------------------

[08:30-09:00] Visitar Cruzcampo S.A.

[10:30-11:00] Preparar dossier ayuntamiento.

[15:00-15:30] Comida con jefes



~$

 

Any suggestions are wellcome

Link to comment
Share on other sites

  • 11 months later...
  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...