Skip to content

Instantly share code, notes, and snippets.

@jexp
Last active May 18, 2016 17:44
Show Gist options
  • Save jexp/8213614 to your computer and use it in GitHub Desktop.
Save jexp/8213614 to your computer and use it in GitHub Desktop.
#!/bin/bash
# usage neo.sh [-h host:port] [-u user:pass] [cmd]
# end cypher statements with semicolon
# terminate read loop with ^d or return
HOST="localhost:7474"
if [ "$1" == "-h" ]; then
shift; HOST="$1";shift;
fi
AUTH=""
if [ "$1" == "-u" ]; then
shift; AUTH="-u $1";shift;
fi
URL="http://${HOST}/db/manage/server/console"
HEADERS=' -H accept:application/json -H content-type:application/json '
function run {
CMD="$@"
DATA="{\"command\":\"${CMD}\",\"engine\":\"shell\"}"
RES=`curl -s $HEADERS $AUTH -d "$DATA" "$URL"`
# bash substitution
RES=${RES#'[ "'}
PROMPT_PATTERN="\", \"neo4j-sh (*)$ \" ]"
RES=${RES%$PROMPT_PATTERN}
# continue reading, incomplete command
if [ "$RES" == "\", \"> \" ]" ]; then
return 1;
else
echo -e "${RES//\\\\n/\\n}"
return 0;
fi
}
P0="neo4j-sh (*)\$ "
if [ "$@" ]; then
run "$@";
exit $?
fi
read -p "$P0" CMD;
while [ "$CMD" ]; do
run "$CMD"
if [ $? == 0 ]; then
read -p "$P0" CMD;
else
#continue reading, incomplete command
read -p "> " CMD1;
CMD="${CMD} ${CMD1}"
fi
done
@levidamian
Copy link

I am running this as recommended.
However the result I am getting is ugly formatted (from Mac Terminal).
I am getting something like this:

Documents levi $ ./neo.sh -h ec2-54-155-80-181.eu-west-1.compute.amazonaws.com:7474 -u neo4j:woka "match (n) return count(n);"
+----------+\n| count(n) |\n+----------+\n| 2259 |\n+----------+\n1 row\n4 ms\n
Documents levi $

Is it here a way to get the result formatted like this?

+-----------+
| count (n) |
+-----------+
| 2259 |
+-----------+
1 row
13 ms

@levidamian
Copy link

Looks like the it was fixed by restarting my Mac.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment