From fe8f0bce94e051c0a88972134aafad6050ae8149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20AKY=C3=9CZ?= Date: Wed, 18 Oct 2023 03:04:57 +0300 Subject: [PATCH] improve && simplify --- .local/bin/videosearch | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.local/bin/videosearch b/.local/bin/videosearch index e696eb24..09df1878 100644 --- a/.local/bin/videosearch +++ b/.local/bin/videosearch @@ -1,6 +1,10 @@ -#!/bin/bash +#!/bin/sh -temp_file=$(mktemp) -locate -d ~/.config/.mymlocate.db -b -r '.*\.\(mp4\|mkv\|webm\|mov\|m4v\wmv\|flv\|avi\)$' | awk -F/ '{name=$NF; gsub(/\.(mp4|mkv|webm|mov|m4v|wmv|flv|avi)$/, "", name); print name "\t" $0}' > "$temp_file" -chosen_file_name_and_path=$(cut -f1 "$temp_file" | dmenu -i -l 10 -p "Select a video file:") -mpv "$(awk -F'\t' -v chosen="$chosen_file_name_and_path" '$1 == chosen {print $2; exit}' "$temp_file")" && rm "$temp_file" +tempfile=$(mktemp) +locate -d ~/.config/.mymlocate.db -b -r '.*\.\(mp4\|mkv\|webm\|mov\|m4v\|wmv\|flv\|avi\)$' > "$tempfile" + +chosen_name=$(sed 's|.*/||; s/\.[^.]*$//' "$tempfile" | dmenu -i -l 10 -p "Select a video file:") +chosen_path=$(grep "/$chosen_name\." "$tempfile") + +mpv "$chosen_path" +rm -f "$tempfile"