0
0

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 1 year has passed since last update.

PowerShellにはhistoryが足りないしlessもない

Posted at

答え

cat  (Get-PSReadlineOption).HistorySavePath

これでヒストリがみれる。

背景

PowerShellのhistoryコマンドはセッション中のコマンド履歴しか表示してくれない。historyコマンドは、先週やったことを思い出したいから使うのであって、用途とあってない。

ヒストリ自体は (Get-PSReadlineOption).HistorySavePathファイルに保存されている。それをみればいいのだが、

PS C:\Users\yugoy> less  (Get-PSReadlineOption).HistorySavePath
less: The term 'less' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

less コマンドはないとのこと。なるほどじゃぁmoreかなと思ったけど先頭行を見せるコマンドであって後ろから見る用途ではない。ということでcatで表示するのが期待に叶う。本当はlessでスクロールしたり検索したりしたいけど、PowerShellにはそれに相当するコマンドがない。そもそも標準のエディタがない。

別解としては

code  (Get-PSReadlineOption).HistorySavePath

でVSCodeでヒストリを眺めることができる。こうなるとPowerShellでファイルを扱ってるという感じじゃない。あれこれ探したけど、どうもvim,nano,lessに相当するものがPowerShellにはない。いやvimもnanoもlessもLinux上では単品の実行ファイルなのだから、Windowsにもコマンドとしてインストールすればいい。がそこまでやらないしVSCodeでいい。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?