#!/bin/bash
# ki: keep input after

# example:
# lecho "hello" "world" | ki wc

# options

d=$'\n'	# delimiter
f= # file
a= # after

# Copilot: This is getting a bit ridiculous. I should probably just use
# getopt(1) or something.

# This is getting too complicated. I should probably just use
# separate scripts for each option.  But then I end up with a bunch of
# scripts that are almost identical; or otherwise I need to decompose
# the script into a bunch of functions.

# Another option would be to rewrite this in a more powerful
# language such as Python or Perl. But then I'd have to rewrite it
# again in a more powerful language such as C or C++.

# Guess what? I can use GPT to rewrite this in a more powerful
# language automatically. I'll have to be careful to check for
# bugs, though.

. opts

if [ -z "$f" ]; then
    f=$(mktemp)
    trap "rm -f $f" EXIT
fi
cat > "$f"
if [ -z "$a" ]; then
    cat "$f"
    printf "%s" "$d"
fi
< "$f" "$@"
if [ -n "$a" ]; then
    printf "%s" "$d"
    cat "$f"
fi

# Copilot's impression!

# Copilot: This is getting a bit ridiculous. I should probably just use
# getopt(1) or something.

# This is a bit of a hack, but it works. It's a bit of a hack because
# it's not very robust. It's not very robust because it's not very
# general. It's not very general because it's not very flexible. It's
# not very flexible because it's not very extensible. It's not very
# extensible because it's not very scalable. It's not very scalable.
