LoginSignup
0
0

More than 1 year has passed since last update.

PowerShellの起動時にエイリアスを設定してみた

Last updated at Posted at 2022-08-12

はじめに

PowerShellでvimコマンドを使う為にエイリアスを設定しましたが、PowerShellを閉じると設定が消えてしまいます。
PowerShellを起動する度にコマンドを打つのは面倒なので、PowerShellの起動時にエイリアスが実行される様にしました。

Step1. 実行ポリシーの変更

管理者権限でPowerhsellで以下のコマンドを実行する。

get-executionpolicy

上記でRemoteSignedが返ってくればOK。
デフォルトはRestrictedなので多くの人はRestrictedが返ってくると思います。

Restrictedが返ってきた人は、下記を実行します。

Set-ExecutionPolicy RemoteSigned -Force

もう一回get-executionpolicyを実行し、下記の様にRemoteSignedが帰ってくることを確認します。

image.png

Step2. プロファイルの作成。

ユーザー権限でPowerhsellを開きなおし、下記のコマンドを実行する。

New-Item –type file –force $profile
notepad $profile

notepad $profileでメモ帳が起動する。

Step3. エイリアスの定義

今回は。Vimコマンドを使える様にしたかったので、
以下の様にVimをインストールしたディレクトリを指定し、エイリアスの定義をしました。

set-alias vi 'C:\Program Files (x86)\Vim\vim90\vim.exe'
set-alias vim 'C:\Program Files (x86)\Vim\vim90\vim.exe'

Step4. 結果確認

vimコマンドを使用できる様になりました。

image.png

image.png

用語解説

ExecutionPolicy・・・PowerShellの実行ポリシー
以下の公式ドキュメントが参考になります。
https://docs.microsoft.com/ja-jp/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.2

New-Item・・・ファイルやフォルダを作成するためのコマンド
参考記事
https://atmarkit.itmedia.co.jp/ait/articles/1606/23/news017.html

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