aboutsummaryrefslogtreecommitdiff
path: root/units/ib_search.zsh
blob: 423b5a16a0eb200a32b0ca356d5b38211e37e155 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Copyright (C) 2024-2025 Maria Lisina
# Copyright (C) 2024-2025 Danil Lisin
# SPDX-License-Identifier: Apache-2.0

if [[ -n "${1}" ]]
then
    ib_board="${1}"

    . "${units}/ib_config.zsh"
    . "${units}/ib_authconfig.zsh"

    if [[ -z "${ib_data_url}" ]]
    then
        output_title="Invalid arguments"
        output_text="Unsupported Image Board"

        return 0
    fi

    shift
else
    output_title="Invalid arguments"
    output_text="You must specify Image Board"

    return 0
fi

if test "${1}" -gt 0
then
    inline_page=${1}
    shift
else
    inline_page=1
    set -- -a ${@}
fi

if [[ -n "${offset}" ]]
then
    inline_page=${offset}
fi

if [[ -n "${1}" ]]
then
    search_query="${@}"

    if ! zparseopts -D -F -K -- \
        a=ib_autopaging \
        m=ib_metadata \
        p=ib_preview \
        q=ib_quick
    then
        output_title="Invalid arguments"
        output_text="Unsupported options"

        return 0
    fi
fi

if [[ -n "${1}" ]]
then
    ib_query="${@}"
    shift ${#}
fi

ib_limit=${inline_limit}
ib_page=${inline_page}

if [[ -n "${ib_iwildcard}" ]]
then
    ib_query="$(sed "s/${ib_iwildcard}/\\\\${ib_iwildcard}/g" <<< "${ib_query}" | tr '*' "${ib_iwildcard}")"
fi