Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions pkg/click/click
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
SCRIPT_NAME=$(basename "$0")
CLICK_CMD="$SCRIPT_DIR/click-format"
# Determine OS
OS_NAME="$(uname -s)"
# Set netcat options based on OS
if [[ "$OS_NAME" == "Darwin" ]]; then
NC_OPTS="-U"
else
# For Linux and others where -W is supported
NC_OPTS="-U -W 1"
fi

# ==========================================================
# VARIABLES
Expand Down Expand Up @@ -69,7 +78,7 @@ EOF
full() {
$CLICK_CMD "$HOON" $DEPS |
$EVAL_CMD eval --jam $JAM_OPTS |
nc -U -W 1 "$PIER/.urb/conn.sock" |
nc $NC_OPTS "$PIER/.urb/conn.sock" |
$EVAL_CMD eval --cue $CUE_OPTS
}

Expand All @@ -82,7 +91,7 @@ jam() {
}

execute() {
nc -U -W 1 "$PIER/.urb/conn.sock" < $INPUT |
nc $NC_OPTS "$PIER/.urb/conn.sock" < $INPUT |
$EVAL_CMD eval --cue $CUE_OPTS
}

Expand Down Expand Up @@ -201,7 +210,10 @@ if [[ -n $INPUT ]]; then

if [[ $EXECUTE -eq 0 ]]; then
# read from file, escape 's, replace newlines w/ gaps
HOON="$(cat $INPUT | sed "s;';\\\\';g" | sed ':a;N;s/\n/ /;$!ba')"
# Previous approach, only works on Linux
# HOON="$(cat $INPUT | sed "s;';\\\\';g" | sed ':a;N;s/\n/ /;$!ba')"
# New approach, works on Linux and macOS
HOON="$(cat $INPUT | sed "s/'/\\\\'/g" | tr '\n' ' ')"
Comment on lines +213 to +216
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be gated by OS; tr doesn't correctly replace newlines on Linux

fi
else
PIER=$1
Expand All @@ -223,7 +235,13 @@ if [[ -z $EVAL_CMD ]]; then
fi
JAM_OPTS="-n"
CUE_OPTS="-n"
TMP_OUT=`mktemp -q --tmpdir`
if [[ "$OS_NAME" == "Darwin" ]]; then
# For macOS
TMP_OUT=$(mktemp -q /tmp/click.XXXXXX)
else
# For Linux and others
TMP_OUT=$(mktemp -q --tmpdir)
fi

if [[ $JAM_ONLY -eq 0 ]]; then
if [[ $FILTER_GOOF -ne 0 ]]; then
Expand Down
2 changes: 1 addition & 1 deletion pkg/click/click-format
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ while getopts ":hk" OPT; do
\?)
echo "Invalid option: -$OPTARG" >&2
STATUS=1
;&
;;
h)
show_help
exit "$STATUS"
Expand Down