Skip to content

Commit

Permalink
move the rosetta check to install
Browse files Browse the repository at this point in the history
  • Loading branch information
romkatv committed Nov 25, 2020
1 parent 3829eda commit 603fb2c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 47 deletions.
25 changes: 2 additions & 23 deletions gitstatus.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -402,27 +402,6 @@ function _gitstatus_daemon"${1:-}"() {
_gitstatus_zsh_downloaded="$3"
}

function _gitstatus_run() {
local proc
if [[ $_gitstatus_zsh_daemon == *-darwin-x86_64 && $uname_sm == 'darwin arm64' ]] &&
[[ ! -e /Library/Apple/System/Library/LaunchDaemons/com.apple.oahd.plist ]] &&
[[ -x /usr/sbin/softwareupdate ]] &&
proc=$(/usr/sbin/sysctl -n machdep.cpu.brand_string) &&
[[ $proc != *Intel* ]]; then
print -Pru $pipe_fd -- 'Please run the following command to install Rosetta:'
print -Pru $pipe_fd -- ''
print -Pru $pipe_fd -- ' %2F/usr/sbin/softwareupdate%f --install-rosetta'
print -Pru $pipe_fd -- ''
print -Pru $pipe_fd -- 'See for details: %Uhttps://support.apple.com/en-us/HT211861%u'
print -Pru $pipe_fd -- ''
print -Pru $pipe_fd -- 'Once Rosetta is installed, restart zsh with this command:'
print -Pru $pipe_fd -- ''
print -Pru $pipe_fd -- ' %2F%Uexec%u zsh%f'
return 130
fi
HOME=$home $_gitstatus_zsh_daemon -G $_gitstatus_zsh_version "${(@)args}" >&$pipe_fd
}

