bloggo ergo sum
msgbartop
msgbarbottom

28 Mar 07 ksh stuff

Below is a little code I use with ksh. The wt() function can only be expected to work in an X-term. The code sequences are different for other terminal emulators.

DIRSTACK=$PWD
function dirs {
  print $DIRSTACK
}
 
function pushd {
  dirname=$1
  cd ${dirname:?"missing directory name."}
  DIRSTACK="$PWD $DIRSTACK"
}
 
function popd {
  DIRSTACK=${DIRSTACK#* }
  top=${DIRSTACK%% *}
  cd $top
}
 
function rfind
{
  dir=$PWD
  while [ ! -e $1 ]; do
    if [ $PWD == "/" ]; then
      command cd $dir
      return 1
    else
      command cd ..
    fi
  done
 
  rfdir=$PWD
  command cd $dir
 
  return 0
}
 
function wt
{
  printf "ESC]0;${@/$HOME/'~'}^G"
}
 
function git_dir
{
  typeset str
  rfdir=""
  rfind '.git'
  if [ $? -eq 0  ]; then
    str="\{`git branch | grep '*' | cut -d ' ' -f 2`\}"
    wt "[${rfdir}${str}]"
  else
    wt "xterm"
  fi
 
  echo "$str"
}
 
function mkprompt
{
  typeset branch
 
  branch=`git_dir`
  PS1="${branch}$ "
}
 
function cd
{
  PS1="$ "
  command cd $@
  mkprompt
}

Tags: ,