Bithon Update 1

# Probably one of many, this is more bash style in the logic statements and better handling of eos.

function launch_python {
  exec 3>&-
  exec 4<&-
  pyin=$(mktemp -u)
  pyot=$(mktemp -u)
  mkfifo $pyin
  mkfifo $pyot
  python -u -i <$pyin &>$pyot &
  pypid=$!
  exec 3> $pyin
  exec 4< $pyot
  rm $pyin
  rm $pyot
  echo print >&3
  while read -u 4 line && [ "${line}" != '>>>' ]
  do
    echo  "# ${line}"
  done
  echo 'import sys;sys.ps2=""' >&3
}

function py_read {
  local line
  while read -u 4 line && [ "${line}" != 'bithon-eos' ]
  do
    [ "${line}" == '>>>' ] && continue
    line="${line#>>> }"
    [ "${line}" == '>>>' ] && continue
    echo "${line#>>>}"
  done
}

function py {
  ( (echo "$@" >&3; echo "print '\nbithon-eos'" >&3)& )
  py_read
}

function _ppy {
  local line
  IFS=''
  while read line
  do
    echo "$line" >&3
  done
  echo >&3
  echo 'print "\nbithon-eos"' >&3
}

function ppy {
  ( _ppy <&0 & )
  py_read
}

function kill_python {
  exec 4<&-
  exec 3>&-
  kill -9 $pypid
}

Comments

Popular posts from this blog

oche, lik echo but a bit easier to use.

Bithon: Run Python Interactively Inside Bash

print, like echo but simpler and more consistent than oche