local gitstatus_plugin_dir_var=_gitstatus_plugin_dir$fsuf
local gitstatus_plugin_dir=${(P)gitstatus_plugin_dir_var}
builtin set -- -d $gitstatus_plugin_dir -s $uname_s -m $uname_m \
Expand All @@ -443,7 +422,7 @@ function _gitstatus_daemon"${1:-}"() {
fi

if [[ -x $_gitstatus_zsh_daemon ]]; then
_gitstatus_run
HOME=$home $_gitstatus_zsh_daemon -G $_gitstatus_zsh_version "${(@)args}" >&$pipe_fd
local -i ret=$?
[[ $ret == (0|129|130|131|137|141|143|159) ]] && return ret
fi
Expand All @@ -462,7 +441,7 @@ function _gitstatus_daemon"${1:-}"() {
[[ -n $_gitstatus_zsh_version ]] || return
[[ $_gitstatus_zsh_downloaded == 1 ]] || return

_gitstatus_run
HOME=$home $_gitstatus_zsh_daemon -G $_gitstatus_zsh_version "${(@)args}" >&$pipe_fd
} always {
local -i ret=$?
zf_rm -f -- $file_prefix.lock $file_prefix.fifo
Expand Down
74 changes: 50 additions & 24 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,45 @@
#
# This script does not have a stable API.

_gitstatus_install_daemon_found() {
local installed="$1"
shift

case "$daemon" in
*-darwin-x86_64);;
*)
[ $# = 0 ] || "$@" "$daemon" "$version" "$installed"
return
;;
esac

local cpu
if [ "$uname_sm" != 'darwin arm64' ] ||
[ -e /Library/Apple/System/Library/LaunchDaemons/com.apple.oahd.plist ] ||
[ ! -x /usr/sbin/softwareupdate ] ||
! cpu="$(/usr/sbin/sysctl -n machdep.cpu.brand_string)"; then
[ $# = 0 ] || "$@" "$daemon" "$version" "$installed"
return
fi

case "$cpu" in
*Intel*);;
*)
[ $# = 0 ] || "$@" "$daemon" "$version" "$installed"
return
;;
esac

>&"$e" printf 'Please run the following command to install Rosetta:\n'
>&"$e" printf '\n'
>&"$e" printf ' \033[32m/usr/sbin/softwareupdate\033[0m --install-rosetta\n'
>&"$e" printf '\n'
>&"$e" printf 'See for details: \033[4mhttps://support.apple.com/en-us/HT211861\033[0m\n'
>&"$e" printf '\n'
>&"$e" printf 'Once Rosetta is installed, restart your shell.\n'
return 1
}

_gitstatus_install_main() {
if [ -n "${ZSH_VERSION:-}" ]; then
emulate -L sh -o no_unset
Expand Down Expand Up @@ -157,7 +196,8 @@ END
>&2 echo "[gitstatus] internal error: empty gitstatus_version in build.info"
return 1
fi
[ $# = 0 ] || "$@" "$daemon" "$gitstatus_version" 0
local version="$gitstatus_version"
_gitstatus_install_daemon_found 0 "$@"
return
fi
fi
Expand Down Expand Up @@ -197,7 +237,7 @@ END
[ -e "$daemon" ] || daemon=
fi
if [ -n "$daemon" ]; then
[ $# = 0 ] || "$@" "$daemon" "$version" 0
_gitstatus_install_daemon_found 0 "$@"
return
fi
fi
Expand All @@ -222,15 +262,11 @@ END
if [ ! -d "$dir" ]; then
>&"$e" printf 'Not a directory: \033[4;31m%s\033[0m\n' "$dir"
>&"$e" printf '\n'
>&"$e" printf 'Delete it, then restart zsh with this command:\n'
>&"$e" printf '\n'
>&"$e" printf ' \033[4;32mexec\033[0m \033[32mzsh\033[0m\n'
>&"$e" printf 'Delete it, then restart your shell.\n'
elif [ ! -w "$dir" ]; then
>&"$e" printf 'Directory is not writable: \033[4;31m%s\033[0m\n' "$dir"
>&"$e" printf '\n'
>&"$e" printf 'Make it writable, then restart zsh with this command:\n'
>&"$e" printf '\n'
>&"$e" printf ' \033[4;32mexec\033[0m \033[32mzsh\033[0m\n'
>&"$e" printf 'Make it writable, then restart your shell.\n'
fi
break
fi
Expand All @@ -256,30 +292,22 @@ END
if [ ! -e "$dir" ]; then
>&"$e" printf 'Temporary '"$label"' does not exist: \033[4;31m%s\033[0m\n' "$dir"
>&"$e" printf '\n'
>&"$e" printf 'Create it, then restart zsh with this command:\n'
>&"$e" printf '\n'
>&"$e" printf ' \033[4;32mexec\033[0m \033[32mzsh\033[0m\n'
>&"$e" printf 'Create it, then restart your shell.\n'
elif [ ! -d "$dir" ]; then
>&"$e" printf 'Not a '"$label"': \033[4;31m%s\033[0m\n' "$dir"
>&"$e" printf '\n'
>&"$e" printf 'Make it a directory, then restart zsh with this command:\n'
>&"$e" printf '\n'
>&"$e" printf ' \033[4;32mexec\033[0m \033[32mzsh\033[0m\n'
>&"$e" printf 'Make it a directory, then restart your shell.\n'
elif [ ! -w "$dir" ]; then
>&"$e" printf 'Temporary '"$label"' is not writable: \033[4;31m%s\033[0m\n' "$dir"
>&"$e" printf '\n'
>&"$e" printf 'Make it writable, then restart zsh with this command:\n'
>&"$e" printf '\n'
>&"$e" printf ' \033[4;32mexec\033[0m \033[32mzsh\033[0m\n'
>&"$e" printf 'Make it writable, then restart your shell.\n'
fi
return 1
fi
fi

if ! command -v curl >/dev/null 2>&1 && ! command -v wget >/dev/null 2>&1; then
>&"$e" printf 'Please install \033[32mcurl\033[0m or \033[32mwget\033[0m, then restart zsh with this command:\n'
>&"$e" printf '\n'
>&"$e" printf ' \033[4;32mexec\033[0m \033[32mzsh\033[0m\n'
>&"$e" printf 'Please install \033[32mcurl\033[0m or \033[32mwget\033[0m, then restart your shell.\n'
return 1
fi

Expand Down Expand Up @@ -435,9 +463,7 @@ END
>&"$e" printf ' 1. \033[4m%s\033[0m\n' "$url1"
>&"$e" printf ' 2. \033[4m%s\033[0m\n' "$url2"
>&"$e" printf '\n'
>&"$e" printf 'Check your internet connection, then restart zsh with this command:\n'
>&"$e" printf '\n'
>&"$e" printf ' \033[4;32mexec\033[0m \033[32mzsh\033[0m\n'
>&"$e" printf 'Check your internet connection, then restart your shell.\n'
exit 1
fi

Expand All @@ -461,7 +487,7 @@ END
command rm -rf -- "$tmpdir"
[ "$ret" = 0 ] || return

[ $# = 0 ] || "$@" "$daemon" "$version" 1
_gitstatus_install_daemon_found 1 "$@"
return
done <"$gitstatus_dir"/install.info

Expand Down

0 comments on commit 603fb2c

Please sign in to comment.