GithubHelp home page GithubHelp logo

Comments (1)

emrakyz avatar emrakyz commented on August 24, 2024

Here are the settings I use for the history:

setopt append_history # Allows new commands to be appended to the history file, instead of overwriting it.

setopt inc_append_history # each command is added to the history file immediately after it's executed, not just when the session ends.

setopt share_history # synchronizes the command history between multiple zsh sessions. Commands entered in one session will be available in others.

setopt hist_ignore_dups # Prevents consecutive duplicates from being saved in the command history.

setopt hist_ignore_all_dups # Ignores all duplicate entries in the history, not just consecutive ones.

setopt hist_expire_dups_first #  When the history file reaches its size limit, remove older duplicate entries before removing unique commands.

setopt hist_find_no_dups  # When searching through history, prevent showing duplicate entries.

setopt hist_save_no_dups # When saving the history, omit duplicate entries, so only unique commands are saved.

setopt hist_reduce_blanks # Removes extra blanks from each command line being added to the history.

setopt hist_verify # After a history expansion (like using ! commands), this option prompts for verification before executing the command.

Additionally; here below is the little function I wrote. You can search your history using fzf by hitting CTRL + R. For example if you write "pacman" and hit CTRL + R, you will see all pacman commands you entered before in fzf menu.

fzf-history-widget-with-date() {
  initial_query="$LBUFFER"
  setopt noglobsubst noposixbuiltins pipefail 2>/dev/null
  entry=$(fc -lir 1 |
          sed -E 's/^[[:space:]]+[0-9]+\*?[[:space:]]+//' |
          awk '{cmd=$0; $1=$2=$3=""; sub(/^[ \t]+/, ""); if (!seen[$0]++) print cmd}' |
          fzf --query="$initial_query" +s)
  [ -n "$entry" ] && LBUFFER=${entry#* * * }
  zle redisplay
}

zle -N fzf-history-widget-with-date
bindkey '^R' fzf-history-widget-with-date

There are also nice plugins you can use called fzf-tab (tab completion using fzf instead of default), fzf-autosuggestions (fish-like suggestions based on history) and zsh-completions (complete commands in a very detailed way for example pressing tab after "grep -" will give you all possible options with explanations).

from voidrice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.