diff --git a/.bash_profile b/.bash_profile index b0cff8b..bab3433 100644 --- a/.bash_profile +++ b/.bash_profile @@ -93,10 +93,6 @@ if [ -f ~/.aws/current_profile ]; then fi export CLOUDSDK_CONFIG="$XDG_CONFIG_HOME/gcloud" -if [ -f "$CLOUDSDK_CONFIG/active_config" ]; then - GC_ACTIVE_CONFIG="$(cat "$CLOUDSDK_CONFIG/active_config")" - export GC_ACTIVE_CONFIG -fi export COLIMA_HOME="$XDG_CONFIG_HOME/colima" diff --git a/.functions b/.functions index 9002732..2ef6272 100644 --- a/.functions +++ b/.functions @@ -9,8 +9,8 @@ prompt_aws() { } prompt_gc() { - if [[ -n "${GC_ACTIVE_CONFIG}" && "${GC_ACTIVE_CONFIG}" != "none" ]]; then - GC_PROMPT=" " + if [[ -n "${CLOUDSDK_CORE_PROJECT}" ]]; then + GC_PROMPT=" " else GC_PROMPT="" fi @@ -201,65 +201,63 @@ if [ ! "$(command -v gps)" ]; then cat << 'EOF' Usage: gps [OPTIONS] [QUERY] -Google Cloud Profile Switcher - Switch between gcloud configurations interactively +Google Cloud Project Switcher - Switch between GCP projects interactively. +Sets CLOUDSDK_CORE_PROJECT for the current shell (per-shell, not persisted). OPTIONS: --help, -h Show this help message - --clear Clear the current gcloud configuration (set to "none") - --list List all configurations (current one marked with *) + --clear Clear the current GCP project (unset CLOUDSDK_CORE_PROJECT) + --list List all projects (current one marked with *) ARGUMENTS: - QUERY Filter configurations by query string (optional) + QUERY Filter projects by query string (optional) EXAMPLES: - gps # Interactive configuration selection with fzf - gps prod # Filter configurations containing "prod" - gps --list # List all available configurations - gps --clear # Clear current configuration + gps # Interactive project selection with fzf + gps prod # Filter projects containing "prod" + gps --list # List all available projects + gps --clear # Clear current project EOF return fi - DUMMY_CONFIG_NAME="none" - if [ ! "$(gcloud config configurations list --format='value(name)' | grep "^${DUMMY_CONFIG_NAME}$")" ]; then - gcloud config configurations create "$DUMMY_CONFIG_NAME" - fi - if [ "$query" = "--clear" ]; then - export GC_ACTIVE_CONFIG="$DUMMY_CONFIG_NAME" - gcloud config configurations activate "$DUMMY_CONFIG_NAME" - echo "Google Cloud configuration cleared." + unset CLOUDSDK_CORE_PROJECT + echo "GCP project cleared." return fi + if ! projects="$(gcloud projects list --format='value(projectId)' --sort-by=projectId)"; then + echo "gps: failed to list GCP projects" >&2 + return 1 + fi + if [ "$query" = "--list" ]; then - # List all configurations with current one marked with * - current_config="${GC_ACTIVE_CONFIG:-$(cat "${CLOUDSDK_CONFIG:-${XDG_CONFIG_HOME:-$HOME/.config}/gcloud}/active_config" 2>/dev/null || echo "")}" - gcloud config configurations list --format='value(name)' | while read -r config; do - if [ "$config" = "$current_config" ]; then - echo "* $config" + current_project="${CLOUDSDK_CORE_PROJECT:-}" + echo "$projects" | while read -r project; do + if [ "$project" = "$current_project" ]; then + echo "* $project" else - echo " $config" + echo " $project" fi done return fi - config="" + project="" if [ -n "$query" ]; then - config="$(gcloud config configurations list --format='value(name)' | grep -v "^${DUMMY_CONFIG_NAME}$" | fzf --filter "$query" | head -n 1)" + project="$(echo "$projects" | fzf --filter "$query" | head -n 1)" else - config="$(gcloud config configurations list --format='value(name)' | grep -v "^${DUMMY_CONFIG_NAME}$" | fzf)" + project="$(echo "$projects" | fzf)" fi - if [ -z "$config" ]; then - echo "No profiles are selected." + if [ -z "$project" ]; then + echo "No projects are selected." return fi - gcloud config configurations activate "$config" - export GC_ACTIVE_CONFIG="$(cat "${CLOUDSDK_CONFIG:-${XDG_CONFIG_HOME:-$HOME/.config}/gcloud}/active_config")" - echo "Google Cloud config set: $config" + export CLOUDSDK_CORE_PROJECT="$project" + echo "GCP project set: $project" } fi diff --git a/claude/rules/software-development.md b/claude/rules/software-development.md index d8919db..db53d89 100644 --- a/claude/rules/software-development.md +++ b/claude/rules/software-development.md @@ -8,7 +8,8 @@ 1. コメントはコードから読み取れない意図の説明のみに限定する 1. シェルコマンドは `&&` や `;` で連結せず、1コマンドずつ個別に実行する。特に `cd` は他のコマンドと絶対に連結しない(bare repository attack防止チェックに該当するため) 1. シェルコマンド内でコマンド置換(`$()`、バッククォート)を使わない。複数行テキストはシングルクォートで渡し、本文にシングルクォートが含まれる場合のみheredocにフォールバック -1. AWS CLIを実行する際は必ず `AWS_PROFILE= aws ...` の形式で環境変数をコマンドの先頭に付与する。使用するprofileは必ずユーザーに確認してから実行すること。GCPの権限切り替えは `gps` コマンドを使用する +1. AWS CLIを実行する際は必ず `AWS_PROFILE= aws ...` の形式で環境変数をコマンドの先頭に付与する。使用するprofileは必ずユーザーに確認してから実行すること +1. gcloud / bq / gsutilを実行する際は必ず `CLOUDSDK_CORE_PROJECT= ...` の形式で環境変数をコマンドの先頭に付与する。使用するprojectは必ずユーザーに確認してから実行すること。project切替は `gps` コマンドを使う 1. プロジェクトと無関係のファイルは、現在のプロジェクトroot直下の `ikuwowfiles/` 以下に置く(グローバルgitignore対象) 1. コード・ファイル内の検索は `git grep` を第一選択とする。Bashの `find` コマンドではなくGlob/Grep/Readツールを優先し、`find` は専用ツールでは実現できない場合(パーミッション・タイムスタンプ条件等)に限定する 1. ユーザー提示のドキュメント・URLは正確に読んでから実装する。コード例はそのまま適用する