Date: 2020-04-15
Speaker: Hiroshi Nishigami (hnishi)
![]()
HHKB (Happy Hacking Keyboard)
を買いました。 ![]()

最近(去年12月頃⛄️)、 自分の dotfiles を整理した ため、共有しようと思いました。
(+ 3 ヶ月くらい使ってみた感想)
ターミナル (CLI) 初学者向け。
実は整理してる人少ないのではないかとおもっていたのですが、
もし「そんなの当たり前」レベルの話でしたら申し訳ありません。
作業効率化的な要素が強い話です。
https://thenextweb.com/dd/2019/06/04/why-does-macos-catalina-use-zsh-instead-of-bash-licensing/
「環境構築で消耗していませんか?」
dotfilesを極めることで、どこで作業していても自分の環境を瞬時にサクっと作り出すことができる
まぁつまり全エンジニアが対象だ!!!
Ref: ようこそdotfilesの世界へ
ちょっと検索しただけでも、プログラマーごとに色が出過ぎている。
https://github.com/hnishi/dotfiles
Please forgive me for the messy.
ワンラインのコマンド一発で、ダウンロードとインストールを行えるようにしました
bash だけで展開できる最小構成の dotfiles レポジトリ を参考にさせてもらいました。
curl -L raw.githubusercontent.com/hnishi/dotfiles/master/scripts/download.sh | bash
if is_exists "git"; then
# --recursive equals to ...
# git submodule init
# git submodule update
git clone --recursive "$DOTFILES_GITHUB" "$DOTPATH"
elif is_exists "curl" || is_exists "wget"; then
# curl or wget
local tarball="https://github.com/hnishi/dotfiles/archive/master.tar.gz"
if is_exists "curl"; then
curl -L "$tarball"
elif is_exists "wget"; then
wget -O - "$tarball"
fi | tar xvz
if [ ! -d dotfiles-master ]; then
log_fail "dotfiles-master: not found"
exit 1
fi
command mv -f dotfiles-master "$DOTPATH"
レポジトリに存在する . (ドット) から始まるファイル or ディレクトリに関して、
既存ファイルのバックアップを取って、ホームディレクトリにシンボリックリンクを貼る
if [[ "$HOME" != "$dotdir" ]];then
for f in $dotdir/.??*; do
[[ `basename $f` == ".git" ]] && continue
if [[ -L "$HOME/`basename $f`" ]];then
command rm -f "$HOME/`basename $f`"
fi
if [[ -e "$HOME/`basename $f`" ]];then
command mv --backup=numbered "$HOME/`basename $f`" "$HOME/.gdotbackup"
fi
command ln -snf $f $HOME
done
mv の --backup=numbered オプションをつければ、番号を振ってバックアップしてくれます。
私は最近知りました。
$ ls -a ~/.bashrc*
/Users/hnishi/.bashrc
/Users/hnishi/.bashrc_local
/Users/hnishi/.bashrc_linux
/Users/hnishi/.bashrc_mac

.bash_profile と .bashrc の違い
bash だと PROMPT_COMMAND に関数を指定すると、プロンプト表示時に実行される。
dispatch () {
local EXIT_STATUS="$?" # 直前のコマンド実行結果のエラーコードを保存
timer_stop # 直前のコマンドの処理時間を図るためのタイマー(関数)
get_datetime # 現在時刻を取得する関数
local status_color="" # exit status によって色を変える
if [ $EXIT_STATUS != 0 ]; then
status_color=$PALE_RED
else
status_color=$DARK_GREEN
fi
export PS1="${GREEN}${PS1_USER}${WHITE}:${PALE_BLUE}\w${CYAN}$(__git_ps1) ${status_color} [exit: \$?] ${WHITE}[last: ${timer_show}s] [${prompt_datetime}]\n\$ "
}
export PROMPT_COMMAND=dispatch
bash + {git,curl,wget}
があれば即座にインストールできます
もしかすると、curl も使わなくてもいいのかもしれませんが、これは試してないです。
exec 3<>/dev/tcp/www.google.com/80
echo -e "GET / HTTP/1.1\r\nhost: http://www.google.com\r\nConnection: close\r\n\r\n" >&3
cat <&3
https://www.linuxjournal.com/content/more-using-bashs-built-devtcp-file-tcpip
以下にあるコードをコピーすると、レポジトリに dotfiles を配置するだけで使えます
(bashのみ対応)。
https://github.com/hnishi/dotfiles/releases/tag/minimal-template-v0
もっと高度な内容を知りたい方は、以下のリンクを参考にしてみて下さい。
(個人的にわかりやすかった記事)
いろいろと調べていると弊社にいる magicant さんが yash なるPOSIX準拠のシェルを開発していることを知りました。
あらためて ACCESS にはすごい技術者がいるものだと再認識しました。
(PC ごとの path 等が設定ファイルに入ってくるので結構面倒)
Visual Studio Code が公式の設定ファイル同期ツールを発表
(現在 preview 版のみ)
まだ使ったことはないですが、期待。
マイクロソフトアカウントへの sign in が必要みたい。
簡単に、プロンプトを設定
starshippowerlevel10k
pure