Skip to content

Commit 95778f9

Browse files
committed
replace mapfile with __split
`mapfile` doesn't exist on bash v3, and doesn't support `-d` until v4.4, furthermore it doesn't support multiple delimiters, multi-length delimiter(s), trimming zero-length, nor easy append also deprecated `get-array` with new `__make_array` fix some bad `--=` usage
1 parent e7f3391 commit 95778f9

58 files changed

Lines changed: 319 additions & 291 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

commands.beta/echo-revolving-screen

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function echo_revolving_screen() (
4242
# determine columns
4343
if [[ -z $option_lines || -z $option_columns ]]; then
4444
local terminal_size=()
45-
mapfile -t terminal_size < <(get-terminal-lines-and-columns || :)
45+
__split terminal_size --no-zero-length < <(get-terminal-lines-and-columns || :)
4646
if [[ ${#terminal_size[@]} -eq 2 ]]; then
4747
if [[ -z $option_lines ]]; then
4848
option_lines="${terminal_size[0]}"

commands.beta/macos-settings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function macos_settings() (
5353

5454
# ask
5555
local choices=()
56-
mapfile -t choices < <(
56+
__split choices --no-zero-length < <(
5757
choose --linger --confirm --multi \
5858
--question="Which settings would you like to enable" \
5959
--label -- \

commands.beta/wallhaven-helper

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function wallhaven_helper() (
5959

6060
# collections
6161
local collections collection
62-
mapfile -t collections < <(fetch "https://wallhaven.cc/api/v1/collections?apikey=$apikey" | jq -r '.data[] | (.id, .label)')
62+
__split collections --no-zero-length < <(fetch "https://wallhaven.cc/api/v1/collections?apikey=$apikey" | jq -r '.data[] | (.id, .label)')
6363
collection="$(
6464
choose \
6565
--question='Which collection to download?' \
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
function get_array() (
44
source "$DOROTHY/sources/bash.bash"
5+
dorothy-warnings add --code='get-array' --bold=' has been deprecated in favor of ' --code='__make_array'
56

67
# =====================================
78
# Arguments
@@ -19,7 +20,7 @@ function get_array() (
1920
How many items to output.
2021
2122
EXAMPLE:
22-
mapfile -t arr < <(get-array 10)
23+
__split arr --no-zero-length < <(get-array 10)
2324
EOF
2425
if [[ $# -ne 0 ]]; then
2526
echo-error "$@"
@@ -57,10 +58,11 @@ function get_array() (
5758
# =====================================
5859
# Action
5960

60-
local i
61+
local i lines=''
6162
for ((i = 0; i < option_size; i++)); do
62-
__print_line
63+
lines+=$'\n'
6364
done
65+
__print_string "$lines"
6466
)
6567

6668
# fire if invoked standalone

commands/checksum

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function checksum_() (
6969
;;
7070
'--algorithm='*) option_algorithm="${item#*=}" ;;
7171
'--')
72-
mapfile -t option_paths < <(fs-absolute -- "$@")
72+
__split option_paths --no-zero-length < <(fs-absolute -- "$@")
7373
shift $#
7474
break
7575
;;

commands/choose

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -738,13 +738,11 @@ function choose_() (
738738
'--match='*) option_matches+=("${item#*=}") ;;
739739
'--default-exact='* | '--default='*) defaults_exact+=("${item#*=}") ;;
740740
'--defaults-exact='* | '--defaults='*)
741-
mapfile -t tmp <<<"${item#*=}"
742-
defaults_exact+=("${tmp[@]}")
741+
__split defaults_exact --append -- "${item#*=}"
743742
;;
744743
'--default-fuzzy='*) defaults_fuzzy+=("${item#*=}") ;;
745744
'--defaults-fuzzy='*)
746-
mapfile -t tmp <<<"${item#*=}"
747-
defaults_fuzzy+=("${tmp[@]}")
745+
__split defaults_fuzzy --append -- "${item#*=}"
748746
;;
749747
'--no-default-all'* | '--default-all'*)
750748
option_default_all="$(get-flag-value --affirmative --fallback="$option_default_all" -- "$item")"
@@ -1249,8 +1247,7 @@ function choose_() (
12491247
style__hide_cursor=''
12501248
style__show_cursor=''
12511249
# set rendering
1252-
mapfile -t items_renders < <(get-array "$items_count")
1253-
mapfile -t items_rows < <(get-array "$items_count")
1250+
__make_array items_renders items_rows --size="$items_count"
12541251
# paging support is eternal, so no need for future updates if disabled
12551252
function reset_terminal_modifications_now {
12561253
:
@@ -1275,7 +1272,7 @@ function choose_() (
12751272
function refresh_terminal_size {
12761273
# refresh
12771274
local terminal_size=()
1278-
mapfile -t terminal_size < <(get-terminal-lines-and-columns)
1275+
__split terminal_size --no-zero-length < <(get-terminal-lines-and-columns)
12791276
terminal_lines="${terminal_size[0]}"
12801277
terminal_columns="${terminal_size[1]}"
12811278

@@ -1308,8 +1305,7 @@ function choose_() (
13081305

13091306
# reset paging for new size
13101307
paging_used='maybe'
1311-
mapfile -t items_renders < <(get-array "$items_count")
1312-
mapfile -t items_rows < <(get-array "$items_count")
1308+
__make_array items_renders items_rows --size="$items_count"
13131309

13141310
# update priors
13151311
terminal_lines_prior="$terminal_lines"
@@ -2234,7 +2230,7 @@ function choose_() (
22342230
# input => keys => key
22352231
keys=()
22362232
skips=()
2237-
mapfile -t keys <<<"$input"
2233+
__split keys -- "$input"
22382234
for key in "${keys[@]}"; do
22392235
if is-digit -- "$key"; then
22402236
action_jump "$key"

commands/choose-path

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function choose_path() (
4343

4444
# adjust args to paths and basenames
4545
local values=()
46-
mapfile -t values < <(echo-paths-and-basenames -- "${option_paths[@]}")
46+
__split values --no-zero-length < <(echo-paths-and-basenames -- "${option_paths[@]}")
4747

4848
# ask with label
4949
choose --label "${options[@]}" -- "${values[@]}"

commands/config-helper

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ function config_helper() (
361361
fi
362362

363363
# adapt for array
364-
mapfile -t lines <<<"$value" # read lines into an array, such that indentation works
364+
__split lines --keep-zero-length -- "$value" # read lines into an array, such that indentation works
365365

366366
# addition, use spaces for consistency with replacements, also use spaces as editors show tabs at variable widths
367367
value=$'(\n'"$(echo-lines --indent=$'\t' --quote="$option_quote" --columns="${option_columns:-"1"}" --width=inputs --filler=space -- "${lines[@]}")"$'\n)'

commands/confirm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ function confirm_() (
336336

337337
# input => keys => key
338338
keys=()
339-
mapfile -t keys <<<"$input"
339+
__split keys -- "$input"
340340

341341
# prep clearing of any input that leaked
342342
question_confirm_and_input_lines=''

commands/debug-bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function debug_bash() (
5454
'--versions='*)
5555
item="${item#*=}"
5656
if [[ -n $item ]]; then
57-
mapfile -t option_bash_binaries <<<"${item#*=}"
57+
__split option_bash_binaries --no-zero-length -- "${item#*=}"
5858
fi
5959
;;
6060
'--bash='* | '--version='*) option_bash_binaries+=("${item#*=}") ;;
@@ -63,7 +63,7 @@ function debug_bash() (
6363
continue
6464
fi
6565
local bash_binaries=()
66-
mapfile -t bash_binaries < <(
66+
__split bash_binaries --no-zero-length < <(
6767
type -pa bash
6868
expand-path -- "$XDG_BIN_HOME/bash-*"
6969
)

0 commit comments

Comments
 (0)