LoginSignup
9
8

More than 5 years have passed since last update.

windows の mingw 環境から chocolatey を `sudo cinst vlc` のように使いたい人のための `sudo` の作り方

Posted at

背景

「やむを得ず windows を使っている」ような人々には cmdpowershell は何かと不便なので cygwin または mingw を入れて使っている事が多い(と思います)。

しかし、「管理者権限で実行」を使いたい場合にわざわざマウスぽちぽちの世界や win + R などから実行したくはありません(と思っている事でしょう)。例えば windows の一般アプリのパッケージ管理として受け入れられた chocolately も通常一般に紹介される使用方法としては管理者権限で cinst しましょうという事になっていますし、sudo で済ませたいわけです。

方法

cygwin の .zshrc なり mingw なりの .bashrc なりに簡単な function で作る:

function sudo()
{
  command=$1
  shift
  powershell -Command Start-Process -Verb runas ${command} { $@ }
}

使い方

source ~/.bashrc なり mintty を再起動するなりして alias が有効になった状態で:

sudo choco install vlc

とか、

sudo cinst ack

とか。

もちろん、sudo cmd として管理者権限の cmd を起動するだけといった事もできるようになる。楽で良い。

References

9
8
5

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
9
8