Tag Archives: bash

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>

rxvt-unicode with 256 colors

# Make a place for rxvt-unicode
mkdir rxvt-unicode
cd rxvt-unicode/
 
# Get the source
apt-get source rxvt-unicode
cd rxvt-unicode-8.4/
 
# Apply 256 color patch, it's included with the source
patch -p1 < doc/urxvt-8.2-256color.patch
 
# Make sure you have all depdencies to build it
sudo apt-get build-dep rxvt-unicode
 
# Build it
dpkg-buildpackage -us -uc -rfakeroot

This will build 3 packages.

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
 }