My Cyberpatriot scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
384 B

#!/bin/bash
HISTFILE="$1"; shift 1
if [[ "$1" == "-f" ]]; then
# lazy getopt
TARGETFUNC="$2"
shift 2
else
TARGETFUNC=
fi
HEADLINES="${1:-1}"
FCLINES=$((HEADLINES + 1))
COMMANDS="$(fc -ln "-${FCLINES}" | head "-${HEADLINES}")"
# echo "$COMMANDS"
if [[ -z "$TARGETFUNC" ]]; then
eval "$COMMANDS"
else
eval "function $TARGETFUNC {
$COMMANDS
}"
fi