my xfce4 dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
9.1 KiB

3 years ago
  1. # zsh-history-substring-search
  2. This is a clean-room implementation of the [Fish shell][1]'s history search
  3. feature, where you can type in any part of any command from history and then
  4. press chosen keys, such as the UP and DOWN arrows, to cycle through matches.
  5. [1]: http://fishshell.com
  6. [2]: http://www.zsh.org/mla/users/2009/msg00818.html
  7. [3]: http://sourceforge.net/projects/fizsh/
  8. [4]: https://github.com/robbyrussell/oh-my-zsh/pull/215
  9. [5]: https://github.com/zsh-users/zsh-history-substring-search
  10. [6]: https://github.com/zsh-users/zsh-syntax-highlighting
  11. Requirements
  12. ------------------------------------------------------------------------------
  13. * [ZSH](http://zsh.sourceforge.net) 4.3 or newer
  14. Install
  15. ------------------------------------------------------------------------------
  16. Using the [Homebrew]( https://brew.sh ) package manager:
  17. brew install zsh-history-substring-search
  18. echo 'source /usr/local/share/zsh-history-substring-search/zsh-history-substring-search.zsh' >> ~/.zshrc
  19. Using [Oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh):
  20. 1. Clone this repository in oh-my-zsh's plugins directory:
  21. git clone https://github.com/zsh-users/zsh-history-substring-search ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search
  22. 2. Activate the plugin in `~/.zshrc`:
  23. plugins=( [plugins...] history-substring-search)
  24. 3. Source `~/.zshrc` to take changes into account:
  25. source ~/.zshrc
  26. Usage
  27. ------------------------------------------------------------------------------
  28. 1. Load this script into your interactive ZSH session:
  29. % source zsh-history-substring-search.zsh
  30. If you want to use [zsh-syntax-highlighting][6] along with this script,
  31. then make sure that you load it *before* you load this script:
  32. % source zsh-syntax-highlighting.zsh
  33. % source zsh-history-substring-search.zsh
  34. 2. Bind keyboard shortcuts to this script's functions.
  35. Users typically bind their UP and DOWN arrow keys to this script, thus:
  36. * Run `cat -v` in your favorite terminal emulator to observe key codes.
  37.      (**NOTE:** In some cases, `cat -v` shows the wrong key codes. If the
  38. key codes shown by `cat -v` don't work for you, press `<C-v><UP>` and
  39. `<C-v><DOWN>` at your ZSH command line prompt for correct key codes.)
  40. * Press the UP arrow key and observe what is printed in your terminal.
  41. * Press the DOWN arrow key and observe what is printed in your terminal.
  42. * Press the Control and C keys simultaneously to terminate the `cat -v`.
  43. * Use your observations from the previous steps to create key bindings.
  44. For example, if you observed `^[[A` for UP and `^[[B` for DOWN, then:
  45. bindkey '^[[A' history-substring-search-up
  46. bindkey '^[[B' history-substring-search-down
  47. However, if the observed values don't work, you can try using terminfo:
  48. bindkey "$terminfo[kcuu1]" history-substring-search-up
  49. bindkey "$terminfo[kcud1]" history-substring-search-down
  50. You might also want to bind the Control-P/N keys for use in EMACS mode:
  51. bindkey -M emacs '^P' history-substring-search-up
  52. bindkey -M emacs '^N' history-substring-search-down
  53. You might also want to bind the `k` and `j` keys for use in VI mode:
  54. bindkey -M vicmd 'k' history-substring-search-up
  55. bindkey -M vicmd 'j' history-substring-search-down
  56. 3. Type any part of any previous command and then:
  57. * Press the `history-substring-search-up` key, which was configured in
  58. step 2 above, to select the nearest command that (1) contains your query
  59. and (2) is also older than the current command in your command history.
  60. * Press the `history-substring-search-down` key, which was configured in
  61. step 2 above, to select the nearest command that (1) contains your query
  62. and (2) is also newer than the current command in your command history.
  63. * Press `^U` the Control and U keys simultaneously to abort the search.
  64. 4. If a matching command spans more than one line of text, press the LEFT
  65. arrow key to move the cursor away from the end of the command, and then:
  66. * Press the `history-substring-search-up` key, which was configured in
  67. step 2 above, to move the cursor to the line above the cursored line.
  68. When the cursor reaches the first line of the command, pressing the
  69. `history-substring-search-up` key again will cause this script to
  70. perform another search.
  71. * Press the `history-substring-search-down` key, which was configured in
  72. step 2 above, to move the cursor to the line below the cursored line.
  73. When the cursor reaches the last line of the command, pressing the
  74. `history-substring-search-down` key, which was configured in step 2
  75. above, again will cause this script to perform another search.
  76. Configuration
  77. ------------------------------------------------------------------------------
  78. This script defines the following global variables. You may override their
  79. default values only after having loaded this script into your ZSH session.
  80. * `HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND` is a global variable that defines
  81. how the query should be highlighted inside a matching command. Its default
  82. value causes this script to highlight using bold, white text on a magenta
  83. background. See the "Character Highlighting" section in the zshzle(1) man
  84. page to learn about the kinds of values you may assign to this variable.
  85. * `HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND` is a global variable that
  86. defines how the query should be highlighted when no commands in the
  87. history match it. Its default value causes this script to highlight using
  88. bold, white text on a red background. See the "Character Highlighting"
  89. section in the zshzle(1) man page to learn about the kinds of values you
  90. may assign to this variable.
  91. * `HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS` is a global variable that defines
  92. how the command history will be searched for your query. Its default value
  93. causes this script to perform a case-insensitive search. See the "Globbing
  94. Flags" section in the zshexpn(1) man page to learn about the kinds of
  95. values you may assign to this variable.
  96. * `HISTORY_SUBSTRING_SEARCH_FUZZY` is a global variable that defines
  97. how the command history will be searched for your query. If set to a non-empty
  98. value, causes this script to perform a fuzzy search by words, matching in
  99. given order e.g. `ab c` will match `*ab*c*`
  100. * `HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE` is a global variable that defines
  101. whether all search results returned are _unique_. If set to a non-empty
  102. value, then only unique search results are presented. This behaviour is off
  103. by default. An alternative way to ensure that search results are unique is
  104. to use `setopt HIST_IGNORE_ALL_DUPS`. If this configuration variable is off
  105. and `setopt HIST_IGNORE_ALL_DUPS` is unset, then `setopt HIST_FIND_NO_DUPS`
  106. is still respected and it makes this script skip duplicate _adjacent_ search
  107. results as you cycle through them, but this does not guarantee that search
  108. results are unique: if your search results were "Dog", "Dog", "HotDog",
  109. "Dog", then cycling them gives "Dog", "HotDog", "Dog". Notice that the "Dog"
  110. search result appeared twice as you cycled through them. If you wish to
  111. receive globally unique search results only once, then use this
  112. configuration variable, or use `setopt HIST_IGNORE_ALL_DUPS`.
  113. History
  114. ------------------------------------------------------------------------------
  115. * September 2009: [Peter Stephenson][2] originally wrote this script and it
  116. published to the zsh-users mailing list.
  117. * January 2011: Guido van Steen (@guidovansteen) revised this script and
  118. released it under the 3-clause BSD license as part of [fizsh][3], the
  119. Friendly Interactive ZSHell.
  120. * January 2011: Suraj N. Kurapati (@sunaku) extracted this script from
  121. [fizsh][3] 1.0.1, refactored it heavily, and finally repackaged it as an
  122. [oh-my-zsh plugin][4] and as an independently loadable [ZSH script][5].
  123. * July 2011: Guido van Steen, Suraj N. Kurapati, and Sorin Ionescu
  124. (@sorin-ionescu) [further developed it][4] with Vincent Guerci (@vguerci).
  125. * March 2016: Geza Lore (@gezalore) greatly refactored it in pull request #55.
  126. ------------------------------------------------------------------------------
  127. Oh My Zsh Distribution Notes
  128. ------------------------------------------------------------------------------
  129. What you are looking at now is Oh My Zsh's repackaging of zsh-history-substring-search
  130. as an OMZ module inside the Oh My Zsh distribution.
  131. The upstream repo, zsh-users/zsh-history-substring-search, can be found on GitHub at
  132. https://github.com/zsh-users/zsh-history-substring-search.
  133. This downstream copy was last updated from the following upstream commit:
  134. SHA: 0f80b8eb3368b46e5e573c1d91ae69eb095db3fb
  135. Commit date: 2019-05-12 17:35:54 -0700
  136. Everything above this section is a copy of the original upstream's README, so things
  137. may differ slightly when you're using this inside OMZ. In particular, you do not
  138. need to set up key bindings for the up and down arrows yourself in `~/.zshrc`; the OMZ
  139. plugin does that for you. You may still want to set up additional emacs- or vi-specific
  140. bindings as mentioned above.