lilalo
annotate l3bashrc @ 71:d499fa3b2af1
Na lilalo@moskau.xt.vpn uspeshno zavelos i\
zarabotalo. + Sohranenie istorii pri vyhode
zarabotalo. + Sohranenie istorii pri vyhode
author | devi |
---|---|
date | Sat Feb 04 00:47:22 2006 +0200 (2006-02-04) |
parents | 6f5ad37fc8d9 |
children | 0ffdebbccfce |
rev | line source |
---|---|
devi@70 | 1 #!/bin/sh |
devi@70 | 2 |
devi@70 | 3 |
devi@70 | 4 _l3_start() |
devi@70 | 5 { |
devi@70 | 6 L3_TTY=`tty` |
devi@70 | 7 proc_on_the_term=`w | grep "${L3_TTY##/dev/}" | awk '{print $8;}'` |
devi@70 | 8 # freeBSD: |
devi@70 | 9 [ -n "$bsd" ] && \ |
devi@70 | 10 proc_on_the_term=`w | grep "${L3_TTY##/dev/tty}" | awk '{print $6;}'` |
devi@70 | 11 |
devi@70 | 12 if [ -n "$proc_on_the_term" ] && echo $proc_on_the_term | grep -qv script |
devi@70 | 13 then |
devi@70 | 14 _l3_start_session |
devi@70 | 15 _l3_run_script |
devi@70 | 16 else |
devi@70 | 17 _l3_env |
devi@70 | 18 _l3_prompt |
devi@70 | 19 fi |
devi@70 | 20 } |
devi@70 | 21 |
devi@70 | 22 _l3_env() |
devi@70 | 23 { |
devi@71 | 24 trap _l3_close_session 2 |
devi@71 | 25 trap _l3_close_session EXIT |
devi@70 | 26 true |
devi@70 | 27 } |
devi@70 | 28 |
devi@70 | 29 _l3_prompt() |
devi@70 | 30 { |
devi@70 | 31 export PS1='\[` |
devi@70 | 32 a="$?"; |
devi@70 | 33 HIDDEN=$([ "$a" = 0 ] || echo -n ^"$a")$(echo -n _${UID}_)$(echo -n _$$_)$(date\ |
devi@70 | 34 +"%j$(cat ${LMHOME}/lab 2>/dev/null) %H:%M:%S"); |
devi@70 | 35 echo $HIDDEN`\033[50D\033[K\][\u@\h:\W]\$ ' |
devi@70 | 36 } |
devi@70 | 37 |
devi@70 | 38 _l3_start_session() |
devi@70 | 39 { |
devi@71 | 40 export L3_SESSION_ID=${L3_TTY##*/}-$$ |
devi@71 | 41 export L3_HOME=~/.lilalo/ |
devi@70 | 42 mkdir -p $L3_HOME |
devi@70 | 43 |
devi@70 | 44 uname -a | grep -qi bsd && bsd=yes |
devi@70 | 45 parent=`cat /proc/$PPID/cmdline 2> /dev/null` |
devi@70 | 46 system=`uname -rs` |
devi@70 | 47 login_from=`who | grep "${tty##/dev/}" | awk '{print $6;}' | tr -d '()'` |
devi@70 | 48 #[ -n "$bsd" ] && login_from="" #FIXME! |
devi@70 | 49 start_time=`date +%s` |
devi@70 | 50 hostname=`hostname -f 2> /dev/null` |
devi@70 | 51 [ -n "$bsd" ] && hostname=`hostname` |
devi@70 | 52 |
devi@70 | 53 cat <<INFO > $L3_HOME/$L3_SESSION_ID.info |
devi@70 | 54 <session> |
devi@70 | 55 <local_session_id>$L3_SESSION_ID</local_session_id> |
devi@70 | 56 <hostname>$hostname</hostname> |
devi@70 | 57 <user>$USER</user> |
devi@70 | 58 <uid>$UID</uid> |
devi@70 | 59 <login_from>$login_from</login_from> |
devi@70 | 60 <tty>$tty</tty> |
devi@70 | 61 <system>$system</system> |
devi@70 | 62 <parent>$parent</parent> |
devi@70 | 63 <ppid>$PPID</ppid> |
devi@70 | 64 <pid>$$</pid> |
devi@70 | 65 <start_time>$start_time</start_time> |
devi@70 | 66 </session> |
devi@70 | 67 INFO |
devi@70 | 68 |
devi@70 | 69 unset parent system login_from start_time hostname |
devi@70 | 70 } |
devi@70 | 71 |
devi@70 | 72 _l3_run_script() |
devi@70 | 73 { |
devi@70 | 74 uname -a | grep -qi bsd && bsd=yes |
devi@70 | 75 flush="-f" #linux |
devi@70 | 76 [ -n "$bsd" ] && flush="-t 0" #freebsd |
devi@70 | 77 exec script $flush -q $L3_HOME/${L3_SESSION_ID}.script |
devi@70 | 78 } |
devi@70 | 79 |
devi@70 | 80 _l3_close_session() |
devi@70 | 81 { |
devi@71 | 82 ( |
devi@71 | 83 echo '<history>' |
devi@71 | 84 history | sed 's/&/\&/; s/</\</g; s/>/\>/g' |
devi@71 | 85 echo '</history>' |
devi@71 | 86 ) >> $L3_HOME/$L3_SESSION_ID.info |
devi@70 | 87 } |
devi@70 | 88 |