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
}
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">