Open10
[WSL Ubuntu] ghq, peco, git, Ruby, fzf, eza 導入
powershell
wsl --install -d Ubuntu-22.04
ghq, peco, 他インストール手順
# peco を apt でインストールすると文字化けをしてしまったので、直接DLして対応
cd /tmp
wget https://github.com/peco/peco/releases/download/v0.5.11/peco_linux_amd64.tar.gz
tar -xzf peco_linux_amd64.tar.gz
sudo mv peco_linux_amd64/peco /usr/local/bin/
peco --version
git の設定
git
git config --global user.name "John Doe"
git
git config --global user.email johndoe@example.com
Ubuntuターミナルのプロンプトにgitブランチ表示
.bashrc に以下追加
bash
# prompt git branch
export PS1='\[\033[01;32m\]\u@\h\[\033[01;33m\] \w \[\033[01;31m\]$(__git_ps1 "(%s)") \n\[\033[01;34m\]\$\[\033[00m\] '
bash
. ~/.bashrc
github アカウントを使い分ける(ssh)
名前、メアド設定をして ~/.gitconfig を作っておく。
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
git ssh を振り分けるための ssh config。
private用、sub1用、sub2用でsshキー、メアドを使い分けている例。
~/.ssh/config
Host github.com.private # プライベートアカウント
HostName github.com
User git
Port 22
IdentityFile ~/.ssh/id_ed25519_private
TCPKeepAlive yes
IdentitiesOnly yes
Host github.com.sub1 # サブアカウント1
HostName github.com
User git
Port 22
IdentityFile ~/.ssh/id_ed25519_sub1 # サブアカウント1用の鍵
TCPKeepAlive yes
IdentitiesOnly yes
Host github.com.sub2 # サブアカウント2
HostName github.com
User git
Port 22
IdentityFile ~/.ssh/id_ed25519_sub2 # サブアカウント2用の鍵
TCPKeepAlive yes
IdentitiesOnly yes
~/.gitconfig
[user]
name = Daichi Kikuchi
email = private@example.com
[includeIf "gitdir:~/ghq/github.com.sub1/"]
path = ~/.gitconfig_sub1
[includeIf "gitdir:~/ghq/github.com.sub2/"]
path = ~/.gitconfig_sub2
~/.gitconfig_sub2
[user]
name = Daichi Kikuchi
email = sub1@example.com
~/.gitconfig_sab2
[user]
name = Daichi Kikuchi
email = sub2@example.com
ssh接続確認
ssh -T git@github.com.private
ssh -T git@github.com.sub1
ssh -T git@github.com.sub2
bash
# rbenvインストール
sudo apt install rbenv
# ruby-build インストール
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
# インストール可能なRubyバージョン確認
rbenv install --list
# Ruby インストール
rbenv install 3.1.4
rbenv install 3.0.6
# gemset インストール
git clone https://github.com/jf/rbenv-gemset.git $HOME/.rbenv/plugins/rbenv-gemset
プロジェクト内でrubyを利用するとき
# ローカル ruby プロジェクト ruby-test を作成
mkdir ruby-test
cd $_
rbenv local 3.0.6
ruby --version
# ローカル ruby プロジェクト ruby-test で gemset 利用
rbenv gemset init
# gemset 確認
rbenv gemset list
# ローカル gemset 確認
rbenv gemset active
参考
VS Code で Ruby ソースのタブを2スペースにする
ショートカット Ctrl + Shift + P で以下を選択
preferences: configure language specific settings
Ruby を選択し、フィルタを以下で入力
@lang:ruby tabsize
Editor: Tab Size を 2 に変更
Rails インストール
インストール可能なバージョン確認
#gem search --exact --all rails
gem search -ea rails
インストール
gem install rails -v 6.1.7.6
# 確認
gem info -e rails
# バージョン指定アプリ作成
rails _6.1.7.6_ new sandbox-app
rails7 で rails new して以下エラーになったとき
An error occurred while installing psych (5.1.0), and Bundler cannot continue.
Gemfile に以下を追加して bundle install (bundle update)
gem "psych", "~> 4.0"
[WLS Ubuntu] fzf 導入
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install
[WSL Ubuntu] eza, nerd-fonts 導入
eza 導入
WSL Ubuntu で実行
cargo install eza
nerd-fonts (オープンソースフォント) をインストール
Windows Terminal から WSL Ubuntu でアイコンを表示させるには Windows 側に nerd-fonts をインストールする必要があります。
Powershell で実行
& ([scriptblock]::Create((iwr 'https://to.loredo.me/Install-NerdFont.ps1')))
bashrc
# eza alias
alias ei="eza --icons --git"
alias ea="eza -a --icons --git"
alias ee="eza -aahl --icons --git"
alias et="eza -T -L 3 -a -I 'node_modules|.git|.cache' --icons"
alias eta="eza -T -a -I 'node_modules|.git|.cache' --color=always --icons | less -r"
alias ls=ei
alias la=ea
alias ll=ee
alias lt=et
alias lta=eta
alias l="clear && ls"