#!/bin/zsh DEBUG=1 function debugging { [[ ${+DEBUG} == 1 && ${DEBUG} == 1 ]] } function format_output { function arg_len { echo $1 | wc -c } heading_separator=": " prefix=${1}${heading_separator} prefix_len=`arg_len ${prefix}` if [[ ${+COLUMNS} == 1 ]]; then columns=${COLUMNS} else columns=80 fi terminal_position=0 first_argument=1 just_wrote_prefix=0 for each in $*; do if [[ ${first_argument} == 1 ]]; then first_argument=0 continue fi if [[ ${terminal_position} == 0 ]]; then echo -n ${prefix} just_wrote_prefix=1 fi token_len=`arg_len ${each}` ((terminal_position += token_len + 1)) if [[ ${terminal_position} > ${columns} ]]; then # If we just wrote the prefix, then we # have to write this token where it stands # even though it will wrap. if [[ ${just_wrote_prefix} == 1 ]]; then echo ${each} just_wrote_prefix=0 ((terminal_position = 0)) else echo -n "\n${prefix}${each} " ((terminal_position = prefix_len + token_len)) just_wrote_prefix=0 fi else echo -n "${each} " just_wrote_prefix=0 fi done echo } if debugging; then format_output DEBUG Executing \"${0} ${*}\" fi for each in test1 test2 test3; do echo "***each=${each}" if debugging; then format_output DEBUG press enter to continue: read fi echo "***each=${each}" done