Skip to content

Commit

Permalink
Clarify license. Improve history support. {enable,read,disable}_history
Browse files Browse the repository at this point in the history
  • Loading branch information
vaeth committed Jan 19, 2019
1 parent 958d3c0 commit a9e1b15
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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_`)`
Expand Down
34 changes: 32 additions & 2 deletions zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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##[-\&\|\(\)\{\}\;]*}})
Expand Down

0 comments on commit a9e1b15

Please sign in to comment.