lilalo

annotate l3bashrc @ 80:d28dda8ea18f

1)
Изменён формат имени diff-файлов.
Теперь в имени присутствует только название сессии, время и имя файла.

2)
Можно просмотреть отдельную сессию.
Для этого нужно щёлкнуть по блоку сессии в журнале

3)
Исправлена ошибка с таблицей новых команд в последнем дне.
Раньше она просто не показывалась

4)
Запись lablog-ов теперь ведётся только для интерактивных shell'ов
Неинтерактивные работают как обычно.
author devi
date Mon Feb 20 17:52:40 2006 +0200 (2006-02-20)
parents 44973d76ba4d
children 9f64b4cfa4f6
rev   line source
devi@70 1 #!/bin/sh
devi@70 2
devi@70 3
devi@76 4 # Environment variables set by the script:
devi@76 5 #
devi@76 6 # L3_SESSION_ID - uniq id of the LiLaLo-session
devi@76 7 # L3_PARENT_TTY - name of tty on which script is running
devi@76 8 # PS1 - intercative shell prompt in which LiLaLo hides
devi@76 9 # various information about the command
devi@76 10 # L3_TAMPERED_EDITORS - list of editors which are tampered with functions
devi@76 11
devi@76 12
devi@76 13 # Functions with the names starting _l3_ are internal.
devi@76 14 # Such functions are unset before this rc script exits
devi@76 15
devi@76 16 _l3_editors_to_tamper='/bin/vi /usr/bin/vi /usr/bin/vim /bin/ee /usr/bin/ee /usr/bin/pico /usr/bin/nano /usr/local/bin/vim'
devi@76 17
devi@70 18 _l3_start()
devi@70 19 {
devi@80 20 echo $- | grep -q i || return 0
devi@79 21 if _l3_is_running_here
devi@76 22 then
devi@76 23 _l3_env
devi@76 24 _l3_init_prompt
devi@76 25 l3_fix_prompt
devi@76 26 _l3_tamper_editors
devi@76 27 _l3_tamper_commands
devi@76 28 _l3_unset_internal
devi@79 29 else
devi@79 30 _l3_start_session
devi@79 31 _l3_run_script
devi@76 32 fi
devi@76 33 }
devi@76 34
devi@76 35 # ===================== STAGE 1 ============================
devi@76 36
devi@79 37 _l3_is_running_here()
devi@76 38 {
devi@79 39 ps waux | awk '{print $2" "$11 }' | grep -q ^$PPID" "script
devi@79 40 return $?
devi@79 41
devi@79 42 # Check if ^^^^ run on Linux
devi@79 43 # and del vvvv this if it does
devi@79 44
devi@76 45 export L3_TTY=`/usr/bin/tty`
devi@79 46 uname -a | grep -qi bsd && bsd=yes
devi@70 47 proc_on_the_term=`w | grep "${L3_TTY##/dev/}" | awk '{print $8;}'`
devi@70 48 # freeBSD:
devi@70 49 [ -n "$bsd" ] && \
devi@70 50 proc_on_the_term=`w | grep "${L3_TTY##/dev/tty}" | awk '{print $6;}'`
devi@70 51
devi@79 52 [ -n "$proc_on_the_term" ] && echo $proc_on_the_term | grep -q script
devi@70 53 }
devi@70 54
devi@70 55 _l3_start_session()
devi@70 56 {
devi@79 57 export L3_SESSION_ID=${RANDOM}${RANDOM}${RANDOM}${RANDOM}-`date +%s`
devi@71 58 export L3_HOME=~/.lilalo/
devi@70 59 mkdir -p $L3_HOME
devi@70 60
devi@79 61 tty=`/usr/bin/tty`
devi@70 62 uname -a | grep -qi bsd && bsd=yes
devi@70 63 parent=`cat /proc/$PPID/cmdline 2> /dev/null`
devi@79 64 [ -z "$parent" ] && parent="`ps waux | awk '{if ($2 == '$PPID') print $11; }'`"
devi@70 65 system=`uname -rs`
devi@79 66 login_from=`who | grep "${tty##/dev/}" | awk '{print $6;}' | tr -d '()'`
devi@70 67 #[ -n "$bsd" ] && login_from="" #FIXME!
devi@70 68 start_time=`date +%s`
devi@70 69 hostname=`hostname -f 2> /dev/null`
devi@70 70 [ -n "$bsd" ] && hostname=`hostname`
devi@70 71
devi@70 72 cat <<INFO > $L3_HOME/$L3_SESSION_ID.info
devi@70 73 <session>
devi@70 74 <local_session_id>$L3_SESSION_ID</local_session_id>
devi@70 75 <hostname>$hostname</hostname>
devi@70 76 <user>$USER</user>
devi@70 77 <uid>$UID</uid>
devi@70 78 <login_from>$login_from</login_from>
devi@79 79 <tty>$tty</tty>
devi@70 80 <system>$system</system>
devi@70 81 <parent>$parent</parent>
devi@70 82 <ppid>$PPID</ppid>
devi@70 83 <pid>$$</pid>
devi@70 84 <start_time>$start_time</start_time>
devi@76 85 <lang>$LANG</lang>
devi@70 86 </session>
devi@70 87 INFO
devi@70 88
devi@79 89 unset parent system login_from start_time hostname tty
devi@70 90 }
devi@70 91
devi@70 92 _l3_run_script()
devi@70 93 {
devi@70 94 uname -a | grep -qi bsd && bsd=yes
devi@70 95 flush="-f" #linux
devi@70 96 [ -n "$bsd" ] && flush="-t 0" #freebsd
devi@76 97 export L3_PARENT_TTY=`/usr/bin/tty`
devi@70 98 exec script $flush -q $L3_HOME/${L3_SESSION_ID}.script
devi@70 99 }
devi@70 100
devi@76 101 # ===================== STAGE 2 ============================
devi@76 102
devi@76 103 _l3_env()
devi@76 104 {
devi@76 105 trap l3_close_session 2
devi@76 106 trap l3_close_session EXIT
devi@76 107 true
devi@76 108 }
devi@76 109
devi@76 110 l3_close_session()
devi@70 111 {
devi@71 112 (
devi@71 113 echo '<history>'
devi@71 114 history | sed 's/&/\&amp;/; s/</\&lt;/g; s/>/\&gt;/g'
devi@71 115 echo '</history>'
devi@71 116 ) >> $L3_HOME/$L3_SESSION_ID.info
devi@70 117 }
devi@70 118
devi@76 119 _l3_init_prompt()
devi@76 120 {
devi@76 121 PS1='[\u@\h:\W]\$ '
devi@77 122 [ $UID = 0 ] \
devi@77 123 && PS1='\[\033[0;31m\]'$PS1'\[\033[0m\]' \
devi@77 124 || PS1='\[\033[0;32m\]'$PS1'\[\033[0m\]' \
devi@76 125 export PS1
devi@76 126 }
devi@76 127
devi@76 128 l3_fix_prompt()
devi@76 129 {
devi@76 130 export PS1='\[v2#\!#$?#$UID#$$#$(/bin/date +%s)#$PWD#\033[1024D\033[K\]'$PS1
devi@76 131 }
devi@76 132
devi@76 133 _l3_tamper_editors()
devi@76 134 {
devi@76 135 for editor_file in $_l3_editors_to_tamper
devi@76 136 do
devi@76 137 [ -x $editor_file ] || continue
devi@76 138 editor_name=${editor_file##*/}
devi@76 139 eval "
devi@76 140 $editor_name() {
devi@76 141 if [ -d \"\$1\" ]
devi@76 142 then
devi@76 143 $editor_file \"\$1\"
devi@76 144 return \$?
devi@76 145 else
devi@76 146 TIME=\"\`date +%s\`\"
devi@76 147 DIR=\"\"
devi@76 148 [ \"\${1#/}\" = \"\$1\" ] && DIR=\"\$PWD/\"
devi@80 149 DIFFNAME=\"\${L3_SESSION_ID}_\${TIME}\`echo \$DIR\$1| sed s@_@__@ | sed 's@/@_@g'\`.diff\"
devi@76 150 old_file=\"/tmp/l3-saved-\$\$.\$RANDOM.\$RANDOM\"
devi@76 151 /bin/cp -- \"\$1\" \"\$old_file\" 2> /dev/null
devi@76 152 $editor_file \"\$@\" || ERR=\$?
devi@80 153 [ -e \"\$old_file\" ] && diff \"\$old_file\" \"\$1\" > \"\$L3_HOME/\$DIFFNAME\" 2> /dev/null
devi@80 154 if [ "$?" == 2 ]
devi@80 155 then
devi@80 156 diff /dev/null \"\$1\" > \"\$L3_HOME/\$DIFFNAME\" 2> /dev/null
devi@80 157 fi
devi@76 158 /bin/rm \"\$old_file\" 2> /dev/null
devi@76 159 return \$ERR
devi@76 160 fi
devi@76 161 }
devi@76 162 "
devi@76 163 L3_TAMPERED_EDITORS="$L3_TAMPERED_EDITORS $editor_name"
devi@76 164 done
devi@76 165 [ -n "$L3_TAMPERED_EDITORS" ] && export L3_TAMPERED_EDITORS
devi@76 166 }
devi@76 167
devi@76 168 _l3_tamper_commands()
devi@76 169 {
devi@76 170 tty()
devi@76 171 {
devi@76 172 [ -n "$L3_PARENT_TTY" ] && echo $L3_PARENT_TTY || /usr/bin/tty
devi@76 173 }
devi@76 174 }
devi@76 175
devi@76 176 _l3_unset_internal()
devi@76 177 {
devi@76 178 unset `set | grep '^_l3_.*()' | sed 's/()//'`
devi@76 179 unset `set | grep '^_l3_.*=' | sed 's/=.*//'`
devi@76 180 }
devi@78 181
devi@78 182
devi@78 183 l3shot()
devi@78 184 {
devi@78 185 if [ -x "`which xwd`" ]
devi@78 186 then
devi@78 187 _l3_home=${L3_HOME:-~/.lilalo}
devi@78 188 shot_name="${L3_SESSION_ID}_`date +%s`".xwd
devi@78 189 echo -n Choose window to be shoot ... >&2
devi@78 190 [ -d ${_l3_home} ] || mkdir -p ${_l3_home}
devi@78 191 xwd -out "$_l3_home/$shot_name" \
devi@78 192 && echo Ok\
devi@78 193 && echo Shot was successful. \
devi@78 194 && echo Screenshot is written to ${_l3_home}/${shot_name} \
devi@78 195 && echo Screenshot will appears in the lablog.
devi@78 196 else
devi@78 197 {
devi@78 198 echo
devi@78 199 echo "Can't make screenshot :("
devi@78 200 echo
devi@78 201 echo I must use program xwd to make screenshot,
devi@78 202 echo but it seems not to be installed
devi@78 203 echo Try to find the program in the \"xbase-clients\" package
devi@78 204 echo
devi@78 205 } >&2
devi@78 206 fi
devi@78 207 }