1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Dev Containersか判定する方法を使ってdotfilesをより効果的に使う

Last updated at Posted at 2024-08-13

結論

環境変数 REMOTE_COTAINERS=trueかどうかでDev Containerかローカルの環境かを判定できる。

export | grep REMOTE_CONTAINERS
declare -x REMOTE_CONTAINERS="true"

dotfilesでの応用例

dotfilesとは: ホームディレクトリに配置してある,.から始まる設定ファイルを管理するリポジトリのこと。

自分のdotfilesリポジトリでは,Dev Containersで実行されるdotfiles installスクリプトに以下のようなif文を追加しています。

if [ "${REMOTE_CONTAINERS}" == "true" ]; then
    echo "REMOTE_CONTAINERS IS ${REMOTE_CONTAINERS}, THEN OVERWRITE SYMBOLIC LINKS"
    ln -sf ~/dotfiles/${f} ~/${f}
    echo "=====CREATE SYMBOLIC LINKS ${HOME}/dotfiles/${f} --> ${HOME}/${f}====="

普段自分のローカルの開発環境ではシンボリックリンクを使ってdotfiles配下の設定ファイルをホームディレクトリにリンクしているのですが,上書きオプション-fをDev Containers内でのみ使用することでDev Containersにもともとあった設定ファイルを上書きしてシンボリックリンクを作成しています。


補足

dotfilesをDev Containersで使う方法については以下を参照してください。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?