Skip to content

Instantly share code, notes, and snippets.

@jxy
Created February 22, 2017 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jxy/88f2972d3994dfea06fd2d3833b7ac8a to your computer and use it in GitHub Desktop.
Save jxy/88f2972d3994dfea06fd2d3833b7ac8a to your computer and use it in GitHub Desktop.
#!/bin/bash
# Copyright (C) 2017 Xiao-Yong Jin
# MIT License [https://opensource.org/licenses/MIT]
set -ue
declare setup=""
declare read_statements=N
while (($# > 0)); do
case $1 in
-s)
setup="$2"; shift 2
;;
-p)
read_statements=Y; shift 1
;;
*)
break
;;
esac
done
if [[ $read_statements == Y ]]; then
read -e || true
declare -r plot="$REPLY"
else
# simply plot data from stdin
# use the command line as plot arguments
declare -r plot="plot '-' $@"
fi
case $(uname) in
Darwin)
declare -ai tty_size=( $(stty -f /dev/tty size) )
;;
*)
declare -ai tty_size=( $(stty -F /dev/tty size) )
;;
esac
#echo "Got setup ::: $setup"
#echo "Got plot ::: $plot"
declare -a gpversion
read -a gpversion < <(gnuplot --version | awk 'BEGIN{FS="[ .]"}{print $2,$3,$5}')
#echo "Got gnuplot version ${gpversion[0]}.${gpversion[1]}.${gpversion[2]}"
if ((${gpversion[0]} > 4)); then
setup="
set linetype 1 pt 'o';
set linetype 2 pt 'x';
set linetype 3 pt '*';
set linetype 4 pt '0';
set linetype 7 pt '^';
set linetype 5 pt 'c';
set linetype 6 pt 'v';
set linetype 8 pt 'u';
set linetype cycle 8;
$setup;"
fi
gnuplot -e \
"set term dumb $((tty_size[1]-2)),$((tty_size[0])) nofeed;
$setup;
$plot"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment