From 0b29e52b72c311a04253a7ab16c59a4f4b15f7ec Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 2 Nov 2025 12:36:27 +0000 Subject: [PATCH] Refactor: Add macOS support and improve OS-specific configs This commit introduces support for macOS alongside Linux, refactors the zsh configuration to be OS-aware using templates, and updates the README to reflect these changes. It also cleans up unused files and improves the overall structure of the dotfiles repository. Co-authored-by: tsuyoshi.nagamine --- .chezmoidata.yaml | 3 + .chezmoiignore | 35 ++++ README.md | 36 +++- dot_zshrc => dot_zshrc.tmpl | 193 +++++++++++------- ...nge_setup.sh => run_onchange_setup.sh.tmpl | 98 +++++++-- 5 files changed, 267 insertions(+), 98 deletions(-) create mode 100644 .chezmoidata.yaml create mode 100644 .chezmoiignore rename dot_zshrc => dot_zshrc.tmpl (57%) rename run_onchange_setup.sh => run_onchange_setup.sh.tmpl (53%) diff --git a/.chezmoidata.yaml b/.chezmoidata.yaml new file mode 100644 index 0000000..9388bd9 --- /dev/null +++ b/.chezmoidata.yaml @@ -0,0 +1,3 @@ +--- +is_linux: {{ eq .chezmoi.os "linux" }} +is_darwin: {{ eq .chezmoi.os "darwin" }} diff --git a/.chezmoiignore b/.chezmoiignore new file mode 100644 index 0000000..399e4b3 --- /dev/null +++ b/.chezmoiignore @@ -0,0 +1,35 @@ +{{- if eq .chezmoi.os "darwin" }} +# Linux??GUI?systemd?? +etc/ +private_dot_config/hypr/ +private_dot_config/foot/ +private_dot_config/gammastep/ +private_dot_config/gtk-3.0/ +private_dot_config/swaync/ +private_dot_config/waybar/ +private_dot_config/wofi/ +private_dot_config/xdg-desktop-portal/ +private_dot_config/private_fcitx5/ +private_dot_config/cursor-flags.conf +private_dot_config/electron-flags.conf +private_dot_config/electron27-flags.conf +private_dot_config/executable_brave-browser.desktop + +# Linux??????? +dot_local/bin/executable_hypr_auto_perfmonitor.sh +dot_local/bin/executable_hypr_perfmodeswitch.sh +dot_local/bin/executable_fix-brave-pwa.sh +dot_local/bin/executable_integrate-appimage.sh +dot_local/bin/executable_uninstall-appimage.sh +dot_local/bin/executable_swaync_launcher.sh +dot_local/bin/executable_unified_launcher.sh +dot_local/bin/lib_hypr_perfmode.sh +dot_local/bin/setup_sleep_backup.sh +dot_local/bin/executable_sleep_backup.sh +dot_local/share/applications/ +dot_local/share/dark-mode.d/ +dot_local/share/light-mode.d/ + +# Linux?????????? +pkglist.txt +{{- end }} diff --git a/README.md b/README.md index 4b8b0e9..ce40cbc 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ # dotfiles 個人的な設定ファイルを[chezmoi](https://www.chezmoi.io/)で管理するリポジトリです。 -主にEndeavourOS(Archベース)向けに最適化されています。 +**Linux(EndeavourOS/Arch)とmacOSの両環境に対応**しています。 ## 主な設定 +### Linux(EndeavourOS/Arch) - ディストリビューション: EndeavourOS / Arch Linux - シェル: Zsh + Starship - ウィンドウマネージャ: Hyprland @@ -15,9 +16,16 @@ - 開発ツール: Docker, lazygit, lazydocker, atuin - その他: git, SSH, waybar など +### macOS +- シェル: Zsh + Starship +- パッケージマネージャ: Homebrew +- エディタ: Neovim +- 開発ツール: mise, gh, ghq, fzf, atuin +- 1Password SSH Agent対応 + ## 使い方 -### インストール +### インストール(Linux) ```bash # chezmoiのインストール @@ -27,6 +35,16 @@ paru -S chezmoi chezmoi init --apply nagamine-git ``` +### インストール(macOS) + +```bash +# chezmoiのインストール(Homebrewがない場合は先にインストール) +brew install chezmoi + +# リポジトリの取得と適用 +chezmoi init --apply nagamine-git +``` + ### 更新 ```bash @@ -36,7 +54,19 @@ chezmoi apply -v ### パッケージ -必要なパッケージは `pkglist.txt` に記載されており、`run_onchange_setup.sh` 実行時に自動的にインストールされます。 +**Linux**: 必要なパッケージは `pkglist.txt` に記載されており、`run_onchange_setup.sh` 実行時に自動的にインストールされます。 + +**macOS**: Homebrewで基本パッケージが自動インストールされます(git, neovim, tmux, fzf, ripgrep, gh等)。 + +## OS別の動作 + +このdotfilesはchezmoiのテンプレート機能を使用してOS別に動作を変更します: + +- **Linux専用**: Hyprland設定、Waybar、fcitx5、keyd等のLinux GUI/システム設定 +- **macOS専用**: Homebrew管理、macOS用PATH設定、1Password統合 +- **共通**: Zsh設定、tmux設定、Neovim設定、開発ツール(mise, starship, sheldon等) + +macOS環境では`.chezmoiignore`によりLinux専用ファイルが自動除外されます。 ### tuigreet /etc/greetd/config.toml diff --git a/dot_zshrc b/dot_zshrc.tmpl similarity index 57% rename from dot_zshrc rename to dot_zshrc.tmpl index 95aecfc..bc15d9c 100644 --- a/dot_zshrc +++ b/dot_zshrc.tmpl @@ -1,67 +1,57 @@ # Created by newuser for 5.9 -# 基本的な環境変数 +# ???????? export LANG=ja_JP.UTF-8 export LC_ALL=ja_JP.UTF-8 export EDITOR=nvim +{{- if eq .chezmoi.os "darwin" }} +# ============================================================ +# macOS???? +# ============================================================ -# PATHの設定 - 一箇所にまとめてシンプル化 -export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$HOME/.local/share/nvim-linux-x86_64/bin:$PATH" +# Homebrew???? +if [[ $(uname -m) == "arm64" ]]; then + eval "$(/opt/homebrew/bin/brew shellenv)" +else + eval "$(/usr/local/bin/brew shellenv)" +fi + +# PATH??? +export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$PATH" export PATH="$PATH:$HOME/.local/share/mise/installs/python/*/bin" export GOPATH="$HOME/go" export PATH="$GOPATH/bin:$PATH" -export PATH="$PATH:/snap/bin" -export SSH_AUTH_SOCK="$HOME/.1password/agent.sock" -GPG_TTY=`tty` -export GPG_TTY -# export MISE_VERBOSE=1 -# 補完 -autoload -Uz compinit -compinit -i +# 1Password SSH Agent +export SSH_AUTH_SOCK="$HOME/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock" -# 補完の設定 -zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' # 大文字小文字を区別しない -zstyle ':completion:*' menu select # 補完メニューを有効化 -zstyle ':completion:*' verbose yes # 補完の詳細を表示 +# ?????????????macOS???pbcopy??? +alias pbcopy='pbcopy' +alias pbpaste='pbpaste' -# プラグイン管理 -eval "$(starship init zsh)" -# 通常のシェル: フルアクティベート -eval "$(mise activate zsh)" -eval "$(sheldon source)" -eval "$(atuin init zsh)" +{{- else if eq .chezmoi.os "linux" }} +# ============================================================ +# Linux???? +# ============================================================ -# Starship -unset PROMPT_EOL_MARK - -# コマンド履歴 -HISTFILE=~/.zsh_history -HISTSIZE=10000 -SAVEHIST=10000 -setopt hist_expire_dups_first -setopt hist_verify -setopt share_history -setopt extended_history - -# historyコマンドで時刻を表示 -alias history='fc -il 1' +# PATH??? - ????????????? +export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$HOME/.local/share/nvim-linux-x86_64/bin:$PATH" +export PATH="$PATH:$HOME/.local/share/mise/installs/python/*/bin" +export GOPATH="$HOME/go" +export PATH="$GOPATH/bin:$PATH" +export PATH="$PATH:/snap/bin" -# alias -alias vim='nvim' -alias svim='vim ~/.note.gpg' +# 1Password SSH Agent +export SSH_AUTH_SOCK="$HOME/.1password/agent.sock" -# ghqでクローンしたリポジトリへ簡単に移動するための関数 -cgh() { - local dir - dir=$(ghq list | fzf --no-multi --exit-0 --query="$*" --preview="ls -FA1 $(ghq root)/{}") - [ -n "$dir" ] && cd "$(ghq root)/$dir" || return -} +# Wayland??????? +alias pbcopy='wl-copy' +alias pbpaste='wl-paste' -# Cursorの実行 +# Cursor??? code() { - # 既存のCursorプロセスをチェック + # ???Cursor????????? if pgrep -f "cursor.*--no-sandbox" > /dev/null; then echo "Cursor is already running. Opening new window..." command /usr/bin/cursor "$@" --reuse-window @@ -72,52 +62,42 @@ code() { fi } -# ls系コマンドの統合 -alias ls='eza --icons --color=always' -alias ll='ls -l' -alias la='ls -la' -alias l='ls -l' -alias tree='ls --tree --git-ignore' -alias lmt='eza --tree --git-ignore --icons=never --classify' -alias supabase='npx supabase' -alias cursor='code' - -# Distroboxコンテナ準備の共通処理 +# Distrobox??????????? _ensure_kali_running() { - # Dockerサービスが起動しているか確認 + # Docker?????????????? if ! systemctl is-active --quiet docker; then - echo "→ Starting Docker service..." + echo "? Starting Docker service..." sudo systemctl start docker fi - # Kaliコンテナが存在するか確認 + # Kali???????????? if ! distrobox list | grep -q "^kali"; then - echo "→ Creating new Kali container (kali)..." + echo "? Creating new Kali container (kali)..." distrobox create --name kali --image docker.io/kalilinux/kali-rolling:latest --home ~/distrobox/kali --additional-flags "--privileged" fi return 0 } -# Kaliコンテナ内でコマンドを実行するヘルパー関数 +# Kali????????????????????? _distrobox_kali_exec() { _ensure_kali_running || return 1 - # distroboxのenterコマンドでbashコマンドを実行 + # distrobox?enter?????bash??????? distrobox enter kali -- bash -c "$@" return $? } -# Torを有効にしてKaliコンテナに入る(proxychains4使用) +# Tor??????Kali????????proxychains4??? k() { _ensure_kali_running || return 1 - echo "→ Entering Kali container with Tor (proxychains4)..." + echo "? Entering Kali container with Tor (proxychains4)..." distrobox enter kali -- bash -c ' - # systemd不要: ユーザーモードでTor起動(未起動なら) + # systemd??: ????????Tor????????? if ! pgrep -x tor >/dev/null 2>&1; then if ! command -v tor >/dev/null 2>&1; then - echo "[ERROR] tor が見つかりません。コンテナ内で: sudo apt-get update && sudo apt-get install -y tor proxychains4" >&2 + echo "[ERROR] tor ???????????????: sudo apt-get update && sudo apt-get install -y tor proxychains4" >&2 exit 1 fi mkdir -p "$HOME/.tor" @@ -130,27 +110,94 @@ Sandbox 0 EOF tor -f "$HOME/.tor/torrc-k" --RunAsDaemon 1 >/dev/null 2>&1 || { echo "[ERROR] Tor failed to start; opening normal shell (no proxy)"; exec /bin/bash --login; } fi - # 以降のシェルを proxychains4 でラップ + # ??????? proxychains4 ???? exec proxychains4 -q /bin/bash --login ' } -# 通常ネットワークモードでKaliコンテナに入る +# ????????????Kali??????? k_pub() { _ensure_kali_running || return 1 - echo "→ Entering Kali container with normal network..." + echo "? Entering Kali container with normal network..." distrobox enter kali -- bash -c ' exec /bin/bash --login ' } -alias pbcopy='wl-copy' alias b='~/.local/bin/biz_start.sh ' -source /home/tsuyoshi/.config/op/plugins.sh + +{{- end }} + +# ============================================================ +# ?????OS??? +# ============================================================ + +GPG_TTY=`tty` +export GPG_TTY +# export MISE_VERBOSE=1 + +# ?? +autoload -Uz compinit +compinit -i + +# ????? +zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' # ???????????? +zstyle ':completion:*' menu select # ?????????? +zstyle ':completion:*' verbose yes # ???????? + +# ??????? +eval "$(starship init zsh)" +# ??????: ????????? +eval "$(mise activate zsh)" +eval "$(sheldon source)" +eval "$(atuin init zsh)" + +# Starship +unset PROMPT_EOL_MARK + +# ?????? +HISTFILE=~/.zsh_history +HISTSIZE=10000 +SAVEHIST=10000 +setopt hist_expire_dups_first +setopt hist_verify +setopt share_history +setopt extended_history + +# history?????????? +alias history='fc -il 1' + +# alias +alias vim='nvim' +alias svim='vim ~/.note.gpg' + +# ghq????????????????????????? +cgh() { + local dir + dir=$(ghq list | fzf --no-multi --exit-0 --query="$*" --preview="ls -FA1 $(ghq root)/{}") + [ -n "$dir" ] && cd "$(ghq root)/$dir" || return +} + +# ls???????? +alias ls='eza --icons --color=always' +alias ll='ls -l' +alias la='ls -la' +alias l='ls -l' +alias tree='ls --tree --git-ignore' +alias lmt='eza --tree --git-ignore --icons=never --classify' +alias supabase='npx supabase' +alias cursor='code' + +{{- if eq .chezmoi.os "linux" }} +# 1Password CLI plugin?Linux????? +if [ -f /home/{{ .chezmoi.username }}/.config/op/plugins.sh ]; then + source /home/{{ .chezmoi.username }}/.config/op/plugins.sh +fi +{{- end }} # pnpm -export PNPM_HOME="/home/tsuyoshi/.local/share/pnpm" +export PNPM_HOME="{{ .chezmoi.homeDir }}/.local/share/pnpm" case ":$PATH:" in *":$PNPM_HOME:"*) ;; *) export PATH="$PNPM_HOME:$PATH" ;; diff --git a/run_onchange_setup.sh b/run_onchange_setup.sh.tmpl similarity index 53% rename from run_onchange_setup.sh rename to run_onchange_setup.sh.tmpl index 1a5eac1..0d891e8 100644 --- a/run_onchange_setup.sh +++ b/run_onchange_setup.sh.tmpl @@ -1,9 +1,9 @@ -#! /bin/bash +#! /usr/bin/env bash # Stop on error set -eu -# 汎用インストール関数 +# ?????????? install_if_missing() { local cmd=$1 local name=${2:-$1} @@ -17,6 +17,11 @@ install_if_missing() { fi } +{{- if eq .chezmoi.os "linux" }} +# ============================================================ +# Linux???????? +# ============================================================ + # keyboard layout sudo cp etc/keyd/default.conf /etc/keyd/default.conf @@ -32,22 +37,22 @@ curl -sS https://downloads.1password.com/linux/keys/1password.asc | gpg --import # Install packages paru -S --needed --noconfirm - < ~/pkglist.txt || echo "Some packages failed to install" -# フォント設定 +# ?????? sudo mkdir -p /usr/share/fonts -# Firgeフォントche +# Firge????che if [ ! -f /usr/share/fonts/Firge35NerdConsole-Regular.ttf ]; then - echo "Firgeフォントをインストールしています..." + echo "Firge????????????????..." - # GitHub APIを使用して最新バージョンを取得 + # GitHub API??????????????? LATEST_RELEASE_INFO=$(curl -s https://api.github.com/repos/yuru7/Firge/releases/latest) FIRGE_VERSION=$(echo $LATEST_RELEASE_INFO | grep -o '"tag_name": "[^"]*' | cut -d'"' -f4 | sed 's/^v//') if [ -z "$FIRGE_VERSION" ]; then - echo "最新バージョンの取得に失敗しました。デフォルトバージョンを使用します。" + echo "???????????????????????????????????" FIRGE_VERSION="0.3.0" else - echo "最新バージョン ${FIRGE_VERSION} を使用します。" + echo "??????? ${FIRGE_VERSION} ???????" fi wget -O /tmp/firge.zip "https://github.com/yuru7/Firge/releases/download/v${FIRGE_VERSION}/FirgeNerd_v${FIRGE_VERSION}.zip" @@ -57,39 +62,88 @@ if [ ! -f /usr/share/fonts/Firge35NerdConsole-Regular.ttf ]; then rm -rf /tmp/firge /tmp/firge.zip fc-cache -f -v else - echo "Firgeフォントはすでにインストールされています。スキップします。" + echo "Firge?????????????????????????????" fi # RobotoNotoSansJP if [ ! -f /usr/share/fonts/Roboto-NotoSansJP-Regular.ttf ]; then - echo "RobotoNotoSansJPフォントをインストールしています..." + echo "RobotoNotoSansJP????????????????..." [ -d /tmp/robotonoto ] && rm -rf /tmp/robotonoto git clone --depth 1 https://github.com/reindex-ot/RobotoNotoSansJP.git /tmp/robotonoto sudo cp /tmp/robotonoto/*.ttf /usr/share/fonts/ rm -rf /tmp/robotonoto fc-cache -f -v else - echo "RobotoNotoSansJPフォントはすでにインストールされています。スキップします。" + echo "RobotoNotoSansJP?????????????????????????????" fi -# アプリケーションのインストール -install_if_missing starship starship "curl -sS https://starship.rs/install.sh | sh" -install_if_missing sheldon sheldon "curl --proto '=https' -fLsS https://rossmacarthur.github.io/install/crate.sh | bash -s -- --repo rossmacarthur/sheldon --to ~/.local/bin --force" - # droidcam sudo dkms autoinstall sudo modprobe -r v4l2loopback sudo modprobe v4l2loopback devices=1 exclusive_caps=1 card_label="DroidCam 1920" max_width=1920 max_height=1080 -# gh extension -gh extension install HikaruEgashira/gh-q -ghq get HikaruEgashira/gh-q - -# tmux -git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm - # bluetooth echo "Enabling Bluetooth service..." sudo systemctl enable --now bluetooth sudo usermod -a -G bluetooth $USER +{{- else if eq .chezmoi.os "darwin" }} +# ============================================================ +# macOS???????? +# ============================================================ + +# Homebrew???????????????? +if ! command -v brew &> /dev/null; then + echo "Installing Homebrew..." + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + + # Apple Silicon??????PATH?? + if [[ $(uname -m) == "arm64" ]]; then + echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile + eval "$(/opt/homebrew/bin/brew shellenv)" + fi +fi + +# ????????????? +brew install \ + git \ + neovim \ + tmux \ + fzf \ + ripgrep \ + fd \ + bat \ + eza \ + ghq \ + mise \ + starship \ + sheldon \ + atuin \ + gh + +# ???????????Nerd Fonts? +brew tap homebrew/cask-fonts +brew install --cask font-firge-nerd-font || echo "Firge font already installed or unavailable" + +{{- end }} + +# ============================================================ +# ?????????Linux/macOS???? +# ============================================================ + +# ??????????????? +install_if_missing starship starship "curl -sS https://starship.rs/install.sh | sh -s -- -y" +install_if_missing sheldon sheldon "curl --proto '=https' -fLsS https://rossmacarthur.github.io/install/crate.sh | bash -s -- --repo rossmacarthur/sheldon --to ~/.local/bin --force" + +# gh extension +gh extension install HikaruEgashira/gh-q || echo "gh-q extension already installed" +ghq get HikaruEgashira/gh-q || echo "gh-q already cloned" + +# tmux plugin manager +if [ ! -d ~/.tmux/plugins/tpm ]; then + git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm +else + echo "tmux plugin manager already installed" +fi + +echo "Setup completed successfully!"