2023-05-14 17:24:43 +00:00
|
|
|
#!/bin/sh
|
2021-10-10 21:27:55 +00:00
|
|
|
|
|
|
|
calc() {
|
2024-11-03 23:36:22 +00:00
|
|
|
res="$(echo "$1" | bc 2>/dev/null)"
|
2024-11-03 01:59:02 +00:00
|
|
|
if [ "$res" == "" ]; then
|
|
|
|
res="-"
|
|
|
|
fi
|
|
|
|
echo "$res"
|
2021-10-10 21:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if [[ -z "$@" ]]; then
|
2024-11-03 01:59:02 +00:00
|
|
|
echo "^= .*$"
|
2021-10-10 21:27:55 +00:00
|
|
|
elif [[ "$1" == "--hint" ]]; then
|
2024-11-03 01:59:02 +00:00
|
|
|
shift
|
|
|
|
echo "- = "
|
2021-10-10 21:27:55 +00:00
|
|
|
elif [[ "$1" == "--complete" ]]; then
|
2024-11-03 01:59:02 +00:00
|
|
|
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
|
2024-11-03 01:59:02 +00:00
|
|
|
shift
|
|
|
|
echo "$1"
|
2021-10-10 21:27:55 +00:00
|
|
|
elif [[ "$1" == "--run" ]]; then
|
2024-11-03 01:59:02 +00:00
|
|
|
shift
|
2024-11-20 07:08:16 +00:00
|
|
|
echo "$2"
|
|
|
|
echo "$2" | (setsid -f wl-copy)
|
2021-10-10 21:27:55 +00:00
|
|
|
elif [[ "$1" == "--cli" ]]; then
|
2024-11-03 01:59:02 +00:00
|
|
|
shift
|
2024-11-03 23:36:22 +00:00
|
|
|
calc "$(echo "$@" | cut -d ' ' -f2-)"
|
2021-10-10 21:27:55 +00:00
|
|
|
else
|
2024-11-03 01:59:02 +00:00
|
|
|
echo "Unexpected arguments: $@"
|
2021-10-10 21:27:55 +00:00
|
|
|
fi
|