q.sh/q-calc

34 lines
688 B
Text
Raw Normal View History

#!/bin/sh
2021-10-10 21:27:55 +00:00
calc() {
res="$(echo "$1" | bc 2>/dev/null)"
if [ "$res" == "" ]; then
res="-"
fi
echo "$res"
2021-10-10 21:27:55 +00:00
}
if [[ -z "$@" ]]; then
echo "^= .*$"
2021-10-10 21:27:55 +00:00
elif [[ "$1" == "--hint" ]]; then
shift
echo "- = "
2021-10-10 21:27:55 +00:00
elif [[ "$1" == "--complete" ]]; then
shift
EXPR="$(echo "$@" | cut -d ' ' -f2-)"
RES="$(calc "$EXPR")"
echo "$RES = $EXPR -> $(calc "$EXPR")"
2021-10-10 21:27:55 +00:00
elif [[ "$1" == "--preview" ]]; then
shift
echo "$1"
2021-10-10 21:27:55 +00:00
elif [[ "$1" == "--run" ]]; then
shift
echo "$1"
echo "$1" | (nohup wl-copy -n 2>/dev/null &)
2021-10-10 21:27:55 +00:00
elif [[ "$1" == "--cli" ]]; then
shift
calc "$(echo "$@" | cut -d ' ' -f2-)"
2021-10-10 21:27:55 +00:00
else
echo "Unexpected arguments: $@"
2021-10-10 21:27:55 +00:00
fi