0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ターミナルにGoogle Cloud SDKを追加する方法

Last updated at Posted at 2023-04-17

Windowsのターミナルに、Google Cloud SDKのPowerShellを追加する方法のメモ。コマンドプロンプト版でもショートカットの情報をきちんとエスケープして真似ることで可能。Google Cloud SDKに限らずほかでも一緒。例えばAnacondaとか。

壊れないように、下記の手順でjsonを開いたときにバックアップを取っておくとよい。

手順

  1. ターミナルを開く
  2. Ctrl+Shift+,を押して、settings.jsonをテキストエディタで開く
    • ここでVisual Studioとかが開いて、編集できない人、好きなテキストエディタで開きたい人は、後述の追加1へ。
  3. jsonの"profiles">"list"に、Google Cloud SDKを追加する。
    • 基本的に、もとからある{}を見ながら、似たような感じで真似して作る。
    • また各種設定は、スタートメニューのショートカットから情報を得る。
      • ショートカットから情報を得る方法は、後述の追加2へ。
    1. {}を1つ追加する。(カンマも適切に入れる)
    2. 新しい"guid"を得る
      • 新しいguidを取得する方法は、後述の追加3へ。
    3. {}内に要素を追加
      • "hidden": false
      • "name": "Google Cloud Tools for PowerShell"
        • 自分がわかればなんでもよい
      • "startingDirectory": "C:\\Program Files (x86)\\Google\\Cloud SDK"
        • 上記は私の環境。自分のショートカットの情報に合わせること。
      • "commandline": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -ExecutionPolicy Bypass -File \"C:\\Program Files (x86)\\Google\\Cloud SDK\\google-cloud-sdk\\platform\\PowerShell\\GoogleCloud\\BootstrapCloudToolsForPowerShell.ps1\""
        • 上記は私の環境。自分のショートカットの情報に合わせること。
        • \\\へ、"\"へ、変更(\を追加)してエスケープする。
        • 他のショートカットを真似るとき用のメモ
          • '&はエスケープ不要
  4. 保存して閉じる
  5. ターミナルを再起動して、選択して起動確認。

追加1:ターミナルの設定ファイルをテキストエディタで開く方法

  1. Windowsの左下の検索欄で、「拡張子」で検索
  2. 設定>「ファイルの種類ごとに規定のアプリ」を選ぶ
    • 開くと、「名前」と「規定のアプリ」がずらーっと表示される。
    • 「名前」は、ピリオドで始まる英数字で、これが拡張子。
    • その拡張子の場合に開くプログラムがが右の「既定のアプリ」。
  3. スクロールして「.json」を探す
  4. 「.json」に対応するプログラムをクリックして、好きなテキストエディタに変更する

追加2:Google Cloud SDKのショートカットの情報を得る方法

  1. スタートメニューのGoogle Cloud SDK>Cloud Tools for PowerShellを右クリック
  2. その他>ファイルの場所を開く
  3. Cloud Tools for PowerShellを右クリック>プロパティ
    • リンク先が、"command"にあたる
    • 作業フォルダが、"startingDirectory"にあたる

追加3:新しいguidを取得する方法

  1. PowerShellを開く
  2. powershell -Command "[Guid]::NewGuid()"
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?