From d68ba937be6a9feb5c756280d53a97e8e8500e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20AKY=C3=9CZ?= Date: Sun, 19 Nov 2023 17:13:36 +0300 Subject: [PATCH] Add robust error handling --- .local/bin/videosearch | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/.local/bin/videosearch b/.local/bin/videosearch index eb19d92d..d0230f9d 100644 --- a/.local/bin/videosearch +++ b/.local/bin/videosearch @@ -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\)$') -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.")"