LoginSignup
17

More than 5 years have passed since last update.

Atom エディタのdotfiles とパッケージを管理する

Posted at

Atom のdotfiles 管理

Adding Atom to Your Dotfiles を参考にしたところ、以下の5つを管理すれば大丈夫らしい。

  • config.cson
  • init.coffee
  • keymap.cson
  • snippets.cson
  • styles.less

こんな感じでシンボリックリンク貼ってます。

% ls -lF ~/.atom
total 40
drwxr-xr-x   5 yulii  staff   170  4 26 19:30 blob-store/
drwxr-xr-x  34 yulii  staff  1156  4 25 22:26 compile-cache/
lrwxr-xr-x   1 yulii  staff    48  4 26 19:30 config.cson@ -> /Users/yulii/projects/dotfiles/.atom/config.cson
lrwxr-xr-x   1 yulii  staff    48  4 26 19:30 init.coffee@ -> /Users/yulii/projects/dotfiles/.atom/init.coffee
lrwxr-xr-x   1 yulii  staff    48  4 26 19:30 keymap.cson@ -> /Users/yulii/projects/dotfiles/.atom/keymap.cson
drwxr-xr-x  13 yulii  staff   442  4 26 19:12 packages/
lrwxr-xr-x   1 yulii  staff    50  4 26 19:30 snippets.cson@ -> /Users/yulii/projects/dotfiles/.atom/snippets.cson
drwxr-xr-x  14 yulii  staff   476  4 10 19:54 storage/
lrwxr-xr-x   1 yulii  staff    48  4 26 19:30 styles.less@ -> /Users/yulii/projects/dotfiles/.atom/styles.less

config.json の userId について

config.jsonuserId というハッシュ値が入っているがセキュリティ的には公開しても問題ないらしい。ちょっと気持ち悪い感じがしますが。

https://github.com/atom/exception-reporting/issues/7
https://github.com/atom/metrics/issues/18

Atom のパッケージ管理

apm list でインストール済みのパッケージを一覧化できるのでそれを適当なファイルに出力して管理します。リストからインストールするには apm install --packages-file でファイルを指定すればOK.

# パッケージリストを保存
apm list --installed --bare packages.list

# パッケージリストからインストール
apm install --packages-file packages.list

という形です。出力した packages.list をGit 管理すればPC 間でパッケージを共有できます。

お手製シェルスクリプト

今のところコマンド覚えるのが面倒なので、シェルスクリプトにまとめてます。

atom/apm.sh
#!/bin/sh
set -eu
# set -x

CWD=$(pwd)
SWD=$(cd $(dirname $0) && pwd)
LWD=$(cd $(dirname $0) && cd .. && pwd)

# trap
trap 'echo -e "\nabort!" ; exit 1' 1 2 3 15

# config {{{
PACKAGES_FILE="$SWD/packages.list"
# }}}

function apm_link() {
  cd $HOME/.atom
  ln -nfs $LWD/.atom/config.cson    config.cson
  ln -nfs $LWD/.atom/init.coffee    init.coffee
  ln -nfs $LWD/.atom/keymap.cson    keymap.cson
  ln -nfs $LWD/.atom/snippets.cson  snippets.cson
  ln -nfs $LWD/.atom/styles.less    styles.less
}

function apm_install() {
  apm install --packages-file $PACKAGES_FILE
}

function apm_dump() {
  [ -f $PACKAGES_FILE ] && rm $PACKAGES_FILE
  apm list --installed --bare > $PACKAGES_FILE
}

function apm_save() {
  git checkout master
  apm_dump
  git add $PACKAGES_FILE && git commit -m 'update apm installed list' && git push
}

case "$1" in
  link)    apm_link    ;;
  install) apm_install ;;
  dump)    apm_dump    ;;
  save)    apm_save    ;;
  *)       apm_install ;;
esac

exit 0

構成変わってしまうかもしれないので、現時点のコミットファイルへリンクしておきます。
yulii/dotfiles

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
17