Skip to content

Instantly share code, notes, and snippets.

@d8660091
Last active August 29, 2015 14:16
Show Gist options
  • Save d8660091/1652c761fa47debbb76a to your computer and use it in GitHub Desktop.
Save d8660091/1652c761fa47debbb76a to your computer and use it in GitHub Desktop.
#!/bin/bash
tmpfile=`mktemp` # name for temp file in /tmp
tmux pipe-pane -t matlab:matlab -o "cat > $tmpfile"
while read line
do
line=${line//;/\\;} # replace ; with \; to pass send-keys of tmux
tmux send-keys -l -t matlab:matlab "$line" # send keys literaly
tmux send-keys -t matlab:matlab Enter
sleep 0.2s # wait until the commands are put to tmux
done
notFinished="1" # wait until commands are executed
while [ $notFinished -eq 1 ]
do
A=`awk '/./{line=$0} END{print line}' $tmpfile` # get last line
if [ A==">> " ]
then
notFinished=0
fi
done
sed -e '/^>>\s*$/d' $tmpfile | # remove >> empty line
sed -e '/^.*;\s*$/d' # remove the lines ended with ;
tmux pipe-pane -t matlab:matlab -o #close tmux's pipe
rm $tmpfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment