File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -45,11 +45,29 @@ assert_cmd "$HEXDUMP"
4545assert_cmd " $BIN_GRAPH "
4646assert_cmd " $PASTE "
4747
48+ # Last argument must be the input file.
4849input_file=" ${*: -1} "
49- if [ ! -f " $input_file " ]; then
50- echo " $( basename " $0 " ) : Input file '${input_file} ' not found." 1>&2
51- exit 1
50+
51+ # Final string of arguments for 'bin-graph'.
52+ bin_graph_args=(" ${BIN_GRAPH_ARGS[@]} " " ${@: 1: $# -1} " )
53+
54+ # In order to redirect the standard input to both commands, it needs to be
55+ # buffered in a temporary file.
56+ if [ " $input_file " = " -" ]; then
57+ tmp_file=" $( mktemp --tmpdir " bin-graph-hexdump.XXXXX.bin" ) "
58+ cat " $input_file " > " $tmp_file "
59+ input_file=" $tmp_file "
5260fi
5361
62+ # Merge the output of the hexdump command with the ANSI-encoded output of
63+ # 'bin-graph'.
64+ #
65+ # FIXME: If the last hexdump line is partial, the output of 'bin-graph' is not
66+ # aligned.
5467" $PASTE " <( " $HEXDUMP " " ${HEXDUMP_ARGS[@]} " " $input_file " ) \
55- <( " $BIN_GRAPH " " ${BIN_GRAPH_ARGS[@]} " " $@ " ' -' )
68+ <( " $BIN_GRAPH " " ${bin_graph_args[@]} " " $input_file " ' -' )
69+
70+ # We are done with the temporary file, delete it.
71+ if [ -n " $tmp_file " ]; then
72+ rm " $tmp_file "
73+ fi
You can’t perform that action at this time.
0 commit comments