日記帳

日記です。

Windows の cygwin 環境でコマンド使ってファイルを開く

Mac OS XGNOMEKDE にできて Windows でできない理由はないですよねぇ…
まぁ Windowsコマンドラインを使う場合は cygwin 環境を使っているのでとりあえず cygwin で調べてみると cygstart コマンドというのがありました.

% cygstart test.txt

上のようにするとメモ帳で test.txt が開きました.

cygstart は別に長すぎるということもないのですが環境毎に名前がかわるとややこしいのでこれもエイリアスを設定してしまいました.

alias open="cygstart"

ヘルプを見ると(cygstart --help) 使えるオプションが見れます.これを見ると単純に SHELL32.DLL の ShellExecute() 関数を使って開いていそうな雰囲気ですね…

以下 cygstart --help の一部を引用です.

Action options
  -a, --action=STRING        Use specified action instead of default
  -o, --open                 Short for: --action open
  -x, --explore              Short for: --action explore
  -e, --edit                 Short for: --action edit
  -f, --find                 Short for: --action find
  -p, --print                Short for: --action print

Directory options
  -d, --directory=STRING     Set working directory

Show options
  --hide                     Hides the window and activates another window
  --maximize                 Maximizes the specified window
  --minimize                 Minimizes the specified window and activates the
                             next top-level window in the z-order
  --restore                  Activates and displays the window. If the window
                             is minimized or maximized, Windows restores it to
                             its original size and position. An application
                             should specify this flag when restoring a
                             minimized window
  --show                     Activates the window and displays it in its
                             current size and position
  --showmaximized            Activates the window and displays it as a
                             maximized window
  --showminimized            Activates the window and displays it as a
                             minimized window
  --showminnoactive          Displays the window as a minimized window. The
                             active window remains active
  --showna                   Displays the window in its current state. The
                             active window remains active
  --shownoactivate           Displays a window in its most recent size and
                             position. The active window remains active
  --shownormal               Activates and displays a window. If the window is
                             minimized or maximized, Windows restores it to
                             its original size and position. An application
                             should specify this flag when displaying the
                             window for the first time