13
13

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 5 years have passed since last update.

環境変数PATHを共通化する。

Posted at

Windowsで環境変数PATHを設定するのってすごく面倒なので、
VimとPowerShellとBatファイル、それぞれ共通のファイルを
読み込んでPATHを設定しようと思いました。

で、以下のコードを.vimrcMicrosoft.PowerShell_profile.ps1に書けばOK。
共通のファイルは1行ごとにPATHが書かれています。

Bat ファイル

@echo off
setlocal enabledelayedexpansion
set PATH=
FOR /F %%i in (%HOME%\example.pathrc) do @set PATH=%%i;!PATH!
echo %PATH%
endlocal

Vim script

if filereadable(expand('~/example.pathrc'))
  let $path = join(readfile(expand('~/example.pathrc')),';')
endif
echo $path

PowerShell script

if(test-path "$env:HOME\example.pathrc"){
  $env:path = [string]::join(';',(get-content "$env:HOME\example.pathrc"))
}
write-host $env:path
13
13
2

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
13
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?