[zsh] refactor platform identification

This commit is contained in:
Dmytro Meleshko 2020-01-05 13:58:58 +02:00
parent 894a81f2b3
commit e549d7fa2f
3 changed files with 17 additions and 8 deletions

View file

@ -16,10 +16,6 @@ viscd() {
rm -f -- "$temp_file"
}
is_linux() { [[ "$OSTYPE" == linux* ]]; }
is_macos() { [[ "$OSTYPE" == darwin* ]]; }
is_android() { [[ "$OSTYPE" == linux-android ]]; }
command_exists() { command -v "$1" &>/dev/null; }
lazy_load() {
@ -33,8 +29,8 @@ lazy_load() {
}"
}
if ! is_macos; then
if is_android; then
if (( ! _is_macos )); then
if (( _is_android )); then
open_cmd='termux-open'
elif command_exists xdg-open; then
open_cmd='nohup xdg-open &> /dev/null'
@ -45,7 +41,7 @@ if ! is_macos; then
unset open_cmd
fi
if is_macos; then
if (( _is_macos )); then
copy_cmd='pbcopy' paste_cmd='pbpaste'
elif command_exists xclip; then
copy_cmd='xclip -in -selection clipboard' paste_cmd='xclip -out -selection clipboard'

View file

@ -17,7 +17,7 @@ path_prepend() {
done
}
if is_macos; then
if (( _is_macos )); then
# local Python binaries (for some reason they don't go into ~/.local/bin, but
# instead into the garbage ~/Library directory)
path_prepend path ~/Library/Python/*/bin(OnN)

View file

@ -33,6 +33,19 @@ autoload -U colors && colors
_perf_timer_start "total"
# platform identification {{{
if [[ "$OSTYPE" == linux* ]]; then
_is_linux=1
if [[ "$OSTYPE" == linux-android ]]; then
_is_android=1
fi
fi
if [[ "$OSTYPE" == darwin* ]]; then
_is_macos=1
fi
# }}}
for script in functions options path env plugins aliases completion zle prompt colorscheme; do
_perf_timer_start "$script.zsh"
source "$ZSH_DOTFILES/$script.zsh"