見出し画像

macOS設定「.bashrc」「.bash_profile」

色々てこずったけど、取り敢えず、現状でbetterな状態に落ち着いたので、備考化してみようかと。

※「brew doctor」と「pyEnv」の相性の悪さを、なんとかしていただきたいのだけど。

「.bashprofile」

中身は↓だけ。.bashrcを読み出してるだけ。

if [ -f ~/.bashrc ]; then
 . ~/.bashrc
fi

「.bashrc」

ちょっとハマったのは、「export 環境変数 = “アペンド内容:$環境変数”」した場合、.NET等でいう「環境変数 = 環境変数.appendFirst(アペンド内容)」的な意味になるという事。

なので、同一の環境変数に対してappendした場合、1行目にセットしたものより、20行目など下の方でappendしたものの方が、優先になりますよ…ということなんですが、書籍などでもちっと、この辺、言及して欲しいな、と。

後。LDFLAGS、CPPFLAGSについては、「スペース文字でエントリーが区切られる」「$(brew --prefix フォーミュラ名)は、”/usr/local/opt/フォーミュラ名”に展開される」ってのは、結構ググらないと出てこなかった。

brewとjEnvを使ってる場合、「CPPFLAGS="-I$(brew --prefix openjdk)/include"」は、どうなるんだろう?

※勿論、pyEnv、rbEnvについてもCPPFLAGS、LDFLAGS、PKG_CONFIG_PATHは関係する筈。

#Default PATH init start
  export PATH="/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:"
#Default PATH init end


alias makepot="/usr/bin/php ~/wordpress-i18n-tools/makepot.php"

#ls color
alias ls='ls -G'


export BASH_COMPLETION_ROOT="$(brew --prefix)/etc/bash_completion.d"
if [ -d "${BASH_COMPLETION_ROOT}" ]; then
  [[ -r “$(brew --prefix)/etc/profile.d/bash_completion.sh” ]] && . “$(brew --prefix)/etc/profile.d/bash_completion.sh”

#git ps1
  source $(brew --prefix)/etc/bash_completion.d/git-prompt.sh
  source $(brew --prefix)/etc/bash_completion.d/git-completion.bash
  GIT_PS1_SHOWDIRTYSTATE=true
  export PS1='\[\033[37m\][\[\033[36m\]\u\[\033[37m\]@\h \[\033[32m\]\W\[\033[37m\]]\[\033[31m\]$(__git_ps1)\[\033[00m\]\$ '
fi

#for bash_completion
if [ -f $(brew --prefix)/etc/bash_completion ]; then
  source $(brew --prefix)/etc/bash_completion
fi


  export PATH="/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Library/Apple/usr/bin:$PATH"


#rbEnv init
#installed list: "rbenv versions"
#installable all list: "rbenv install --list-all"
#installable HEAD list: "rbenv install --list"
# 「cd $HOME/.rbenv/plugins/ruby-build && git pull && cd -」
# 「rbenv versions ; rbenv global バージョン; rbenv local バージョン; rbenv rehash; rbenv exec gem list ; rbenv exec gem install アプリ名」
export RBENV_ROOT="$HOME/.rbenv"
if [ -d "${RBENV_ROOT}" ]; then
  export PATH="$RBENV_ROOT/shims:$RBENV_ROOT/bin:$PATH"

  eval "$(rbenv init -)"
fi


#jEnv init
#installed list: "jenv versions"
#setting check: "jenv doctor" / "echo ${JAVA_HOME}"
#export plugin: "jenv enable-plugin export"
export JENV_ROOT="$HOME/.jenv"
if [ -d "${JENV_ROOT}" ]; then
  export PATH="$JENV_ROOT/shims:$PATH"

  eval "$(jenv init -)"
fi


#pyEnv init
#installed list: "pyenv versions"
#installable all list: "pyenv install --list"
#installable HEAD list: "pyenv install --list | grep -v - | grep -v b | tail -1"
export PYENV_ROOT="$HOME/.pyenv"
if [ -d "${PYENV_ROOT}" ]; then
  export PATH="$PYENV_ROOT/shims:$PATH"

  eval "$(pyenv init -)"
fi


#Laravel init
export COMPOSER_ROOT="$HOME/.composer"
if [ -d "${COMPOSER_ROOT}" ]; then
  export PATH="$COMPOSER_ROOT/vendor/bin:$PATH"
fi


#SdkMan
export SDKMAN_DIR="$HOME/.sdkman"
[[ -s "$SDKMAN_DIR/bin/sdkman-init.sh" ]] && source "$SDKMAN_DIR/bin/sdkman-init.sh"


#nodebrew init
export NODEBREW_ROOT="$HOME/.nodebrew"
if [ -d "${NODEBREW_ROOT}" ]; then
  export PATH="$NODEBREW_ROOT/current/bin:$PATH"
fi


