Skip to content

Commit 959a8c5

Browse files
committed
macOS support
1 parent 23e9ab1 commit 959a8c5

File tree

6 files changed

+65
-20
lines changed

6 files changed

+65
-20
lines changed

Diff for: README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ See `@mighty-scroll-fallback-mode`.
2222
## Requirements
2323

2424
* Mouse mode enabled (`set -g mouse on`).
25-
* Linux (`/proc` file system).
26-
* C compiler (optional, but highly recommended).
25+
* C compiler (Linux only. Optional, but highly recommended).
2726

2827
## Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended)
2928

@@ -62,7 +61,7 @@ $ tmux source ~/.tmux.conf
6261
|`@mighty-scroll-interval`|`2`|Number|How many lines to scroll in `by-line` and `history` modes.|
6362
|`@mighty-scroll-select-pane`|`on`|`on`, `off`|If enabled, the pane being scrolled becomes automatically selected.|
6463
|`@mighty-scroll-by-line`|`'man less pager fzf'`|List|Space separated list of processes that will be scrolled by line.|
65-
|`@mighty-scroll-by-page`|`'irssi vim'`|List|Space separated list of processes that will be scrolled by page.|
64+
|`@mighty-scroll-by-page`|`'irssi vim vi'`|List|Space separated list of processes that will be scrolled by page.|
6665
|`@mighty-scroll-fallback-mode`|`'history'`|`'history'`, `'by-line'`, `'by-page'`|Scroll mode when in alternate screen but the process didn't match `by-line` and `by-page` lists from above.|
6766

6867
Scrolling modes:
@@ -82,9 +81,11 @@ set -g @mighty-scroll-select-pane off
8281

8382
## Performance caveats
8483

85-
Be sure to have a C compiler (`gcc`, `clang`) available (check with `$ cc -v`),
86-
otherwise a Shell implementation of the process checker will be used,
87-
which is about 400% slower!
84+
On Linux, make sure to have a C compiler (`gcc`, `clang`) available (check with
85+
`$ cc -v`), otherwise a Shell implementation of the process checker will be
86+
used, which is about 400% slower!
87+
88+
On macOS there is only a Shell implementation of the process checker at the moment.
8889

8990
## License
9091
[MIT](LICENSE.MIT)

Diff for: benchmark.sh

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
set -e
22

3+
case "$OSTYPE" in
4+
"darwin"*)
5+
echo "macOS is not supported"
6+
exit 1
7+
;;
8+
esac
9+
310
cd "$(dirname "$0")"
411

512
TARGET_PID=$$ # PID of benchmark.sh

Diff for: mighty-scroll.tmux

+13-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@ CURRENT_DIR="$(cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P)"
33
. "$CURRENT_DIR/scripts/helpers.sh"
44
. "$CURRENT_DIR/scripts/variables.sh"
55

6-
if which cc >/dev/null 2>&1; then
7-
make -f "$CURRENT_DIR/Makefile" -C "$CURRENT_DIR" >/dev/null 2>&1
8-
set_tmux_environment "PSCHECK" "$CURRENT_DIR/pscheck"
9-
else
10-
set_tmux_environment "PSCHECK" "$CURRENT_DIR/pscheck.sh"
11-
fi
6+
case "$OSTYPE" in
7+
"darwin"*)
8+
set_tmux_environment "PSCHECK" "$CURRENT_DIR/pscheck.sh"
9+
;;
10+
*)
11+
if which cc >/dev/null 2>&1; then
12+
make -f "$CURRENT_DIR/Makefile" -C "$CURRENT_DIR" >/dev/null 2>&1
13+
set_tmux_environment "PSCHECK" "$CURRENT_DIR/pscheck"
14+
else
15+
set_tmux_environment "PSCHECK" "$CURRENT_DIR/pscheck.sh"
16+
fi
17+
;;
18+
esac
1219

1320
set_tmux_environment "MIGHTY_SCROLL_INTERVAL" "$(get_tmux_option "$interval_option" "$interval_default")"
1421
set_tmux_environment "MIGHTY_SCROLL_BY_LINE" "$(get_tmux_option "$by_line_option" "$by_line_default")"

Diff for: pscheck.sh

+30-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
# Copyright (C) 2020 Sergey Vlasov <[email protected]>
1+
# Copyright (C) 2022 Sergey Vlasov <[email protected]>
22
# MIT License
33

4-
set -e
5-
6-
if [ $# -lt 3 ]; then
4+
if [ $# -lt 2 ]; then
75
BASENAME=$(basename $0)
86
echo "$BASENAME: too few arguments"
97
echo "usage: $BASENAME PID NAME..."
@@ -13,20 +11,45 @@ fi
1311
PID=$1; shift
1412
NAMES=$@
1513

14+
process_name() {
15+
case "$OSTYPE" in
16+
"darwin"*)
17+
ps -p $1 -o comm=
18+
;;
19+
*)
20+
if [ -f /proc/$1/comm ]; then
21+
cat /proc/$P/comm
22+
fi
23+
;;
24+
esac
25+
}
26+
27+
process_children() {
28+
case "$OSTYPE" in
29+
"darwin"*)
30+
pgrep -P $1 -a
31+
;;
32+
*)
33+
cat /proc/$1/task/$1/children
34+
;;
35+
esac
36+
}
37+
1638
walk() {
1739
for P in $@; do
18-
if [ ! -f /proc/$P/comm ]; then # process no longer exists or something else
40+
CMD_NAME="$(process_name $P)"
41+
if [ -z "$CMD_NAME" ]; then # process no longer exists or something else
1942
continue
2043
fi
21-
CMD_NAME=$(cat /proc/$P/comm)
44+
2245
for N in $NAMES; do
2346
if [ "$N" = "$CMD_NAME" ]; then # it's a match
2447
echo "$N"
2548
exit 0
2649
fi
2750
done
2851

29-
CHILDREN=$(cat /proc/$P/task/$P/children)
52+
CHILDREN=$(process_children $P)
3053
if [ ! -z "$CHILDREN" ]; then
3154
walk $CHILDREN
3255
fi

Diff for: scripts/variables.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ by_line_option="@mighty-scroll-by-line"
88
by_line_default="man less pager fzf"
99

1010
by_page_option="@mighty-scroll-by-page"
11-
by_page_default="irssi vim"
11+
by_page_default="irssi vim vi"
1212

1313
fallback_mode_option="@mighty-scroll-fallback-mode"
1414
fallback_mode_default="history"

Diff for: test.sh

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
set -e
22

3+
case "$OSTYPE" in
4+
"darwin"*)
5+
echo "macOS is not supported"
6+
exit 1
7+
;;
8+
esac
9+
310
cd "$(dirname "$0")"
411

512
TARGET_PID=$$ # PID of benchmark.sh

0 commit comments

Comments
 (0)