Skip to content

Commit e812415

Browse files
committedNov 21, 2020
improve MacOS compatibility
1 parent 9870a43 commit e812415

20 files changed

+261
-212
lines changed
 

‎.github/workflows/build.yml

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
paths-ignore:
77
- '**/*.md'
88
pull_request:
9+
paths-ignore:
10+
- '**/*.md'
11+
workflow_dispatch:
12+
# https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
913

1014
jobs:
1115

@@ -39,6 +43,10 @@ jobs:
3943
if: startsWith(matrix.os, 'ubuntu')
4044
run: sudo apt-get --no-install-recommends install -y bc rng-tools
4145

46+
- name: Install coreutils, ioping
47+
if: startsWith(matrix.os, 'macos')
48+
run: brew install coreutils ioping
49+
4250
- name: Test bash-funk
4351
shell: bash
4452
env:

‎docs/ansi.md

+9-11
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,6 @@ Options:
542542
Assigns the current cursor position to the variable with the given name.
543543
-d, --down [LINES] (default: '1', integer: ?-?)
544544
Moves the cursor n lines down.
545-
--fd [NUM] (default: '1', integer: ?-?)
546-
Send the ANSI sequences to the given file descriptor.
547545
-l, --left [COLUMNS] (default: '1', integer: ?-?)
548546
Move the cursor n columns forward.
549547
--print
@@ -570,40 +568,40 @@ Options:
570568
*Implementation:*
571569
```bash
572570
if [[ $_save ]]; then
573-
>&$_fd echo -en "\033[s"
571+
echo -en "\033[s"
574572
fi
575573

576574
if [[ $_restore ]]; then
577-
>&$_fd echo -en "\033[u"
575+
echo -en "\033[u"
578576
fi
579577

580578
if [[ $_up ]]; then
581-
>&$_fd echo -en "\033[${_up}A"
579+
echo -en "\033[${_up}A"
582580
fi
583581

584582
if [[ $_down ]]; then
585-
>&$_fd echo -en "\033[${_up}B"
583+
echo -en "\033[${_down}B"
586584
fi
587585

588586
if [[ $_right ]]; then
589-
>&$_fd echo -en "\033[${_right}C"
587+
echo -en "\033[${_right}C"
590588
fi
591589

592590
if [[ $_left ]]; then
593-
>&$_fd echo -en "\033[${_left}D"
591+
echo -en "\033[${_left}D"
594592
fi
595593

596594
if [[ $_set ]]; then
597-
>&$_fd echo -en "\033[${_set//:/;}H"
595+
echo -en "\033[${_set//:/;}H"
598596
fi
599597

600598
if [[ $_print || $_assign ]]; then
601599
local pos
602-
>&$_fd echo -en "\E[6n" && read -sdR pos
600+
echo -en "\E[6n" && read -sdR pos
603601
pos=${pos#*[}
604602
pos=${pos//;/:}
605603
if [[ $_print ]]; then
606-
>&$_fd echo $pos
604+
echo $pos
607605
fi
608606
if [[ $_assign ]]; then
609607
eval "$_assign=\"$pos\""

‎docs/docker.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ function -docker-debug() {
1616
if [[ ! -e ~/.docker-debug/docker-debug.bin ]]; then
1717
echo "Installing the docker-debug tool (https://github.com/zeromake/docker-debug)..."
1818
mkdir -p ~/.docker-debug
19-
if [[ $OSTYPE =~ "darwin" ]]; then
19+
if [[ $OSTYPE == "darwin"* ]]; then
2020
curl -Lo ~/.docker-debug/docker-debug.bin https://github.com/zeromake/docker-debug/releases/download/0.6.3/docker-debug-darwin-amd64-upx
2121
chmod 700 ~/.docker-debug/docker-debug.bin
22-
elif [[ $OSTYPE =~ "linux" ]]; then
22+
elif [[ $OSTYPE == "linux"* ]]; then
2323
curl -Lo ~/.docker-debug/docker-debug.bin https://github.com/zeromake/docker-debug/releases/download/0.6.3/docker-debug-linux-amd64-upx
2424
chmod 700 ~/.docker-debug/docker-debug.bin
2525
else

‎docs/filesystem.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ Options:
536536
[[ ! $_PATH ]] && _PATH=(.) || true
537537

538538
local _ls="command ls -lAph \"${_PATH[@]}\""
539-
[[ ${OSTYPE} =~ "darwin" ]] && _ls="$_ls -G" || _ls="$_ls -I lost+found --color=always"
539+
[[ $OSTYPE == "darwin"* ]] && _ls="$_ls -G" || _ls="$_ls -I lost+found --color=always"
540540
eval $_ls | awk '
541541
BEGIN { dotDirs = ""; dirs = ""; dotFiles = ""; files = "" }
542542
/^total/ { total = $0 } # capture total line

‎docs/memory.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ Options:
285285
*Implementation:*
286286
```bash
287287
-alloc-mem --selftest && echo || return 1
288-
-memfree --selftest && echo || return 1
289-
-meminfo --selftest && echo || return 1
290-
-memtotal --selftest && echo || return 1
288+
if [ -e /proc/meminfo ]; then -memfree --selftest && echo || return 1; fi
289+
if [ -e /proc/meminfo ]; then -meminfo --selftest && echo || return 1; fi
290+
if [ -e /proc/meminfo ]; then -memtotal --selftest && echo || return 1; fi
291291
-procmem --selftest && echo || return 1
292292
```

‎docs/misc.md

+36-29
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ function -timeout() {
1111
echo "Executes the COMMAND and aborts if it does not finish within the given TIMEOUT in seconds."
1212
[[ ${1:-} == "--help" ]] && return 0 || return 1
1313
fi
14-
# see: http://mywiki.wooledge.org/BashFAQ/068
15-
perl -e 'alarm shift; exec @ARGV' "$@";
14+
if hash timeout 2>/dev/null; then
15+
timeout "$@"
16+
elif hash gtimeout 2>/dev/null; then
17+
# MacOS: https://stackoverflow.com/a/21118126/5116073
18+
gtimeout "$@"
19+
else
20+
# see: http://mywiki.wooledge.org/BashFAQ/068
21+
perl -e 'alarm shift; exec @ARGV' "$@"
22+
fi
1623
}
1724
```
1825

