瀏覽代碼

Add up/down arrow history searching to bash

Weiyi Lou 9 年之前
父節點
當前提交
45db1dbbae
共有 5 個文件被更改,包括 12 次插入3 次删除
  1. 3 0
      shell/bash/history.bash
  2. 4 0
      shell/bash/keybindings.bash
  3. 3 0
      shell/env
  4. 1 1
      shell/zsh/history.zsh
  5. 1 2
      shell/zsh/key-bindings.zsh

+ 3 - 0
shell/bash/history.bash

@@ -0,0 +1,3 @@
+HISTSIZE=10000
+# Do not store duplicate commands and commands starting with space.
+HISTCONTROL=ignoreboth

+ 4 - 0
shell/bash/keybindings.bash

@@ -10,3 +10,7 @@ bind '\C-w:backward-kill-word'
 
 # Set Ctrl-l to clear the screen.
 bind '\C-l:clear-screen'
+
+# Search history for the current input string.
+bind '"\e[A":history-search-backward'
+bind '"\e[B":history-search-forward'

+ 3 - 0
shell/env

@@ -35,3 +35,6 @@ export MANPATH=$MANPATH:$HOME/dotfiles/shell/man
 # setting variables that should be available to other programs e.g. `PATH`,
 # `EDITOR`, `PAGER`, and generally not the place to put commands that produce
 # output or assume attachment to a tty/terminal.
+#
+# https://shreevatsa.wordpress.com/2008/03/30/zshbash-startup-files-loading-order-bashrc-zshrc-etc/
+# http://blog.flowblok.id.au/2013-02/shell-startup-scripts.html

+ 1 - 1
shell/zsh/history.zsh

@@ -1,7 +1,7 @@
 ## Command history configuration
 HISTSIZE=10000 # Max events stored in the internal history list.
 SAVEHIST=10000 # Max events to save to file when interactive shell exits.
-[[ -z "$HISTFILE" ]] && HISTFILE=$HOME/.zshhistory
+HISTFILE=$HOME/.zsh_history
 
 # Show history
 #alias history='fc -l 1' # No timestamps

+ 1 - 2
shell/zsh/key-bindings.zsh

@@ -39,11 +39,10 @@ bindkey '^Z' fancy-ctrl-z
 
 # Key bindings for history search
 #
-# Start typing + [Up-Arrow] - fuzzy find history forward
+# [Up & Down Arrow] - search through history for the current input string.
 if [[ "${terminfo[kcuu1]}" != "" ]]; then
   bindkey "${terminfo[kcuu1]}" up-line-or-search
 fi
-# Start typing + [Down-Arrow] - fuzzy find history backward
 if [[ "${terminfo[kcud1]}" != "" ]]; then
   bindkey "${terminfo[kcud1]}" down-line-or-search
 fi