32eb6d9812aa8f7801aa59bf18b6be7c85268ffb
- Author
- Michael Aquilina <michaelaquilina@gmail.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
Merge pull request #16 from wookayin/fix/freebsd-stat
Fix stat command usage to support macOS/FreeBSD
Diff
1diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
2index c87b1fbdc178d32cea541c6dd844941471b7ea80..57f878f02eb1d35a7bfe03120b2adb80ca2d3696 100644
3--- a/autoswitch_virtualenv.plugin.zsh
4+++ b/autoswitch_virtualenv.plugin.zsh
5@@ -38,10 +38,18 @@ function _check_venv()
6
7 SWITCH_TO=""
8
9+ # Get the .venv file, scanning parent directories
10 venv_path=$(_check_venv_path "$PWD")
11 if [[ -n "$venv_path" ]]; then
12- file_owner="$(stat -c %u "$venv_path")"
13- file_permissions="$(stat -c %a "$venv_path")"
14+
15+ stat --version &> /dev/null
16+ if [[ $? -eq 0 ]]; then # Linux, or GNU stat
17+ file_owner="$(stat -c %u "$venv_path")"
18+ file_permissions="$(stat -c %a "$venv_path")"
19+ else # macOS, or FreeBSD stat
20+ file_owner="$(stat -f %u "$venv_path")"
21+ file_permissions="$(stat -f %OLp "$venv_path")"
22+ fi
23
24 if [[ "$file_owner" != "$(id -u)" ]]; then
25 echo "AUTOSWITCH WARNING: Virtualenv will not be activated"