From 1400941de13bb00f468abe1d113dfb8893761ec6 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Tue, 7 Aug 2012 11:19:43 -0700 Subject: [PATCH] Add status messages to shell init files Mostly for profiling, but I think it's cool to have status occasionally. In the process, I also did some clean up, moving some stuff between profile, rc, and env. --- env | 8 ++++++-- profile | 28 ++-------------------------- rc | 25 ++++++++++++++++++++++++- shell-functions | 11 +++++++++++ zprofile | 2 ++ zshrc | 15 ++++----------- 6 files changed, 49 insertions(+), 40 deletions(-) diff --git a/env b/env index 0176255..a637661 100644 --- a/env +++ b/env @@ -8,8 +8,13 @@ # # Eryn Wells -export SYS=`uname -s | tr A-Z a-z` +[ -e $HOME/.shell-functions ] && source $HOME/.shell-functions +export SYS=`uname -s | tr A-Z a-z` +# Set this to a non-zero integer to see startup messages +export NOISY=0 + +print_info_noisy 1 "Initializing environment for $SYS system" PAGER="less" MANPAGER=$PAGER EDITOR="vim" @@ -33,7 +38,6 @@ PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin export PATH -# System specific environment settings case $SYS in darwin) export PATH=$HOME/Library/Python/2.7/bin:$PATH diff --git a/profile b/profile index f002eb5..cbcc10e 100644 --- a/profile +++ b/profile @@ -2,33 +2,9 @@ # vim: ft=zsh # Eryn Wells -# Gotta do some machine specific setup -arch=`uname -s` -case $arch in - Linux) - alias iptls='sudo iptables --line-numbers -nv -L' - alias ip6tls='sudo ip6tables --line-numbers -nv -L' - alias rlx="xrdb $HOME/.Xdefaults" - ;; - - Darwin) - alias indent='gnuindent' - alias acls='/bin/ls -le' - ;; -esac - -# NetHack options -# use color in the terminal -export NETHACKOPTIONS="color" - -[ -e $HOME/.profile-local ] && source $HOME/.profile-local - # Start SSH agent for password-less logins -if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ] -then +if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ]; then + print_info_noisy 1 'Starting ssh-agent' eval `ssh-agent -s` trap "kill $SSH_AGENT_PID" 0 fi - -LEDGER_FILE=$HOME/Documents/Financial/personal.ledger -export LEDGER_FILE PATH diff --git a/rc b/rc index 2b0b4e2..9e95e27 100644 --- a/rc +++ b/rc @@ -3,8 +3,9 @@ # Generic interactive shell setup # Eryn Wells -. $HOME/.shell-functions +print_info_noisy 1 'Initializing interactive shell' +print_info_sub_noisy 2 'Creating aliases' alias j='jobs' alias h='history' alias df='df -h' @@ -37,16 +38,38 @@ case $SYS in alias la="$ls -A $ls_options" alias ll="$ls -l $ls_options" binary_exists gdircolors && alias dircolors='gdircolors' + alias indent='gnuindent' + alias acls='/bin/ls -le' ;; linux) alias ls="ls --color=auto" alias la="ls -A --color=auto" alias ll="ls -l --color=auto" alias l.="ls -d --color=auto .*" + # iptables aliases + alias iptls='sudo iptables --line-numbers -nv -L' + alias ip6tls='sudo ip6tables --line-numbers -nv -L' + alias rlx="xrdb $HOME/.Xdefaults" ;; *) print_error "What system %Bis%b this, anyway?" ;; esac +# Set up dircolors +if [ -e $HOME/.dircolors/$SYS.cfg ]; then + dircolors=$HOME/.dircolors/$SYS.cfg +else + dircolors=$HOME/.dircolors/default.cfg +fi +eval `dircolors $dircolors` + +# NetHack options +# use color in the terminal +export NETHACKOPTIONS="color" + +# Default ledger file +[ -e "$HOME/Documents/Financial/personal.ledger" ] && \ + LEDGER_FILE=$HOME/Documents/Financial/personal.ledger + [ -e $HOME/.rc.local ] && source $HOME/.rc.local diff --git a/shell-functions b/shell-functions index 403cd53..962fdaa 100644 --- a/shell-functions +++ b/shell-functions @@ -9,5 +9,16 @@ function print_msg { print -P "%F{$1}==>%f $2" } function print_info { print_msg 'blue' "$@" } function print_error { print_msg 'red' "$@" } +function print_msg_sub { print -P " %F{$1}*%f $2" } +function print_info_sub { print_msg_sub 'blue' "$@" } +function print_error_sub { print_msg_sub 'error' "$@" } + +# Print if $NOISY is set +function print_info_noisy { [ ${NOISY:-0} -ge $1 ] && print_info $@[2,-1] } +function print_error_noisy { [ ${NOISY:-0} -ge $1 ] && print_error $@[2,-1] } + +function print_info_sub_noisy { [ ${NOISY:-0} -ge $1 ] && print_info_sub $@[2,-1] } +function print_error_sub_noisy { [ ${NOISY:-0} -ge $1 ] && print_error_sub $@[2,-1] } + # Return 1 if the binary exists (according to hash); 0 otherwise. function binary_exists { return $(hash $1 1>/dev/null 2>&1) } diff --git a/zprofile b/zprofile index cb93fb4..bd45fbc 100644 --- a/zprofile +++ b/zprofile @@ -5,6 +5,8 @@ # # Eryn Wells +print_info_noisy 1 'Initializing login shell' + [ -e $HOME/.profile ] && source $HOME/.profile # Any ZSH stuff goes here. diff --git a/zshrc b/zshrc index 390cbfb..439e92e 100644 --- a/zshrc +++ b/zshrc @@ -25,6 +25,7 @@ else isroot="%(!.%{$fg_bold[red]%}%#%{$reset_color%}.%#)" fi +print_info_sub_noisy 2 'Setting prompt' PROMPT=" $hist $bgjob$isroot " @@ -72,6 +73,7 @@ precmd_git_rprompt() precmd_functions=(precmd_xterm_title precmd_separator_info precmd_git_rprompt) +print_info_sub_noisy 2 'Initializing ZSH' # Shell options setopt \ TRANSIENT_RPROMPT \ @@ -106,17 +108,6 @@ HISTSIZE=1000000 SAVEHIST=1000000 HISTFILE="$HOME/.zhistory" -#[ -n "$DISPLAY" ] && alias -s pdf='evince' -#[ -n "$DISPLAY" ] && alias -s dvi='evince' - -# Set up dircolors -if [ -e $HOME/.dircolors/$SYS.cfg ]; then - dircolors=$HOME/.dircolors/$SYS.cfg -else - dircolors=$HOME/.dircolors/default.cfg -fi -eval `dircolors $dircolors` - # emacs command line editing bindkey -v @@ -125,6 +116,8 @@ bindkey -v # Completion ### +print_info_sub_noisy 2 'Initializing completion' + # load completion system autoload -U compinit compinit