@@ -62,14 +69,14 @@ Parameters:
6269
Allowed options to choose from.
6370
6471
Options:
65-
--assign VARNAME
72+
--assign VARNAME
6673
Assigns the selected value to the variable with the given name instead of printing to stdout.
67-
--default OPTION
74+
--default OPTION
6875
The option to pre-selected.
6976
-----------------------------
70-
--help
77+
--help
7178
Prints this help.
72-
--selftest
79+
--selftest
7380
Performs a self-test.
7481
--
7582
Terminates the option list.
@@ -157,9 +164,9 @@ Usage: -help [OPTION]...
157164
Prints the online help of all bash-funk commands.
158165
159166
Options:
160-
--help
167+
--help
161168
Prints this help.
162-
--selftest
169+
--selftest
163170
Performs a self-test.
164171
--
165172
Terminates the option list.
@@ -184,9 +191,9 @@ Requirements:
184191
+ Command 'sudo' must be available.
185192
186193
Options:
187-
--help
194+
--help
188195
Prints this help.
189-
--selftest
196+
--selftest
190197
Performs a self-test.
191198
--
192199
Terminates the option list.
@@ -217,9 +224,9 @@ Usage: -reload [OPTION]...
217224
Reloads bash-funk.
218225
219226
Options:
220-
--help
227+
--help
221228
Prints this help.
222-
--selftest
229+
--selftest
223230
Performs a self-test.
224231
--
225232
Terminates the option list.
@@ -249,9 +256,9 @@ Usage: -root [OPTION]...
249256
Starts an interactive shell as root user. Same as 'sudo -i'.
250257
251258
Options:
252-
--help
259+
--help
253260
Prints this help.
254-
--selftest
261+
--selftest
255262
Performs a self-test.
256263
--
257264
Terminates the option list.
@@ -271,9 +278,9 @@ Usage: -test-all-misc [OPTION]...
271278
Performs a selftest of all functions of this module by executing each function with option '--selftest'.
272279
273280
Options:
274-
--help
281+
--help
275282
Prints this help.
276-
--selftest
283+
--selftest
277284
Performs a self-test.
278285
--
279286
Terminates the option list.
@@ -301,12 +308,12 @@ Usage: -tweak-bash [OPTION]...
301308
Performs some usability configurations of Bash.
302309
303310
Options:
304-
-v, --verbose
311+
-v, --verbose
305312
Prints additional information during command execution.
306313
-----------------------------
307-
--help
314+
--help
308315
Prints this help.
309-
--selftest
316+
--selftest
310317
Performs a self-test.
311318
--
312319
Terminates the option list.
@@ -339,7 +346,7 @@ if [[ $- == *i* ]]; then
339346
fi
340347
341348
# make ls colorful by default except on MacOS where it is not supported
342-
[[ ${OSTYPE} =~ "darwin" ]] || alias -- ls="command ls --color=auto"
349+
[[ $OSTYPE == "darwin"* ]] || alias -- ls="command ls --color=auto"
343350
344351
#
345352
# aliases
@@ -408,14 +415,14 @@ Usage: -update [OPTION]...
408415
Updates bash-funk to the latest code from github (https://github.com/vegardit/bash-funk). All local modifications are overwritten.
409416
410417
Options:
411-
-r, --reload
418+
-r, --reload
412419
Reloads the bash-funk after updating.
413-
-y, --yes
420+
-y, --yes
414421
Answer interactive prompts with 'yes'.
415422
-----------------------------
416-
--help
423+
--help
417424
Prints this help.
418-
--selftest
425+
--selftest
419426
Performs a self-test.
420427
--
421428
Terminates the option list.
@@ -486,12 +493,12 @@ Parameters:
486493
Name of the Bash variable to check.
487494
488495
Options:
489-
-v, --verbose
496+
-v, --verbose
490497
Prints additional information during command execution.
491498
-----------------------------
492-
--help
499+
--help
493500
Prints this help.
494-
--selftest
501+
--selftest
495502
Performs a self-test.
496503
--
497504
Terminates the option list.
@@ -529,9 +536,9 @@ Parameters:
529536
Number of seconds to wait.
530537
531538
Options:
532-
--help
539+
--help
533540
Prints this help.
534-
--selftest
541+
--selftest
535542
Performs a self-test.
536543
--
537544
Terminates the option list.

‎docs/performance.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ $ -cpu-count
5454

5555
*Implementation:*
5656
```bash
57-
[[ "$OSTYPE" != "darwin"* ]] && grep processor /proc/cpuinfo | wc -l || sysctl -n hw.logicalcpu
57+
[[ $OSTYPE != "darwin"* ]] && grep processor /proc/cpuinfo | wc -l || sysctl -n hw.logicalcpu
5858
```
5959

6060

@@ -97,7 +97,7 @@ case $_mode in
9797
echo "-cpu-perf: Required command '${_mode#dd-}' is not available."
9898
return 1
9999
fi
100-
[[ "$OSTYPE" == "darwin"* ]] && local _bs=1m || local _bs=1M
100+
[[ $OSTYPE == "darwin"* ]] && local _bs=1m || local _bs=1M
101101
dd if=/dev/zero bs=$_bs count=1024 2> >(head -3 | tail -1) > >(${_mode#dd-} >/dev/null)
102102
;;
103103
esac

0 commit comments

Comments
 (0)