Skip to content

Commit 4c69aaf

Browse files
committed
run ggrep if it is installed
1 parent a6e01a2 commit 4c69aaf

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

‎impd‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ is_installed() {
3737
[[ -x "$(command -v "$1")" ]]
3838
}
3939

40+
_grep() {
41+
# Run ggrep (GNU grep) from Homebrew if it is installed.
42+
# https://formulae.brew.sh/formula/grep
43+
if is_installed ggrep; then
44+
ggrep "$@"
45+
else
46+
grep "$@"
47+
fi
48+
}
49+
4050
fetch_ignored_chapters() {
4151
# Print ignored chapters present in container, 1 chatper per line.
4252
# Format: start_time,end_time
@@ -313,14 +323,14 @@ fetch_episode_number() {
313323
local -r file=${1:?}
314324
{
315325
echo 01
316-
grep -Pio '\[\K\d+(?=\])' <<<"${file%.*}"
326+
_grep -Pio '\[\K\d+(?=\])' <<<"${file%.*}"
317327
sed \
318328
-Ee 's/(\[|\()[^])]*(\]|\))//g' \
319329
-Ee 's/[0-9]{3,4}[pP]//g' \
320330
-Ee 's/(19|20)[0-9]{2}//g' \
321331
-Ee 's/v[.0-9-]{1,4}//g' \
322332
-e 's/_/ /g' <<<"${file%.*}" |
323-
grep -Pio '(?<=[##. pe-])[[:digit:]]{1,3}\b'
333+
_grep -Pio '(?<=[##. pe-])[[:digit:]]{1,3}\b'
324334
} | tail -1
325335
}
326336

@@ -501,7 +511,7 @@ find_external_subtitles() {
501511
-regextype posix-extended \
502512
-iregex '.*\.(ass|srt)$' \
503513
-print0 |
504-
grep -Fiz --max-count=1 "$video" |
514+
_grep -Fiz --max-count=1 "$video" |
505515
tr '\0' '\n' # fix no newline at the end
506516
}
507517

@@ -927,7 +937,7 @@ add() {
927937

928938
file_can_be_added() {
929939
local -r file=$1
930-
grep -Pqv "$filename_skip_pattern" <<<"$file" && is_media "$file"
940+
_grep -Pqv "$filename_skip_pattern" <<<"$file" && is_media "$file"
931941
}
932942

933943
add_stdin() {
@@ -1082,7 +1092,7 @@ mkplaylist() {
10821092

10831093
grep_mpd_dir() {
10841094
# https://wiki.archlinux.org/index.php/Music_Player_Daemon#Configuration
1085-
grep -Pos 'music_directory\s*"?\K[^"]*(?="?)' -- ~/.config/mpd/mpd.conf
1095+
_grep -Pos 'music_directory\s*"?\K[^"]*(?="?)' -- ~/.config/mpd/mpd.conf
10861096
}
10871097

10881098
find_xdg_music_dir() {
@@ -1187,7 +1197,7 @@ version() {
11871197
read_config_file() {
11881198
if [[ -f $config_filepath ]]; then
11891199
# shellcheck source=/dev/null
1190-
source -- <(grep -xP '^[a-z_]+=.+$' -- "$config_filepath")
1200+
source -- <(_grep -xP '^[a-z_]+=.+$' -- "$config_filepath")
11911201
fi
11921202
}
11931203

0 commit comments

Comments
 (0)