@@ -240,6 +240,14 @@ fetch_title() {
240
240
echo " $title "
241
241
}
242
242
243
+ _grep () {
244
+ if command -v ggrep > /dev/null 2>&1 ; then
245
+ ggrep " $@ "
246
+ else
247
+ grep " $@ "
248
+ fi
249
+ }
250
+
243
251
fetch_episode_number () {
244
252
local -r file=${1:? }
245
253
{
@@ -421,7 +429,7 @@ find_external_subtitles() {
421
429
422
430
if [[ -z $dir ]] || [[ ! -d $dir ]]; then
423
431
echo " Error: video directory '$dir ' is invalid." >&2
424
- exit 1
432
+ return 1
425
433
fi
426
434
427
435
find " $dir " \
@@ -957,11 +965,15 @@ mkplaylist() {
957
965
958
966
grep_mpd_dir () {
959
967
# https://wiki.archlinux.org/index.php/Music_Player_Daemon#Configuration
960
- if command -v ggrep > /dev/null; then
961
- ggrep -Pos ' music_directory\s*"?\K[^"]*(?="?)' -- ~ /.config/mpd/mpd.conf 2> /dev/null
968
+ _grep -Pos ' music_directory\s*"?\K[^"]*(?="?)' -- ~ /.config/mpd/mpd.conf 2> /dev/null
969
+ }
970
+
971
+ find_xdg_music_dir () {
972
+ # macOS doesn't have xdg-user-dir, so we'll use ~/Music as the default
973
+ if command -v xdg-user-dir > /dev/null 2>&1 ; then
974
+ xdg-user-dir MUSIC 2> /dev/null
962
975
else
963
- # Fallback for macOS - extract music directory path from mpd.conf
964
- grep ' music_directory' ~ /.config/mpd/mpd.conf 2> /dev/null | sed -E ' s/.*music_directory[[:space:]]*"?([^"]*).*/\1/'
976
+ echo " $HOME /Music"
965
977
fi
966
978
}
967
979
@@ -1090,7 +1102,16 @@ ensure_dirs() {
1090
1102
" $tmp_dir "
1091
1103
}
1092
1104
1105
+ check_macos_grep () {
1106
+ # if running macOS, ggrep must be installed to support Perl-compatible regular expressions.
1107
+ if [[ " $( uname) " == " Darwin" ]] && ! command -v ggrep > /dev/null 2>&1 ; then
1108
+ echo " ggrep is not installed. install it with brew." >&2
1109
+ exit 1
1110
+ fi
1111
+ }
1112
+
1093
1113
main () {
1114
+ check_macos_grep
1094
1115
# Load configuration file, then apply settings omitted in the config file.
1095
1116
read_config_file
1096
1117
0 commit comments