Categories
Tags
Alamofire Android AppStoreConnect AWS Bun C++ cAdvisor CFW Cloudflare Cloudflare Access Cloudflare KV Cloudflare Tunnel Cloudflare Workers D1 Deno DevContainer Discord Docker ECR ECS Edizon Emulator EmuMMC Fastlane Firestore Frida Ghidra Git GitHub GitHub Actions GitLab GPG Grafana HACGUI Heroku Homebrew Hono IDA Pro iOS IPSwitch Jailbreak Javascript JSON JWT LanPlay Linode macOS Mirakurun MongoDB NestJS NextJS Nintendo Nintendo Switch NodeJS PHP PostgreSQL Prisma Programming Prometheus Python React Realm RealmSwift Ruby Salmon Run Salmonia3+ Shogi Sideload Snap Splatoon Splatoon2 Splatoon3 SSH Stable Diffusion Starlight Swift Swift Package SwiftUI Switch TensorRT Turf War Typescript TypeScript Ubuntu Ubuntu Server VNC VPN VSCode Vue WARP Wireguard XCode Xcode yarn zsh 家電 横歩取り
361 words
2 minutes
Ubuntuでzshを使おう
概要
Ubuntuの使い勝手を良くしていきます。
zshへの切り替え
sudo apt install zsh -y
chsh
パスワード入力を求められたら/usr/bin/zsh
と入力する。
Homebrewの導入
sudo apt install -y build-essential procps curl file git
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
エンターを押すとインストールが始まる。終わったら以下のコマンド入力。
(echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> /home/mini/.zshrc
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
Node Version Manager
brew install nvm
でインストールが始まる。
mkdir ~/.nvm
export NVM_DIR="$HOME/.nvm"
[ -s "/home/linuxbrew/.linuxbrew/opt/nvm/nvm.sh" ] && \. "/home/linuxbrew/.linuxbrew/opt/nvm/nvm.sh" # This loads nvm
[ -s "/home/linuxbrew/.linuxbrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/home/linuxbrew/.linuxbrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
とすれば反映される。
Git
mkdir ~/.zsh
cd ~/.zsh
curl -o git-prompt.sh https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
curl -o git-completion.bash https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
curl -o _git https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.zsh
現在いるブランチとかが表示される、便利。
最後に
# Fig
[[ -f "$HOME/.fig/shell/zshrc.pre.zsh" ]] && builtin source "$HOME/.fig/shell/zshrc.pre.zsh"
# GIT
source ~/.zsh/git-prompt.sh
fpath=(~/.zsh $fpath)
zstyle ':completion:*:*:git:*' script ~/.zsh/git-completion.bash
autoload -Uz compinit && compinit
GIT_PS1_SHOWDIRTYSTATE=true
GIT_PS1_SHOWUNTRACKEDFILES=true
GIT_PS1_SHOWSTASHSTATE=true
GIT_PS1_SHOWUPSTREAM=auto
# NVM
export NVM_DIR="$HOME/.nvm"
[ -s "/home/linuxbrew/.linuxbrew/opt/nvm/nvm.sh" ] && \. "/home/linuxbrew/.linuxbrew/opt/nvm/nvm.sh"
[ -s "/home/linuxbrew/.linuxbrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/home/linuxbrew/.linuxbrew/opt/nvm/etc/bash_completion.d/nvm"
# Load NVM
autoload -U add-zsh-hook
load-nvmrc() {
if [[ -f .nvmrc && -r .nvmrc ]]; then
nvm use
elif [[ $(nvm version) != $(nvm version default) ]]; then
echo "Reverting to nvm default version"
nvm use default
fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc
# Load VENV
autoload -U add-zsh-hook
load-pyenv() {
if [[ -r .venv ]]; then
source .venv/bin/activate
elif [[ -n "$VIRTUAL_ENV" && $PWD != ${VIRTUAL_ENV%/*} && $PWD != ${VIRTUAL_ENV%/*}/* ]]; then
deactivate
fi
}
add-zsh-hook chpwd load-pyenv
load-pyenv
# Load Rbenv
[[ -d ~/.rbenv ]] && \
export PATH=${HOME}/.rbenv/bin:${PATH} && \
eval "$(rbenv init -)"
# Fig
[[ -f "$HOME/.fig/shell/zshrc.post.zsh" ]] && builtin source "$HOME/.fig/shell/zshrc.post.zsh"
これで変更が効かないときはexec zsh
を実行すると良い。
Ubuntu Zsh (via Vagrant) is not locating Zsh or its functions
Ubuntuでzshを使おう
https://fuwari.vercel.app/posts/2024/02/ubunth_zsh/