---
title: "ターミナルがダサいとモテない。macOSとLinuxのXDG_CONFIG_HOMEを共有するぞ - yadm編 | grasys blog"
url: "https://blog.grasys.io/post/yusukeh/terminal-yadm-xdg-config-home"
description: "Batch management of XDG CONFIG HOME on macOS and Linux with yadm Photo by Ferenc Almasi on Unsplash 恵比寿でIT企業をやっているとモテると聞いて創業しましたが早いことありがたいことに10年目に突入した長谷川です。 まだモテる成果は出ていません、、、これからです！（もうめんどくさいのでカウントやめました😆） 最近、少しだけLinuxをお触…"
---

# ターミナルがダサいとモテない。macOSとLinuxのXDG\_CONFIG\_HOMEを共有するぞ - yadm編

-   ![](/_astro/noicon.CTHOhNiB_1HMs6A.webp)[yusukeh](/authors/yusukeh/)
-   公開日：2025年2月28日
-   カテゴリー：[Tech](/categories/tech/)
-   タグ：[#シリーズ: ターミナル環境](/tags/シリーズ-ターミナル環境/)[#yadm](/tags/yadm/)[#dotfiles](/tags/dotfiles/)[#macOS](/tags/macos/)[#Linux](/tags/linux/)

![ターミナルがダサいとモテない。macOSとLinuxのXDG\_CONFIG\_HOMEを共有するぞ - yadm編](/_astro/ogp.wV2rrp9M_sEnGe.webp)

Photo by [Ferenc Almasi](http://webtips.dev/) on [Unsplash](https://unsplash.com/?utm_source=medium&utm_medium=referral)

Batch management of XDG\_CONFIG\_HOME on macOS and Linux with yadm

恵比寿でIT企業をやっているとモテると聞いて創業しましたが早いことありがたいことに10年目に突入した長谷川です。

まだモテる成果は出ていません、、、これからです！（もうめんどくさいのでカウントやめました😆）

最近、少しだけLinuxをお触りするお仕事をしていて・・・ふと思ったのが・・・

macOSばかり触っているから、macOSの中身をめちゃくちゃ弄くり倒していて、抜き身のUbuntuやDebianが痒くて触りにくくなってしまうという・・・😅

vimだときつくて[NeoVim](https://neovim.io/)使いたくて[AstroNvim](https://astronvim.com/)使いたくてと・・・  
lsだとちょっと[eza](https://github.com/eza-community/eza)が・・・とか  
[starship](https://starship.rs/)欲しいなとか・・・

出てくる出てくる🤣

そこで[yadm](https://yadm.io/)です。

## yadm

> Yet Another Dotfiles Manager

こんな紹介がされています。

## Yet Another Dotfiles Manager

### When you live in a command line, configurations are a deeply personal thing. They are often crafted over years of…

yadm.io

ざっくり紹介すると以下です。

-   XDG\_CONFIG\_HOMEのgit化
-   alternate filesによるdotfilesの管理
-   暗号化と復号化
-   bootstrapによるscript runner
-   git cloneするだけで外部依存が少ない（Install方法はいろいろあります）

_ただし注意点として、最低限gitがCommand-Lineで扱える必要があります。_

それでは実際にyadmの各種機能を紹介していきます。

## Install yadm

## Installation

### OSX

yadm.io

いろいろなOSやDistribution向けのInstall手法がこちらで紹介されています。

macOSなら[homebrew](https://brew.sh/)でInstallできます。

Plain textcontent\_copy

```
brew install yadm
```

gitでcloneする方法もあります。

## Installation

### OSX

yadm.io

Plain textcontent\_copy

```
git clone https://github.com/yadm-dev/yadm.git ~/.yadm-project
ln -s ~/.yadm-project/yadm ~/bin/yadm
```

自分は以下のような形でInstallしました。

Plain textcontent\_copy

```
declare repo=https://github.com/yadm-dev/yadm.git
declare deploy_to=${HOME}/local/yadm

if [ ! -d ${deploy_to}/.git ]; then
  git clone --depth 1 ${repo} ${deploy_to}
else
  git -C ${deploy_to} pull
fi

# PATH通したければ以下
declare -x PATH=${deploy_to}:${PATH}
```

PATHはどうぞお好きにしてください。

## yadm help

まずはhelpを叩きましょう。

新しいコマンド触るときは最初にhelpを見る！これ基本！

Plain textcontent\_copy

```
❯ yadm --help
Usage: yadm <command> [options...]

Manage dotfiles maintained in a Git repository. Manage alternate files
for specific systems or hosts. Encrypt/decrypt private files.

Git Commands:
Any Git command or alias can be used as a <command>. It will operate
on yadm's repository and files in the work tree (usually $HOME).

Commands:
  yadm init [-f]             - Initialize an empty repository
  yadm clone <url> [-f]      - Clone an existing repository
  yadm config <name> <value> - Configure a setting
  yadm list [-a]             - List tracked files
  yadm alt                   - Create links for alternates
  yadm bootstrap             - Execute $HOME/.config/yadm/bootstrap
  yadm encrypt               - Encrypt files
  yadm decrypt [-l]          - Decrypt files
  yadm perms                 - Fix perms for private files
  yadm enter [COMMAND]       - Run sub-shell with GIT variables set
  yadm git-crypt [OPTIONS]   - Run git-crypt commands for the yadm repo
  yadm transcrypt [OPTIONS]  - Run transcrypt commands for the yadm repo

Files:
  $HOME/.config/yadm/config        - yadm's configuration file
  $HOME/.config/yadm/encrypt       - List of globs to encrypt/decrypt
  $HOME/.config/yadm/bootstrap     - Script run via: yadm bootstrap
  $HOME/.local/share/yadm/repo.git - yadm's Git repository
  $HOME/.local/share/yadm/archive  - Encrypted data stored here

Use "man yadm" for complete documentation.
```

gitのwrapperになってるのがわかりますね

## yadm init

yadmでdotfilesとXDG\_CONFIG\_HOMEを管理し始めます。

いきなりmacOSで構成を始めないで、なにかVMを立てて何が起きるかも含め確認しながら進めた方が良いと思います。

dotfilesと.configのバックアップも忘れずに！😅

[オフィシャルのGetting Started](https://yadm.io/docs/getting_started)に記載があります。

## Getting Started

### Starting out with yadm should be just a few easy steps.

yadm.io

Plain textcontent\_copy

```
yadm init
yadm add <important file>
yadm commit
```

yadm commitは-mでコメント入れたりすることもできるみたいです。

プログラマーの方はgitをCommand-Lineで処理するので、ちょっとCLIでgitする練習しといた方がいいかもしれないですね。（自分も最近はlazygitを使っていて、ちょっと久しぶりすぎて😂）

gitのrepository urlを入れてbranch指定するのは以下です。

Plain textcontent\_copy

```
yadm remote add origin <url>
yadm push -u origin <local branch>:<remote branch>
```

## yadm clone

同じく[Getting Started](https://yadm.io/docs/getting_started)に記載があります。

## Getting Started

### Starting out with yadm should be just a few easy steps.

yadm.io

Plain textcontent\_copy

```
yadm clone <url>
yadm status
```

## yadm Common Commands

どんなSub-Commandがあるのかはこちらをみればわかります。

## Common Commands

### Most of these operations will look like Git commands; because they are.yadm wraps Git, allowing it to perform all of…

yadm.io

またyadm statusにはgit statusと同じで-unormalがあります。

Plain textcontent\_copy

```
yadm status -unormal
```

## Frequently Asked Questions

### Categories

yadm.io

Usageの”How can I display untracked files with a `yadm status` command?”に記載があります。

Plain textcontent\_copy

```
yadm status -unormal
```

それではここから、yadmの基本的な機能の紹介をしていきます。

## Bootstrap

## Bootstrap

### Often there is more to set up once your dotfiles repository has been cloned. Forexample, if your repository has…

yadm.io

実際にyadm cloneした時にbootstrapを起動するか、y/nで聞かれるみたいです。

また –bootstrap や –no-bootstrap といったオプションもyadm cloneにはあります。

Plain textcontent\_copy

```
$HOME/.config/yadm/bootstrap
```

としてShell Scriptを配置すれば動かすことができます。

### bootstrap.d

またページ下部を見てもらえるとわかるのですが、サポートScriptが用意されていて複数のScriptに分割する拡張することができます。

[https://raw.githubusercontent.com/yadm-dev/yadm/master/contrib/bootstrap/bootstrap-in-dir](https://raw.githubusercontent.com/yadm-dev/yadm/master/contrib/bootstrap/bootstrap-in-dir)

自分は上記のSupport Scriptを使わずに自前で作ったScriptで処理しています。

自分のbootstrapは以下のようになっています。

Plain textcontent\_copy

```
tree ${HOME}/.config/yadm/
├──  bootstrap
├──  bootstrap.d
│   ├──  asdf
│   ├──  astrocommunity
│   ├──  envutils-darwin
│   ├──  envutils-linux
│   ├──  gobrew
│   ├──  luaver
│   ├──  mustache
│   ├──  rerun
│   ├──  rustup
│   ├──  tmux-tpm
│   ├──  uv
│   └──  volta
```

まだしっかりできてないのですが、以下のようなfunctionを組んだShell Script郡になっています。

-   OS Check
-   yes or no prompt
-   pre bootstrap
-   bootstrap
-   post bootstrap

## Alternate Files

## Alternate Files

### When possible, it is best to use the same files across all systems. However,there are occasions when you need different…

yadm.io

Symlink alternatesにはcondition attributeという仕組みがあります。

最初は戸惑いましたが、試しにひとつファイルを作ってみるとなんのこっちゃない話でした。

今回の主題はmacOSとLinuxを相互に管理するなのでここで使うのはos attributeかな？

### ex) ${HOME}/.gitconfig

例えばHOMEの.gitconfigをsymlinkしたいとします。

_ここで紹介する.gitconfigについてはあくまでも例です。  
XDG\_BASE\_DIRの考え方でしばらく自分のコンピュータを触っていると理解して貰えると思うのですが、基本的に${HOME}にあるいわゆるrcfile系のdotfiles郡について${HOME}配下に配置しない方が良いと思います。  
yadmの管理に複雑さをもたらしてしまいます。  
またXDG\_CACHE\_DIRやXDG\_STATE\_DIRやXDG\_DATA\_DIRなどは移動してしまうと、チームで共用しているサーバなどでは混乱を発生させる可能性もあると思います。  
とはいうものの、正直なところ好みの問題だと思うので個人の選択と判断で責任を持って管理すれば良いと思います。_

その場合のalternate fileは、

Plain textcontent\_copy

```
${HOME}/.config/yadm/alt/.gitconfig##default
```

になります。

##defaultを利用すると特に条件なしにHOMEにsymlinkします。

これをOS別に分けたい場合は以下です。

macOSだけsymlinkしたい場合は以下

${HOME}/.config/yadm/alt/.gitconfig##os.Darwin

Linuxだけsymlinkしたい場合は以下

${HOME}/.config/yadm/alt/.gitconfig##os.Linux

このようにすることで、OS別でsymlinkのするしないをコントロールできます。

## Templates

またalternate filesにはtemplate engineがあります。

## Templates

### Templates are a special kind of alternate file. The templatecontent and host specific data are combined as input to a…

yadm.io

自分はtemplate engineのprocessorには4種類あります。

-   default
-   esh
-   j2cli
-   envtpl

自分はdefaultしか使っていないのでここではdefaultの説明をします。

どんなtemplate処理ができるのかというとExposed dataに記載があります。

今回、自分が使ったのはyadm.osくらいでした。

### example) ${HOME}/.config/yadm/alt/.bash\_private

Plain textcontent\_copy

```
###############################################################################
# fastfetch
{% include ".bash_private.d/fastfetch/fastfetch" %}
```

上記のようにinclude文も使えます。

Plain textcontent\_copy

```
${HOME}/.config/yadm/alt/.bash_private.d/fastfetch/fastfetch
```

は以下

Plain textcontent\_copy

```
declare -x enable_fastfetch=true
if command -v fastfetch &> /dev/null; then
  if "${enable_fastfetch}"; then
    fastfetch
  fi
fi
```

yadm altを実行するとsymlinkが貼られます。

### example) ifとyadm.osを利用したtemplateの条件分岐

以下のように記載することでmacOSではhomebrewを  
Linuxではlinuxbrewを使うことができます。

Plain textcontent\_copy

```
{% if yadm.os == "Darwin" %}
# homebrew
{% include ".bash_private.d/homebrew/homebrew.{{ yadm.os }}" %}
{% endif %}

{% if yadm.os == "Linux" %}
# linuxbrew
{% include ".bash_private.d/linuxbrew/linuxbrew.{{ yadm.os }}" %}
{% endif %}
```

実際のファイル配置は以下のようにすれば読み込めます。

homebrew.{{ yadm.os }}となっているのでOSに置換されます。

-   ${HOME}/.config/yadm/alt/.bash\_private.d/homebrew/homebrew.Darwin
-   ${HOME}/.config/yadm/alt/.bash\_private.d/linuxbrew/linuxbrew.Linux

実際の自分のalt directoryの中はこのようになっています。

![linuxbrewの画面（1）](/_astro/image-02.DMaFVZca_k36Qw.webp)

もともと、いろんなものを自由に組み込み、管理し外すことができるようにするためにこのような形にしています。

もともとbashの設定をかなり拡張していて・・・😅

もはや、ほとんど趣味の世界なんですが・・・

よく見るとweztermやneovimのpluginなどmacOS上でしか使わないものなどもあり、このyadm alternate filesとtemplateとconditionの仕組みを使いコントロールすることができました。

例としてはneovimの[im-select.nvim](https://github.com/keaising/im-select.nvim)などはmacOS上でしか使わないため、無効化しています。

![linuxbrewの画面（2）](/_astro/image-03.AOtlOX23_1YmGYx.webp)

最初はNeoVimのluaの中でOS Checkしてたのですが、AstroNvimはplugins directoryにファイルがあると検知してnilが返ってErrorでるのでやめました😅

ファイルを個別にするなと言われると、その通りなんですが、管理しやすいので・・・😅

他にはenv.VARなど環境変数から取り込む機能もあります。

## yadm encrypt/decrypt

[yadm](https://yadm.io/)にはファイル群に対しての暗号化と復号化機能を持っています。

## Encryption

### It can be useful to manage confidential files, like SSH keys, across multiplesystems. However, doing so would put plain…

yadm.io

デフォルトではgnupgを利用するようです。  
opensslに変更することも可能みたいです。

オフィシャルではsshの鍵を設定する手法が紹介されていますが、自分の環境では、社員とはいえ他者に見られる可能性があるためやめました。

またやるとなるとTemplateを用いて${HOME}/.ssh/configもコントロールする必要があるので、これもしていません。

## yadm hook

[yadm](https://yadm.io/)はgitのwrapになっていますが、そのgitにおけるhookを仕込むことができます。

## Hooks

### For every command yadm supports, a program can be provided to run before orafter that command. These are referred to as…

yadm.io

こちらも今のところ使っていません。

なにか思いついたら追加していこうと思います。

## 感想

一通り、yadmの説明をしてみました。

これでmacOSとLinuxのdotfilesを管理できます。

実際に[Comparisons](https://yadm.io/docs/faq#comparisons)でも紹介されていますが、dotfilesを管理する手法はいろいろあります。

-   [homeshick](https://github.com/andsens/homeshick)
-   [vcsh](https://github.com/ek9/vcsh-dotfiles)

他にも[awesome-dotfiles Tools](https://github.com/webpro/awesome-dotfiles?tab=readme-ov-file#tools)を見れば、たくさんあります。

-   [chezmoi](https://github.com/twpayne/chezmoi)
-   [rotz](https://github.com/volllly/rotz)

[chezmoi](https://github.com/twpayne/chezmoi)あたりが新しくて多機能で、postもちらほら見るので良さげです。

[rotz](https://github.com/volllly/rotz)もOS別に設定だけでなくコンポーネントのInstallまでdotsというyamlやtomlやjsonで書けるconfigで制御できるみたいです。

yadmで自分は問題ないけど、mediamのpost書くために[chezmoi](https://github.com/twpayne/chezmoi)も使ってみようかな・・・  
いや[rotz](https://github.com/volllly/rotz)の方が記事がないのでマニアックで良いかな🤣

bashのframeworkである[rerun](https://rerun.github.io/rerun/)でmacOSのsetupをしていますが、良いタイミングなのでやめるかなぁ・・・

rerunによる縛りがなくなればzshに移行できるぜ😆

## Appendix: xdg-ninja

[xdg-ninja](https://github.com/b3nj5m1n/xdg-ninja)の紹介

## GitHub - b3nj5m1n/xdg-ninja: A shell script which checks your $HOME for unwanted files and…

### A shell script which checks your $HOME for unwanted files and directories. - b3nj5m1n/xdg-ninja

github.com

> A shell script that checks your `$HOME` for unwanted files and directories.When `xdg-ninja` encounters a file or directory it knows about, it will tell you whether it’s possible to move it to the appropriate location, and how to do it.The configurations are from the [arch wiki page on XDG\_BASE\_DIR](https://wiki.archlinux.org/title/XDG_Base_Directory), [antidot](https://github.com/doron-cohen/antidot) (thanks to Scr0nch for writing a conversion tool), and crowdsourced by other users.

簡単にいうと${HOME}にあるファイルをXDG\_BASE\_DIRに移行できるものを列挙してくれます。

Plain textcontent\_copy

```
> xdg-ninja

~~~ 省略 ~~~
[zsh]: /Users/[Username]/.zshenv

  Move the file to "$HOME"/.config/zsh/.zshenv and export the following environment variable:

    export ZDOTDIR="$HOME"/.config/zsh

  You can do this in /etc/zshenv (Or /etc/zsh/zshenv, on some distros).

[zsh]: /Users/[Username]/.zshrc

  Move the file to "$HOME"/.config/zsh/.zshrc and export the following environment variable:

    export ZDOTDIR="$HOME"/.config/zsh

  You can do this in /etc/zshenv (Or /etc/zsh/zshenv, on some distros).

Done checking your $HOME.
```

このような出力をしてくれ、XDG\_BASE\_DIRへ移行するのに便利です。

自分の場合はyadmで管理し始めたため、一部環境ごとに別々にしたいものなどがあるためすべての対応をするのではなく、選択して対応しています。

ターミナル環境について他の記事も書いているので、よろしければこちらもご覧ください！  
[『ターミナルがダサいとモテない』シリーズ一覧](https://blog.grasys.io/tags/series-terminal-update)

転載：[ターミナルがダサいとモテない。macOSとLinuxのXDG\_CONFIG\_HOMEを共有するぞ - yadm編](https://medium.com/@yusuke_h/%E3%82%BF%E3%83%BC%E3%83%9F%E3%83%8A%E3%83%AB%E3%81%8C%E3%83%80%E3%82%B5%E3%81%84%E3%81%A8%E3%83%A2%E3%83%86%E3%81%AA%E3%81%84-macos%E3%81%A8linux%E3%81%AExdg-config-home%E3%82%92%E5%85%B1%E6%9C%89%E3%81%99%E3%82%8B%E3%81%9E-yadm%E7%B7%A8-e4ce0effb03e)

この記事は [Medium（@yusuke\_h）](https://medium.com/@yusuke_h) からの転載です。

## この記事を書いた人

[![](/_astro/yusukeh.BvUd2yKE_1mQ6Fp.webp)](/authors/yusukeh/)

### [yusukeh](/authors/yusukeh/)

Fly high. Think deep. Move fast. Go far.🦅

-   [X](https://x.com/yusukeh "X")
-   [GitHub](https://github.com/yusukeh "GitHub")
-   [Medium](https://medium.com/@yusukeh "Medium")
-   [Facebook](https://www.facebook.com/yusuke.exzm "Facebook")
-   [Instagram](https://www.instagram.com/yusukehasegawa/ "Instagram")
-   [LinkedIn](https://www.linkedin.com/in/hasegawa-yusuke-091b4164/ "LinkedIn")

[プロフィールと記事一覧](/authors/yusukeh/)