Skip to content

Commit f3f0801

Browse files
committed
give the user an affordance if run on the wrong file type
1 parent 6d26560 commit f3f0801

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

packages/srtcpy.nix

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ writeShellApplication {
33
name = "srtcpy";
44
text = builtins.readFile ./srtcpy.sh;
55
}
6+
# see https://hackage.haskell.org/package/subtitleParser

packages/srtcpy.sh

+5-11
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,19 @@ if [ -z "$1" ]; then
55
fi
66

77
filename="$1"
8+
srt_filename="${filename%.*}.srt" # Remove extension (if any) and append .srt
89

9-
# Check if the file has a .srt extension
10-
if [[ "$filename" != *.srt ]]; then
11-
echo "Error: File '$filename' is not a .srt file."
12-
exit 1
13-
fi
14-
15-
# Check if the file exists
16-
if [ ! -f "$filename" ]; then
17-
echo "Error: File '$filename' not found."
10+
# Check if the .srt file exists
11+
if [ ! -f "$srt_filename" ]; then
12+
echo "Error: File '$srt_filename' not found."
1813
exit 1
1914
fi
2015

2116
instructions="Instructions: Summarize the following article."
2217
start_tag="[START ARTICLE]"
2318
end_tag="[END ARTICLE]"
2419

25-
26-
output=$(tr -d '\r' < "$filename" | \
20+
output=$(tr -d '\r' < "$srt_filename" | \
2721
sed -e '/^[[:space:]]*$/d' -e '/^[0-9]/d' | \
2822
uniq)
2923

0 commit comments

Comments
 (0)