-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiretabs.sh
executable file
·48 lines (40 loc) · 1.12 KB
/
firetabs.sh
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
#!/bin/bash
# Check if at least one file path is provided
if [ $# -eq 0 ]; then
echo "Usage: firetabs <path-to-txt-file> [more-files...]"
exit 1
fi
# Function to process each file
open_urls_from_file() {
local file="$1"
# Check if the file exists
if [ ! -f "$file" ]; then
echo "Error: File '$file' not found."
return
fi
# Remove trailing empty lines in the original file
sed -i '/^[[:space:]]*$/d' "$file"
# Read URLs into an array
urls=()
while IFS= read -r url; do
urls+=("$url")
done < "$file"
echo # Print an empty line for separation
# Print URLs one per line
echo "Opening URLs from '$file':"
for url in "${urls[@]}"; do
echo "$url"
done
# Open in a new window if only one URL, otherwise open in a new tabbed window
if [ ${#urls[@]} -eq 1 ]; then
firefox --new-window "${urls[0]}"
elif [ ${#urls[@]} -gt 1 ]; then
firefox --url "${urls[@]}"
else
echo "Error: No URLs found in '$file'."
fi
}
# Loop through all provided files
for file in "$@"; do
open_urls_from_file "$file"
done