#dotNET Core init
export DOTNET_ROOT="$HOME/.dotnet"
if [ -d "${DOTNET_ROOT}" ]; then
  export PATH="$DOTNET_ROOT/tools:$PATH"
fi
if [ -d "/usr/local/share/dotnet" ]; then
  export PATH="/usr/local/share/dotnet:$PATH"
fi


export USR_LOCAL_OPT="/usr/local/opt"
if [ -d "${USR_LOCAL_OPT}" ]; then
  # apr / apr-util / curl-openssl / icu4c / krb5 / libpq / openldap / openssl@1.1 / sqlite / python@3.8
  export PATH="$USR_LOCAL_OPT/apr/bin:$PATH"
  export PATH="$USR_LOCAL_OPT/apr-util/bin:$PATH"
  export PATH="$USR_LOCAL_OPT/curl-openssl/bin:$PATH"
  export PATH="$USR_LOCAL_OPT/icu4c/bin:$USR_LOCAL_OPT/icu4c/sbin:$PATH"
  export PATH="$USR_LOCAL_OPT/krb5/bin:$USR_LOCAL_OPT/krb5/sbin:$PATH"
  export PATH="$USR_LOCAL_OPT/libpq/bin:$PATH"
 # export PATH="$USR_LOCAL_OPT/openjdk/bin:$PATH"
  export PATH="$USR_LOCAL_OPT/openldap/bin:$USR_LOCAL_OPT/openldap/sbin:$PATH"
  export PATH="$USR_LOCAL_OPT/openssl@1.1/bin:$PATH"
  export PATH="$USR_LOCAL_OPT/sqlite/bin:$PATH"
  export PATH="$USR_LOCAL_OPT/python@3.8/bin$PATH"

  export PATH="$USR_LOCAL_OPT/php/bin:$PATH"

  # curl-openssl / icu4c / krb5 / libffi / libpq / openssl@1.1 / readline / sqlite / zlib / python@3.8
  export PKG_CONFIG_PATH="$USR_LOCAL_OPT/curl-openssl/lib/pkgconfig:$PKG_CONFIG_PATH"
  export PKG_CONFIG_PATH="$USR_LOCAL_OPT/icu4c/lib/pkgconfig:$PKG_CONFIG_PATH"
  export PKG_CONFIG_PATH="$USR_LOCAL_OPT/krb5/lib/pkgconfig:$PKG_CONFIG_PATH"
  export PKG_CONFIG_PATH="$USR_LOCAL_OPT/libffi/lib/pkgconfig:$PKG_CONFIG_PATH"
  export PKG_CONFIG_PATH="$USR_LOCAL_OPT/libpq/lib/pkgconfig:$PKG_CONFIG_PATH"
  export PKG_CONFIG_PATH="$USR_LOCAL_OPT/openssl@1.1/lib/pkgconfig:$PKG_CONFIG_PATH"
  export PKG_CONFIG_PATH="$USR_LOCAL_OPT/readline/lib/pkgconfig:$PKG_CONFIG_PATH"
  export PKG_CONFIG_PATH="$USR_LOCAL_OPT/sqlite/lib/pkgconfig:$PKG_CONFIG_PATH"
  export PKG_CONFIG_PATH="$USR_LOCAL_OPT/zlib/lib/pkgconfig:$PKG_CONFIG_PATH"
  export PKG_CONFIG_PATH="$USR_LOCAL_OPT/python@3.8/lib/pkgconfig:$PKG_CONFIG_PATH"

  # curl-openssl / icu4c / krb5 / libffi / libpq / openldap / openssl@1.1 / readline / sqlite / zlib / python@3.8
  export LDFLAGS="-L$(brew --prefix curl-openssl)/lib -L$(brew --prefix icu4c)/lib -L$(brew --prefix krb5)/lib -L$(brew --prefix libffi)/lib -L$(brew --prefix libpq)/lib -L$(brew --prefix openldap)/lib -L$(brew --prefix openssl@1.1)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix sqlite)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix python@3.8)/lib"

  # curl-openssl / icu4c / krb5 / libffi / libpq / openldap / openssl@1.1 / readline / sqlite / zlib
  export CPPFLAGS="-I$(brew --prefix curl-openssl)/include -I$(brew --prefix icu4c)/include -I$(brew --prefix krb5)/include -I$(brew --prefix libffi)/include -I$(brew --prefix libpq)/include -I$(brew --prefix openldap)/include -I$(brew --prefix openssl@1.1)/include -I$(brew --prefix readline)/include -I$(brew --prefix sqlite)/include -I$(brew --prefix zlib)/include"
  # CPPFLAGS="-I$(brew --prefix openjdk)/include"
fi


jdk() {
  version=$1
  export JAVA_HOME=$(/usr/libexec/java_home -v"$version");
  java -version
}

この記事が気に入ったらサポートをしてみませんか?