fix shitty bugs, fuck shell script they piss me off
This commit is contained in:
28
play.sh
28
play.sh
@@ -1,16 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
FILE="$1"
|
||||
[[ -f "$FILE" ]] || { echo "Usage: $0 <file>"; exit 1; }
|
||||
|
||||
STATE="$HOME/.soundboard"
|
||||
mkdir -p "$STATE"
|
||||
|
||||
# Check if the soundboard is started
|
||||
if [[ ! -f "$STATE/remap.id" ]]; then
|
||||
echo "Soundboard not started"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
FILE="$1"
|
||||
if [[ -z "$FILE" || ! -f "$FILE" ]]; then
|
||||
echo "Usage: $0 <audio-file>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DEFAULT_SINK=$(pactl get-default-sink)
|
||||
|
||||
# Start paplay processes in foreground
|
||||
# Store PIDs so we can clean up
|
||||
paplay --device=soundboard_sink "$FILE" &
|
||||
PID_MIC=$!
|
||||
|
||||
@@ -20,11 +27,14 @@ PID_OUT=$!
|
||||
# Trap signals to stop both outputs if script is killed
|
||||
trap "kill $PID_MIC $PID_OUT 2>/dev/null" EXIT INT TERM
|
||||
|
||||
# Register this process in PID file for stop_all.sh
|
||||
echo $$ >> "$STATE/playing.pids"
|
||||
# Register paplay PIDs for stop_all.sh
|
||||
mkdir -p "$STATE"
|
||||
echo "$PID_MIC" >> "$STATE/playing.pids"
|
||||
echo "$PID_OUT" >> "$STATE/playing.pids"
|
||||
|
||||
# Wait for both streams to finish
|
||||
wait $PID_MIC $PID_OUT
|
||||
|
||||
# Remove from PID file when done
|
||||
sed -i "\|^$$\$|d" "$STATE/playing.pids"
|
||||
# Remove these PIDs from PID file when done
|
||||
sed -i "\|^$PID_MIC\$|d" "$STATE/playing.pids"
|
||||
sed -i "\|^$PID_OUT\$|d" "$STATE/playing.pids"
|
||||
|
||||
Reference in New Issue
Block a user