Tag Archives: unix

logging with script

While you can log everything with screen’s logging functionality, or tee it to some file, you can also use script.

Script makes a typescript of everything printed on your terminal. It is useful for students who need a hardcopy record of an inter‐active session as proof of an assignment, as the typescript file can be printed out later with lpr(1).

% script foo
Script started, file is foo
% ps
  PID TTY          TIME CMD
11448 pts/3    00:00:00 zsh
11511 pts/3    00:00:00 ps
%
Script done, file is foo
 
% cat foo
Script started on Fri Jun 18 10:13:14 2010
% ps
  PID TTY          TIME CMD
11448 pts/3    00:00:00 zsh
11511 pts/3    00:00:00 ps
% <ctrl +d>
Script done on Fri Jun 18 10:13:25 2010                            
</ctrl>

.Xmodmap for my mac

keycode 63 = Alt_L
keycode 71 = Alt_R
keycode 66 = Super_L
keycode 69 = Super_R
clear mod1
clear mod2
add mod1 = Alt_L
add mod1 = Alt_R
add mod4 = Super_L
add mod4 = Super_R
keycode 75 = asterisk
keycode 77 = plus

Fire up xmodmap somewhere. .xinitrc or .bash_profile

bash prompt

bash_prompt_command() {
  # How many characters of the $PWD should be kept
  local pwdmaxlen=55
  # Indicate that there has been dir truncation
  local trunc_symbol=".."
  local dir=${PWD##*/}
  pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen ))
  NEW_PWD=${PWD/$HOME/~}
  local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen ))
  if [ ${pwdoffset} -gt "0" ]; then
   NEW_PWD=${NEW_PWD:$pwdoffset:$pwdmaxlen}
    NEW_PWD=${trunc_symbol}/${NEW_PWD#*/}
  fi
}
 
bash_prompt() {
  if [ -n "$PS1" ]; then
    PS1="$XTITLE""\033[01;32m\][\!][\u@]\[\033[01;34m\] \${NEW_PWD}\n     >\\$\[\033[00m\] "
  fi
 }