New message/log functions
This commit is contained in:
parent
0c08add311
commit
8ebe1788bf
6 changed files with 60 additions and 38 deletions
7
env
7
env
|
@ -14,7 +14,8 @@ 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'
|
||||
print_heading -l 1 'Initializing environment'
|
||||
|
||||
PAGER="less"
|
||||
MANPAGER=$PAGER
|
||||
EDITOR="vim"
|
||||
|
@ -38,7 +39,7 @@ PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
|
|||
|
||||
export PATH
|
||||
|
||||
print_info_sub_noisy 2 "Setting up $SYS environment"
|
||||
print_info -l 2 "Setting up $SYS environment"
|
||||
case $SYS in
|
||||
darwin)
|
||||
export PATH=$HOME/Library/Python/2.7/bin:$PATH
|
||||
|
@ -58,6 +59,6 @@ esac
|
|||
|
||||
# Local environment settings
|
||||
if [ -e $HOME/.env.local ]; then
|
||||
print_info_noisy 2 "Sourcing local environment setup"
|
||||
print_info -l 2 "Sourcing local environment setup"
|
||||
source $HOME/.env.local
|
||||
fi
|
||||
|
|
2
profile
2
profile
|
@ -4,7 +4,7 @@
|
|||
|
||||
# Start SSH agent for password-less logins
|
||||
if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ]; then
|
||||
print_info_noisy 1 'Starting ssh-agent'
|
||||
print_info -l 1 'Starting ssh-agent'
|
||||
eval `ssh-agent -s`
|
||||
trap "kill $SSH_AGENT_PID" 0
|
||||
fi
|
||||
|
|
12
rc
12
rc
|
@ -3,9 +3,9 @@
|
|||
# Generic interactive shell setup
|
||||
# Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
print_info_noisy 1 'Initializing interactive shell'
|
||||
print_heading -l 1 'Initializing interactive shell'
|
||||
|
||||
print_info_sub_noisy 2 'Creating aliases'
|
||||
print_info -l 2 'Creating aliases'
|
||||
alias j='jobs'
|
||||
alias h='history'
|
||||
alias df='df -h'
|
||||
|
@ -28,7 +28,7 @@ alias pprint="python -c 'import sys,pprint; pprint.pprint(eval(sys.stdin.read())
|
|||
alias pprint-json="python -c 'import sys,json;print json.dumps(json.load(sys.stdin), indent=2)'"
|
||||
|
||||
|
||||
print_info_sub_noisy 2 "Sourcing ${SYS}-specific settings"
|
||||
print_info -l 2 "Sourcing ${SYS}-specific settings"
|
||||
case $SYS in
|
||||
darwin)
|
||||
alias acls='command ls -le'
|
||||
|
@ -69,7 +69,7 @@ function {
|
|||
;;
|
||||
esac
|
||||
|
||||
print_info_sub_noisy 3 "Setting up ls: `which $ls`"
|
||||
print_info_sub -l 3 "Setting up ls: `which $ls`"
|
||||
alias ls="$ls $ls_options"
|
||||
alias la="$ls -A $ls_options"
|
||||
alias ll="$ls -l $ls_options"
|
||||
|
@ -81,7 +81,7 @@ function {
|
|||
else
|
||||
dircolors=$HOME/.dircolors/default.cfg
|
||||
fi
|
||||
print_info_sub_noisy 3 "Setting up dircolors: `basename $dircolors`"
|
||||
print_info_sub -l 3 "Setting up dircolors: `basename $dircolors`"
|
||||
eval `dircolors $dircolors`
|
||||
fi
|
||||
}
|
||||
|
@ -95,6 +95,6 @@ binary_exists nethack && export NETHACKOPTIONS="color"
|
|||
LEDGER_FILE=$HOME/Documents/Financial/personal.ledger
|
||||
|
||||
if [ -e $HOME/.rc.local ]; then
|
||||
print_info_noisy 2 "Sourcing local settings for interactive shells"
|
||||
print_info -l 2 'Sourcing local interactive shell setup'
|
||||
source $HOME/.rc.local
|
||||
fi
|
||||
|
|
|
@ -5,20 +5,42 @@
|
|||
|
||||
|
||||
# Print prettier, more uniform messages
|
||||
function print_msg { print -P "%F{$1}==>%f $2" }
|
||||
function print_info { print_msg 'blue' "$@" }
|
||||
function print_error { print_msg 'red' "$@" }
|
||||
function print_msg {
|
||||
# Level 0: always show
|
||||
local -i level=0 bold=0
|
||||
local prefix message
|
||||
local foreground background
|
||||
|
||||
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' "$@" }
|
||||
while getopts 'bl:f:k:p:' opt; do
|
||||
case $opt in
|
||||
b) bold=1;;
|
||||
l) level="$OPTARG";;
|
||||
f) foreground="$OPTARG";;
|
||||
k) background="$OPTARG";;
|
||||
p) prefix="$OPTARG";;
|
||||
esac
|
||||
done
|
||||
|
||||
# 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] }
|
||||
message=$@[$OPTIND,${#@}]
|
||||
|
||||
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] }
|
||||
(( bold )) && message="%B${message}%b"
|
||||
[[ -n "$foreground" ]] && message="%F{$foreground}$message%f"
|
||||
[[ -n "$background" ]] && message="%K{$background}$message%k"
|
||||
[[ -n "$prefix" ]] && message="$prefix $message"
|
||||
|
||||
[[ ${NOISY:-0} -ge $level ]] && print -P "${message}"
|
||||
}
|
||||
|
||||
function print_info { print_msg -p '%F{blue}==>%f' "$@" }
|
||||
function print_error { print_msg -p '%F{red}==>%f' "$@" }
|
||||
|
||||
function print_heading { print_msg -b "$@" }
|
||||
function print_info_heading { print_info -b "$@" }
|
||||
function print_error_heading { print_error -b "$@" }
|
||||
|
||||
function print_msg_sub { print_msg -p " *" "$@" }
|
||||
function print_info_sub { print_msg_sub -p ' %F{blue}*%f' "$@" }
|
||||
function print_error_sub { print_msg_sub -p ' %F{error}*%f' "$@" }
|
||||
|
||||
function binary_exists { return $(hash $1 1>/dev/null 2>&1) }
|
||||
function binary_not_exists { binary_exists $1; return $(( ! $? )) }
|
||||
|
|
2
zprofile
2
zprofile
|
@ -5,7 +5,7 @@
|
|||
#
|
||||
# Eryn Wells <eryn@erynwells.me>
|
||||
|
||||
print_info_noisy 1 'Initializing login shell'
|
||||
print_heading -l 1 'Initializing login shell'
|
||||
|
||||
[ -e $HOME/.profile ] && source $HOME/.profile
|
||||
|
||||
|
|
31
zshrc
31
zshrc
|
@ -12,17 +12,17 @@ ZLE_MODE='vim'
|
|||
# load bash/zsh/ksh agnostic configurations
|
||||
[ -e $HOME/.rc ] && source $HOME/.rc
|
||||
|
||||
print_info_noisy 1 "Initializing interactive Z Shell"
|
||||
print_heading -l 1 "Initializing interactive Z Shell"
|
||||
|
||||
|
||||
function configure_general #{{{
|
||||
{
|
||||
print_info_sub_noisy 2 'Configuring general ZSH settings'
|
||||
print_info -l 2 'Configuring general ZSH settings'
|
||||
|
||||
# Report seconds since shell was invoked in milliseconds
|
||||
typeset -F SECONDS
|
||||
|
||||
print_info_sub_noisy 2 'Setting shell options'
|
||||
print_info_sub -l 3 'Setting shell options'
|
||||
# See zshoptions(1)
|
||||
setopt EXTENDED_GLOB \
|
||||
MULTIOS \
|
||||
|
@ -33,9 +33,9 @@ function configure_general #{{{
|
|||
|
||||
function configure_zle #{{{
|
||||
{
|
||||
print_info_sub_noisy 2 'Configuring ZLE'
|
||||
print_info -l 2 'Configuring ZLE'
|
||||
|
||||
print_info_sub_noisy 5 "Using $ZLE_MODE command line editing mode"
|
||||
print_info_sub -l 5 "Using $ZLE_MODE command line editing mode"
|
||||
[[ -z "$ZLE_MODE" ]] && ZLE_MODE='vim'
|
||||
if [[ $ZLE_MODE == 'vim' ]]; then
|
||||
bindkey -v
|
||||
|
@ -55,26 +55,26 @@ function configure_zle #{{{
|
|||
|
||||
function configure_modules_and_functions #{{{
|
||||
{
|
||||
print_info_noisy 2 'Loading modules'
|
||||
print_info -l 2 'Loading modules'
|
||||
|
||||
local myfpath="$HOME/.zsh/func"
|
||||
print_info_sub_noisy 2 "Adding $myfpath to \$fpath"
|
||||
print_info_sub -l 2 "Adding $myfpath to \$fpath"
|
||||
fpath=($myfpath/makers $myfpath $fpath)
|
||||
|
||||
print_info_sub_noisy 3 'Loading vcs_info'
|
||||
print_info -l 3 'Loading vcs_info'
|
||||
autoload -Uz vcs_info
|
||||
zstyle ':vcs_info:*' enable git
|
||||
|
||||
load_module 'makers'
|
||||
|
||||
print_info_sub_noisy 3 "Loading pw module"
|
||||
print_info -l 3 "Loading pw module"
|
||||
autoload pw
|
||||
} #}}}
|
||||
|
||||
|
||||
function configure_prompt #{{{
|
||||
{
|
||||
print_info_sub_noisy 2 "Configuring prompt: $PROMPT_THEME"
|
||||
print_info -l 2 "Configuring prompt: $PROMPT_THEME"
|
||||
autoload -U promptinit
|
||||
promptinit
|
||||
prompt $PROMPT_THEME
|
||||
|
@ -83,7 +83,7 @@ function configure_prompt #{{{
|
|||
|
||||
function configure_zsh_aliases #{{{
|
||||
{
|
||||
print_info_sub_noisy 3 'Creating ZSH-specific aliases'
|
||||
print_info -l 3 'Creating ZSH-specific aliases'
|
||||
alias pd='pushd'
|
||||
alias pod='popd'
|
||||
|
||||
|
@ -101,7 +101,7 @@ function configure_zsh_aliases #{{{
|
|||
|
||||
function configure_history #{{{
|
||||
{
|
||||
print_info_sub_noisy 4 'Setting up history'
|
||||
print_info -l 2 'Setting up history'
|
||||
setopt \
|
||||
APPEND_HISTORY \
|
||||
EXTENDED_HISTORY \
|
||||
|
@ -120,7 +120,7 @@ function configure_history #{{{
|
|||
|
||||
function configure_completion #{{{
|
||||
{
|
||||
print_info_sub_noisy 2 'Initializing completion system'
|
||||
print_info -l 2 'Initializing completion system'
|
||||
|
||||
autoload -U compinit
|
||||
compinit
|
||||
|
@ -151,7 +151,6 @@ function configure_completion #{{{
|
|||
|
||||
configure_general
|
||||
configure_zle
|
||||
configure_fpath
|
||||
configure_modules_and_functions
|
||||
configure_zsh_aliases
|
||||
configure_history
|
||||
|
@ -160,11 +159,11 @@ configure_prompt
|
|||
|
||||
|
||||
if [ -e $HOME/.zshrc.$SYS ]; then
|
||||
print_info_noisy 3 "Sourcing ${SYS}-specific Z Shell settings"
|
||||
print_info -l 3 "Sourcing ${SYS}-specific Z Shell settings"
|
||||
source $HOME/.zshrc.$SYS
|
||||
fi
|
||||
|
||||
if [ -e $HOME/.zshrc.local ]; then
|
||||
print_info_noisy 3 "Sourcing local Z Shell settings"
|
||||
print_info -l 3 "Sourcing local Z Shell settings"
|
||||
source $HOME/.zshrc.local
|
||||
fi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue