Skip to content

Instantly share code, notes, and snippets.

@Leko
Last active March 13, 2026 02:49
Show Gist options
  • Select an option

  • Save Leko/c71a64716811ba038da11bf02b795ee7 to your computer and use it in GitHub Desktop.

Select an option

Save Leko/c71a64716811ba038da11bf02b795ee7 to your computer and use it in GitHub Desktop.
Setup local from scratch
#########################
# Prompt
#
# 参考:bashプロンプトのカスタマイズ http://www.deftrash.com/blog/archives/2006/05/bash_1.html
# NOTE: 使える変数
# \u: カレントユーザ名
# \h: ホスト名(短い)
# \H: ホスト名(長い)
# \w: $HOMEからカレントディレクトリへのパス
# \W: カレントディレクトリ名
# \d: "Fri May 26" みたいな形式の日付
# \t: hh:MM:ss形式の時刻(24h)
# \T: hh:MM:ss形式の時刻(12h)
# \n: 改行
# \S: rootなら#、その他なら$を表示する
#########################
if [ -f $(brew --prefix)/etc/bash_completion ]; then
source $(brew --prefix)/etc/bash_completion
fi
source $(brew --prefix)/etc/bash_completion.d/git-prompt.sh
export GIT_PS1_SHOWSTASHSTATE=1
export GIT_PS1_STATESEPARATOR='|'
export PS1="\n[&:\j] \u: \[\e[00;34m\]\w\[\e[0m\]\[\e[00;35m\]\$(__git_ps1)\[\e[0m\]\n( ˘ω˘).oO( "
# export PATH=$PATH:$(brew --prefix)/share/git-core/contrib/diff-highlight
#########################
# History
#########################
# 連続した重複コマンドを履歴に残さない(ignoredups,ignorespace,erasedups)
export HISTCONTROL=ignoreboth
export HISTIGNORE="fg*:bg*:history*:cd*:jobs*"
export HISTSIZE=10000
#########################
# Override commands
#
# http://natelandau.com/my-mac-osx-bash_profile/
#########################
alias cp='cp -iv' # Preferred 'cp' implementation
alias mv='mv -iv' # Preferred 'mv' implementation
alias rm='rm -iv' # Preferred 'rm' implementation
alias mkdir='mkdir -pv' # Preferred 'mkdir' implementation
alias ll='ls -FGlAhp' # Preferred 'ls' implementation
cd() { builtin cd "$@"; ll; } # Always list directory contents upon 'cd'
alias less='less -FSRXc' # Preferred 'less' implementation
#########################
# Development > Bash
#########################
export GREP_OPTIONS='--color=auto'
export LS_COLORS="no=00:fi=00:di=32:ln=36"
#########################
# AI Coding
#########################
export PATH="$HOME/.local/bin:$PATH"
wn() {
repo=$(basename $(git rev-parse --show-toplevel))
git worktree add ../${repo}-${1} -b ${1}
cd ../${repo}-${1}
cp ../${repo}/.env.local ./
nvm use
npm i
npm run setup
npm run prisma:generate
npx next typegen
claude --chrome --permission-mode plan
}
wx() {
repo=$(basename $(dirname $(git rev-parse --git-common-dir)))
current=${PWD##*/}
# フォルダ名はproject-<branch>という形式になっている
branch=${current##${repo}-}
echo repo=$repo current=$current branch=$branch
cd ../$repo
git worktree remove ../$current
git bd $branch
}
#########################
# Development > Homebrew
#########################
HOMEBREW_CASK_APP_DIR=/Applications
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
export HOMEBREW_CASK_OPTS=--appdir=$HOMEBREW_CASK_APP_DIR
export HOMEBREW_MAKE_JOBS=4
#########################
# Programming > Git
#########################
# Require Bash 4.0+
peco_ghq() {
local selected
selected="$(ghq list -p | peco --null)"
if [ -n "$selected" ]; then
cd $selected
fi
}
# http://qiita.com/comutt/items/f54e755f22508a6c7d78
peco_select_history() {
local cmd=$(history | awk '{$1=""; print}' | sort | uniq -c | sort -nr | awk '{$1=""; print}' | sed 's/^ //' | peco --initial-filter=Fuzzy --query "$READLINE_LINE")
# 出現件数でソートせずにuniqする場合はこちら
# local cmd=$(history | awk '$1=""; !a[$0]++{print}' | peco --query "$READLINE_LINE")
READLINE_LINE="$cmd"
READLINE_POINT=${#l}
}
bind -x '"\C-]": peco_ghq'
bind -x '"\C-r": peco_select_history'
#########################
# Programming > nvm
#########################
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
nvm install --lts
nvm use --lts
#########################
# Development > Node.js
#########################
eval $(npm completion)
alias t='npm test'
_npm_run_peco() {
local cur prev cword
_get_comp_words_by_ref -n : cur prev cword
if [ "$prev" = "run" ] || [ "$prev" = "yarn" ]; then
COMPREPLY=$(cat package.json | jq -r '.scripts | keys[]' | peco --initial-filter=Fuzzy --query=$cur)
fi
}
complete -F _npm_run_peco npm yarn
_npm_install_peco() {
local cur prev cword
_get_comp_words_by_ref -n : cur prev cword
if [[ "$cur" =~ @$ ]]; then
PACKAGE=${cur%@}
COMPREPLY=${PACKAGE}@$(npm show $PACKAGE time --json | jq -r 'del(.created,.modified) | keys[]' | sort -r | peco --initial-filter=Fuzzy)
elif [ "$prev" = "install" ] || [ "$prev" = "add" ]; then
COMPREPLY=$(npm search --json $cur | jq -r '.[].name' | peco --initial-filter=Fuzzy --query=$cur)
fi
}
complete -F _npm_install_peco npm yarn
_npx_peco() {
local cur prev cword
_get_comp_words_by_ref -n : cur prev cword
if [ "$prev" = "npx" ]; then
COMPREPLY=$(ls node_modules/.bin/ | peco --initial-filter=Fuzzy --query=$cur)
fi
}
complete -F _npx_peco npx
[alias]
b = branch
bd = branch -D
cm = commit -m
c = commit
co = checkout
cb = checkout -b
ca = commit --amend
s = status --short --branch
f = fetch --all --tags --prune
l = log --decorate --oneline --graph
ls = log --decorate --oneline --graph --stat --find-renames
gi = grep -n -i
mnff = merge --no-ff
default-branch = "!gi() { REMOTE=${1:-origin}; git symbolic-ref refs/remotes/${REMOTE}/HEAD | sed \"s@^refs/remotes/${REMOTE}/@@\" ;}; gi"
ignore = "!gi() { curl -L -s https://www.gitignore.io/api/$@ ;}; gi"
pr = "!po() { git push origin HEAD && hub compare $(git symbolic-ref --short HEAD) ;}; po"
com = "!gi() { CB=$(git rev-parse --abbrev-ref HEAD); BRANCH=${1:-$(git default-branch)}; git fetch --all && git branch -D $BRANCH && git checkout $BRANCH && git bd $CB ;}; gi"
comu = "!gi() { CB=$(git rev-parse --abbrev-ref HEAD); BRANCH=${1:-$(git default-branch upstream)}; git fetch --all && git branch -D $BRANCH && git checkout -b $BRANCH upstream/$BRANCH && git bd $CB ;}; gi"
p = push origin HEAD
tl = tag -l --sort=v:refname
wc = "!wc() { git worktree add ../project-${1} -b ${1} && echo hoge && pwd && cd ../project-${1} && pwd &&echo bar ;}; wc"
[ui]
color = true
[core]
pager = delta
attributesfile = ~/.gitattributes
excludesfile = ~/.gitignore
[interactive]
diffFilter = delta --color-only
[add.interactive]
useBuiltin = false # required for git 2.37.0
[delta]
navigate = true # use n and N to move between diff sections
light = false # set to true if you're in a terminal w/ a light background color (e.g. the default macOS terminal)
side-by-side = true
keep-plus-minus-markers = true
line-numbers = true
[merge]
conflictstyle = diff3
[diff]
colorMoved = default
algorithm = histogram
renames = true
[diff "json"]
textconv = "jq ."
[grep]
lineNumber = true
threads = 16
fallbackToNoIndex = true
[filter "lfs"]
clean = git-lfs clean %f
smudge = git-lfs smudge %f
required = true
[user]
name = Leko
email = leko.noor@gmail.com
#!/bin/bash
set -euo pipefail
echo ">>> デフォルトシェルをbashに変更"
if [ "$(dscl . -read ~/ UserShell | awk '{print $2}')" != "/bin/bash" ]; then
chsh -s /bin/bash
fi
# Apply System Preferences
echo ">>> Dock: 自動的に隠す & 起動中のアプリのみ表示"
defaults write com.apple.dock autohide -bool true
defaults write com.apple.dock static-only -bool true
echo ">>> ホットコーナー: 左下=デスクトップ, 右下=スクリーンセーバー"
defaults write com.apple.dock wvous-bl-corner -int 4
defaults write com.apple.dock wvous-bl-modifier -int 0
defaults write com.apple.dock wvous-br-corner -int 5
defaults write com.apple.dock wvous-br-modifier -int 0
echo ">>> Dockを再起動"
killall Dock
echo ">>> Caps LockをControlに割り当て"
KEYREMAP_PLIST=/Library/LaunchDaemons/com.local.KeyRemapping.plist
if [ ! -f "$KEYREMAP_PLIST" ]; then
# 即時反映(Sonoma以降はsudoが必要)
sudo hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x7000000E0}]}'
# 再起動後も永続化(LaunchDaemon)
sudo tee "$KEYREMAP_PLIST" > /dev/null << 'PLIST'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.local.KeyRemapping</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/hidutil</string>
<string>property</string>
<string>--set</string>
<string>{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x7000000E0}]}</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
PLIST
sudo chown root:wheel "$KEYREMAP_PLIST"
sudo chmod 644 "$KEYREMAP_PLIST"
sudo launchctl bootstrap system "$KEYREMAP_PLIST"
fi
echo ">>> 電源接続時のスリープ設定"
if [ "$(pmset -g custom | awk '/AC Power/,0' | awk '/^ sleep/{print $2}')" != "0" ]; then
sudo pmset -c sleep 0
fi
echo ">>> 画面オフまで5分"
if [ "$(pmset -g | awk '/displaysleep/{print $2}')" != "5" ]; then
sudo pmset -a displaysleep 5
fi
echo ">>> スクリーンセーバー後、直ちにパスワードを要求"
defaults write com.apple.screensaver askForPassword -int 1
defaults write com.apple.screensaver askForPasswordDelay -int 0
echo ">>> キーリピート設定"
defaults write NSGlobalDomain KeyRepeat -int 2
defaults write NSGlobalDomain InitialKeyRepeat -int 10
echo ">>> マウスの速度"
defaults write NSGlobalDomain com.apple.mouse.scaling -float 0.75
echo ">>> Finder: 全ファイルの拡張子を表示"
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
echo ">>> トラックパッド: タップでクリック"
defaults write com.apple.AppleMultitouchTrackpad Clicking -bool true
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true
echo ">>> 自動スペル修正を無効化"
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false
# ----------------------------------------
# Install CLI Tools
# ----------------------------------------
echo ">>> Homebrewをインストール"
if ! command -v brew &>/dev/null; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
eval "$(/opt/homebrew/bin/brew shellenv)"
echo ">>> brew install"
brew install wget git gh ghq peco bitwarden
brew install --cask ghostty
echo ">>> nvmをインストール"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash
export PATH="$HOME/.local/bin:$PATH"
echo ">>> Claude Codeをインストール"
if ! command -v claude &>/dev/null; then
curl -fsSL https://claude.ai/install.sh | bash
fi
# ----------------------------------------
# Dotfiles
# ----------------------------------------
echo ">>> Dotfilesを配置"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cp "$SCRIPT_DIR/.bashrc" ~/.bashrc
cp "$SCRIPT_DIR/.gitconfig" ~/.gitconfig
echo ">>> セットアップ完了"

Comments are disabled for this gist.