X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=zsh%2Frc;h=7f5b1b0cc0eb52b3ed41ea7eb068ce61920bcbf2;hb=fc2020eebed7ddd989ab53e6b9a709da2f39cbf9;hp=48f12fc4b0b0b70fc7866d03d6c1f4661889d0ed;hpb=b1fdce6a314b77279469fb660668143bef080577;p=config%2Fdotfiles.git diff --git a/zsh/rc b/zsh/rc index 48f12fc..7f5b1b0 100644 --- a/zsh/rc +++ b/zsh/rc @@ -1,6 +1,6 @@ # Zsh configuration file. -# Copyright (C) 2011-2012 Simon Ruderich +# Copyright (C) 2011-2013 Simon Ruderich # # This file is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -297,10 +297,10 @@ if [[ $ZSH_VERSION == (4.3.<9->*|4.<4->*|<5->*) || local -a stashes # Thanks to Valodim in #zsh on Freenode (2013-07-01 14:14 CEST) # for the solution to "grep" the output with (M) and :#(...). - stashes=${#${(M)${(f)"$(git stash list 2>/dev/null)"}:#(*WIP*)}} + stashes=( ${(M)${(f)"$(git stash list 2>/dev/null)"}:#(*WIP*)} ) - if [[ $stashes -gt 0 ]]; then - hook_com[misc]+=" ${yellow}${stashes}s${default}" + if [[ ${#stashes} -gt 0 ]]; then + hook_com[misc]+=" ${yellow}${#stashes}s${default}" fi fi } @@ -914,6 +914,63 @@ periodic() { } +# RESTART SETTINGS + +zmodload -F zsh/stat b:zstat + +# Remember startup time. Used to perform automatic restarts when ~/.zshrc is +# modified. +zshrc_startup_time=$EPOCHSECONDS + +# Automatically restart Zsh if ~/.zshrc was modified. +zshrc_restart_precmd() { + local stat + if ! zstat -A stat +mtime ~/.zshrc; then + return + fi + + # ~/.zshrc wasn't modified, nothing to do. + if [[ $stat -le $zshrc_startup_time ]]; then + return + fi + + local startup + strftime -s startup '%Y-%m-%d %H:%M:%S' "$zshrc_startup_time" + + echo -n "${fg[magenta]}" + echo -n "~/.zshrc modified since startup ($startup) ... " + echo -n "${fg[default]}" + + if [[ -n $zshrc_disable_restart ]]; then + echo 'automatic restart disabled.' + return + fi + + # Don't exec if we have background processes because execing will let us + # lose control over them. + if [[ ${#${(k)jobstates}} -ne 0 ]]; then + echo 'active background jobs!' + return + fi + + # Try to start a new interactive shell. If it fails, something is wrong. + # Don't kill our current session by execing it. + zsh -i -c 'exit 42' + if [[ $? -ne 42 ]]; then + echo -n "${fg_bold[red]}" + echo 'failed to start new zsh!' + echo -n "${fg_bold[default]}" + return + fi + + echo 'restarting zsh.' + echo + + exec zsh +} +precmd_functions+=(zshrc_restart_precmd) + + source_debug '. ~/.zsh/rc (done)' # vim: ft=zsh