在命令中使用先前列印的文本

在命令中使用先前列印的文本

通常,我會使用終端命令來輸出一些接下來要執行的建議命令,或多行文字輸出中的檔案路徑。

我希望能夠重新使用檔案路徑或命令。

例如

$ nativefier --name "Asana Personal" "https://app.asana.com"
Packaging app for platform darwin x64 using electron v1.6.6
App built to /Users/Vaughan/Asana Personal-darwin-x64


$ cd /Users<press-tab>/Vaughan/Asana Personal-darwin-x64


$ brew info postgres
...
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
  https://github.com/Homebrew/legacy-homebrew/issues/2510

To migrate existing data from a previous major version (pre-9.0) of PostgreSQL, see:
  https://www.postgresql.org/docs/9.6/static/upgrading.html

To migrate existing data from a previous minor version (9.0-9.5) of PostgreSQL, see:
  https://www.postgresql.org/docs/9.6/static/pgupgrade.html

  You will need your previous PostgreSQL installation from brew to perform `pg_upgrade`.
  Do not run `brew cleanup postgresql` until you have performed the migration.

To have launchd start postgresql now and restart at login:
  brew services start postgresql
Or, if you don't want/need a background service you can just run:
  pg_ctl -D /usr/local/var/postgres start


$ pg ctl<press-tab>-D /usr/local/var/postgres start

答案1

這基本上意味著記錄整個終端會話以捕獲您想要的資訊。

為此,您可以使用該程式script(例如,放入script /tmp/myuseronlyreadablefile您的,或增強您的提示,以便一次又一次地在同一日誌檔案上的這一行輸入上.zshrc使用,之後立即解析它),然後您將解析生成的script您設定的小部件的日誌檔案(過濾所有路徑的輸出) zsh 自動補全

我不確定使用“腳本”可能有哪些缺點,以及與舊的“腳本”相比,這對您意味著多少努力用滑鼠標記任何文本,然後只需單擊滑鼠滾輪即可立即插入' 功能。

答案2

終端多工器例如tmuxscreen支援從會話中複製和貼上,但如果您想在沒有終端多路復用器的情況下或自動執行此操作,則可以使用tee將輸出發送到臨時文件,並使用cut,sed和/或grep建置(然後運行)說命令。

但是,由於您似乎使用的是 OSX,因此您只需突出顯示文本,然後按 ⌘C 進行複製,按 ⌘V 進行貼上。 (除非你ssh在)

相關內容