Cygwin shortcut for command history

后端 未结 6 1651
难免孤独
难免孤独 2021-02-08 16:01

How can I search the command history in cygwin?

I don\'t want to keep pressing the arrow keys to execute a command from console command history.

6条回答
  •  北荒
    北荒 (楼主)
    2021-02-08 16:17

    The history command is the way to go. I use

    h ()
    {
        history | cut -f 2- | sort -u | grep -P --color=auto -e "$*"
    }
    

    so that I can type something like h git.*MyProgram, h ^tar -c, h svn:ignore, etc to pull up a sorted list of past commands matching a regex.

    You might also want to add the following lines to ~/.inputrc:

    # Ctrl+Up/Down for searching command history
    "\e[1;5A": history-search-backward
    "\e[1;5B": history-search-forward
    

    With these in place, you can type a partial command prefix (such as gi or sql) then use Ctrl+Up to scroll back through the list of just your command history entries that match that prefix (such as git clone https://code.google.com/p/double-conversion/ and sqlite3 .svn/wc.db .tables). This can be a lot faster than searching and then cutting and pasting if you want to edit or re-execute a command that was fairly recent.

提交回复
热议问题