-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlilsound
More file actions
executable file
·54 lines (46 loc) · 1.15 KB
/
lilsound
File metadata and controls
executable file
·54 lines (46 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env bash
#
# Play a sound from lilsound.sounds/ folder.
#
# - No args: play the first sound in the folder.
# - With args: hash the input and choose a stable sound index.
#
# Usage:
#
# lilsound [<SEED-TEXT>...]
#
# Examples:
#
# lilsound
# lilsound 12345
# lilsound "finished tests"
#
# author: andreasl
set -euo pipefail
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
sound_dir="${script_dir}/lilsound.sounds"
shopt -s nullglob
all_entries=("${sound_dir}"/*)
shopt -u nullglob
sound_files=()
for entry in "${all_entries[@]}"; do
if [[ -f "${entry}" ]]; then
sound_files+=("${entry}")
fi
done
if ((${#sound_files[@]} > 1)); then
mapfile -t sound_files < <(printf '%s\n' "${sound_files[@]}" | LC_ALL=C sort)
fi
if ((${#sound_files[@]} == 0)); then
echo "Error: no sounds found in ${sound_dir}" >&2
exit 1
fi
if (($# == 0)); then
sound_index=0
else
input_text="$*"
checksum_output="$(printf '%s' "${input_text}" | cksum)"
checksum_value="${checksum_output%% *}"
sound_index=$((checksum_value % ${#sound_files[@]}))
fi
ffplay -nodisp -autoexit "${sound_files[${sound_index}]}" 2>/dev/null