diff --git a/README.md b/README.md index 6aba94f..4731266 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,7 @@ (C) Martin Väth (martin at mvath.de) -You can copy the `zshrc` file completely or partly, as you need. -Comments are welcome. +This project is under the Creative Commons CC-BY-4.0 license. zshrc is a __zsh__ initialization file (e.g. to be used as `/etc/zshrc` or `~/.zshrc`) which activates a lot of zsh interactive features. @@ -65,6 +64,12 @@ you can define a function `after_zshrc`: If this function is defined, it is called at the very end of `zshrc` (passing the arguments of the shell), so you can undo/extend any change done in `zshrc` if you wish to. +For example, by default zshrc disables a history file. +If you call enable_history in the function after_zshrc, +the history will be saved to $HOME/history and restored from there: +after_zshrc() enable_history +(use read_history to pick up changes saved in another terminal) + Also some other paths are configurable if you have set - `DEFAULTS=(`_/paths/to/dirs-with-local-configuration-files_`)` diff --git a/zshrc b/zshrc index 0b647cf..12b23de 100644 --- a/zshrc +++ b/zshrc @@ -92,6 +92,9 @@ setopt path_dirs auto_name_dirs bash_auto_list prompt_subst no_beep setopt no_list_ambiguous list_packed setopt hist_ignore_all_dups hist_reduce_blanks hist_verify no_hist_expand setopt extended_glob hist_subst_pattern +#setopt hist_ignore_space # distinguish 1/2 spaces in zshaddhistory() instead +setopt hist_lex_words hist_no_functions hist_save_no_dups +setopt no_append_history inc_append_history setopt no_glob_dots no_nomatch no_null_glob numeric_glob_sort no_sh_glob setopt mail_warning interactive_comments no_clobber setopt no_bg_nice no_check_jobs no_hup long_list_jobs monitor notify @@ -117,11 +120,37 @@ ttyctl -f # History -SAVEHIST=${HISTSIZE:-1000} +DIRSTACKSIZE=100 +HISTSIZE=9999999 +SAVEHIST=$HISTSIZE unset HISTFILE -DIRSTACKSIZE=100 +# Call enable_history in after_zsh if you want a histfile. +# This will also pick up changes saved in another terminal. +enable_history() { + emulate -L zsh + typeset -g HISTFILE=$HOME/history + fc -RI +} + +# Pick up changes saved in another terminal without necessarily enabling saving +read_history() { + emulate -L zsh + fc -RI ${HISTFILE:-$HOME/history} +} +disable_history() { + unset HISTFILE +} + +zshaddhistory() { + case $1 in + ' '*|' ') + return 1;; # Save neither in history nor $HISTFILE + ' '*|'# '*|knock*' '[0123456789]*) + return 2;; # Exclude from $HISTFILE + esac +} # The code in this file needs some modules @@ -154,6 +183,7 @@ autoload -Uz colors zargs zcalc zed zmv # Title are the first 3 words starting with sane chars (paths cutted) # We also truncate to at most 30 characters and add dots if args follow set_title() { + emulate -L zsh local a b a=(${=${(@)${=1}:t}}) a=(${=${a##[-\&\|\(\)\{\}\;]*}})