mac 前回実行したコマンドの最後のパラメーター以外を取得する

  • 作成日 2023.01.28
  • mac
mac 前回実行したコマンドの最後のパラメーター以外を取得する

macで、前回実行したコマンドの最後のパラメーター以外を取得する手順を記述してます。「 !:- 」で取得できます。覚えておくと作業時間短縮になります。

環境

  • OS macOS Monterey
  • SHELL /bin/zsh

最後のパラメーター以外を取得

最後のパラメーター以外を取得するには、「 !:- 」を使用します。

例えば、以下のコマンドを実行した場合、

wget -d -c https://github.com/ogham/exa/releases/download/v0.10.1/exa-macos-x86_64-v0.10.1.zip

「wget -c」までを「 !:- 」で利用でき「URL」を変えるだけで前回のコマンドを実行できます。

!:- https://github.com/ogham/exa/releases/download/v0.10.0/exa-macos-x86_64-v0.10.0.zip

履歴には、ちゃんとしたコマンドとして表示されます。

history

<出力結果>
  271  wget -d -c https://github.com/ogham/exa/releases/download/v0.10.1/exa-macos-x86_64-v0.10.1.zip
  272  wget -d -c https://github.com/ogham/exa/releases/download/v0.10.0/exa-macos-x86_64-v0.10.0.zip
  273  hisotry