Add robust error handling

This commit is contained in:
Emre AKYÜZ 2023-11-19 17:13:36 +03:00 committed by GitHub
parent e259c2af0a
commit d68ba937be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,22 @@
#!/bin/sh #!/bin/dash
command -v locate >/dev/null || {
sudo pacman -S mlocate &&
notify-send "Locate not found. Installing..." || {
notify-send "Failed. Run the script once on terminal OR change sudo permissions."
exit 1
}
}
[ -s "$HOME/.config/.mymlocate.db" ] || {
notify-send "You have no database. Creating it..."
disk_path=$(echo "" | rofi -dmenu -l 0 -p "Enter the disk path (e.g '/mnt/harddisk'): ")
doas updatedb -o ~/.config/.mymlocate.db -U "$disk_path" || {
notify-send "Failed. Run the script once on terminal OR change doas permissions."
exit 1
}
}
video_files=$(locate -d ~/.config/.mymlocate.db -b -r '.*\.\(mp4\|mkv\|webm\|mov\|m4v\|wmv\|flv\|avi\)$') video_files=$(locate -d ~/.config/.mymlocate.db -b -r '.*\.\(mp4\|mkv\|webm\|mov\|m4v\|wmv\|flv\|avi\)$')
chosen_file=$(echo "$video_files" | sed 's|.*/||; s/\.[^.]*$//' | dmenu -i -l 10 -p "Select Video") chosen_file=$(echo "$video_files" | sed 's|.*/||; s/\.[^.]*$//' | rofi -dmenu -p "Select Video")
mpv "$(echo "$video_files" | grep -F "/$chosen_file.")" mpv "$(echo "$video_files" | grep -F "/$chosen_file.")"