From: Simon Ruderich Date: Sat, 18 Sep 2010 22:42:13 +0000 (+0200) Subject: Simplify configuration setup. X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=9598f48f59d3ad70faac00f5c4c9466d28591a7e;p=config%2Fdotfiles.git Simplify configuration setup. Drop the host related configuration files and just load a .local file if it exists. Simplify source_config() for this as well, drop its test files. --- diff --git a/bash/host/rc.zucker b/bash/host/rc.zucker deleted file mode 100644 index 99301db..0000000 --- a/bash/host/rc.zucker +++ /dev/null @@ -1,7 +0,0 @@ -# Bash configuration file for zucker.schokokeks.org. - - -# Immediately start zsh. -exec zsh - -# vim: ft=sh diff --git a/bash/logout b/bash/logout index 90cb162..a191464 100644 --- a/bash/logout +++ b/bash/logout @@ -3,8 +3,7 @@ source_debug ". ~/.bash/logout" -# Load logout file usable by all shells. -source_config ~/.shell "" logout +source_config ~/.shell/logout source_debug ". ~/.bash/logout (done)" diff --git a/bash/rc b/bash/rc index 7243ceb..3cc4827 100644 --- a/bash/rc +++ b/bash/rc @@ -3,27 +3,11 @@ # Is sourced by all interactive shells and other shells like scp or rcp. -# Get the current hostname (first part before a dot). -host=$(echo $(hostname) | sed -e 's/\..*$//') - -# Load environmental related settings used by all shells. -if [[ -f ~/.shell/env ]]; then - . ~/.shell/env -# Fallback functions as ~/.shell/env couldn't be loaded. -else - function source_debug() { - echo $@ - } - function source_config() { - echo "Couldn't load source_config(), can't source files." >&2 - } -fi +. ~/.shell/functions source_debug ". ~/.bash/rc" -# Load global env file for current hostname (first part before a dot) or -# global env.local. -source_config ~/.shell "" env $host +source_config ~/.shell/env # Check if this is an interactive shell. Abort if not to prevent problems with @@ -40,14 +24,10 @@ PS1='\[\033[01;32m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\] \$ ' # Use Vi(m) style in bash. set -o vi -# Load aliases and similar functions also used by other shells. -if [[ -f ~/.shell/aliases ]]; then - . ~/.shell/aliases -fi +source_config ~/.shell/aliases -# Load rc file for current hostname (first part before a dot) or rc.local. -source_config ~/.bash host rc $host +source_config ~/.bash/rc.local source_debug ". ~/.bash/rc (done)" diff --git a/shell/env b/shell/env index ed0ec52..a71dfc7 100644 --- a/shell/env +++ b/shell/env @@ -1,8 +1,6 @@ # Configuration file for environment related options for all shells. -. ~/.shell/functions - source_debug ". ~/.shell/env" diff --git a/shell/env.rammstein b/shell/env.rammstein deleted file mode 100644 index 1d9d096..0000000 --- a/shell/env.rammstein +++ /dev/null @@ -1,17 +0,0 @@ -# Configuration file for environment related options for all shells for my -# local computer. - - -# Display options, necessary for X11 window manager. -DISPLAY=':0.0' -export DISPLAY - -# Set HTTP proxy for privoxy/tor. -http_proxy=http://127.0.0.1:8119/ -HTTP_PROXY=$http_proxy -export http_proxy HTTP_PROXY - -# Necessary for xterm to find man pages through PATH. -unset MANPATH - -# vim: ft=sh diff --git a/shell/functions b/shell/functions index 8a9bcb3..308252b 100644 --- a/shell/functions +++ b/shell/functions @@ -11,81 +11,19 @@ source_debug() { fi } -# Sources a configuration file if it exists; loads a fallback .local file if -# it doesn't. If the .local files doesn't exist nothing is sourced. -# -# $1: Path to directory where configuration files are located. -# $2: Directory name in $1 where the non .local files are stored, can be -# empty. If empty both configuration files (normal and .local) are stored -# in $1. -# $3: Base name of file in $2, for example "rc" or "env". -# $4: Extension for $3, if this file doesn't exist "$1/$3.local" is sourced. -# Can be empty, then no extension is used. -# $5: Additional options, set to nolocal to prevent loading of "$1/$3.local" -# if "$1/$2/$3.$4" doesn't exist. -# -# Example with the following directory/file structure, $os is Darwin and -# $hostname is marvin. -# -# ~/.zsh -# ~/.zsh/env -# ~/.zsh/env.local -# ~/.zsh/rc -# ~/.zsh/rc.local -# ~/.zsh/host/rc.marvin -# ~/.zsh/os/rc.Darwin -# -# To load additional rc files from within ~/.zsh/rc use the following: -# -# source_config ~/.zsh os rc $os # loads os/rc.Darwin -# source_config ~/.zsh host rc $hostname # loads host/rc.marvin -# -# To load additional env files from within ~/.zsh/env use the following (note -# nolocal to prevent loading env.local two times if os and host files don't -# exist): -# -# source_config zsh os env $os nolocal # loads os/rc.Darwin -# source_config zsh host env $hostname # loads env.local -# -# By letting $4 empty normal configuration files can be sourced. A .local can -# still be used. -# -# source_config zsh "" file # loads zsh/file if it exists -# -# Doesn't fit perfectly in this file, but this is the best place to make it -# available everywhere. -# -# If DEBUG is set to a non empty value additional debug output is printed. +# Source $1 if it exists. And $1.local if it exists as well. source_config() { - # Path to the file to source and its local counterpart. - if [ x$4 != x ]; then - source_file=$1/$2/$3.$4 - # If $4 is empty don't append a trailing dot. This allows source_config() - # to load normal configuration files. - else - source_file=$1/$2/$3 - fi - source_file_local=$1/$3.local - - # Additional debug output. - source_debug "source_config(): checking if $source_file exists" - source_debug "source_config(): checking if $source_file_local exists" + source_debug "source_config(): $1" - # If the file does exist then source it. - if [ -f $source_file ]; then - source_debug "source_config(): -> sourcing $source_file" - . $source_file - - # Otherwise load the .local file if it exists and .local files are - # allowed. - elif [ -f $source_file_local -a x$5 != xnolocal ]; then - source_debug "source_config(): -> sourcing $source_file_local" - . $source_file_local - else - source_debug "source_config(): -> neither exists" + if [ -f $1 ]; then + source_debug "source_config(): . $1" + . $1 fi - unset source_file source_file_local + if [ -f $1.local ]; then + source_debug "source_config(): . $1.local" + . $1.local + fi } # vim: ft=sh diff --git a/tests/run.zsh b/tests/run.zsh deleted file mode 100644 index a34281b..0000000 --- a/tests/run.zsh +++ /dev/null @@ -1,25 +0,0 @@ -# Runs all tests. - - -# Get all test files. -for file in *.test; do - # Run the test file in zsh and sh and get its output. - zsh $file &> $file.out.zsh - sh $file &> $file.out.sh - - # Check if the output matches the expected one. If not abort with exit - # code 1. - diff -u $file.out $file.out.zsh - if [[ $? -ne 0 ]]; then - exit 1 - fi - diff -u $file.out $file.out.sh - if [[ $? -ne 0 ]]; then - exit 1 - fi -done - -# Remove all temporary files. -rm -rf tmp -rm *.out.zsh -rm *.out.sh diff --git a/tests/source_config.test b/tests/source_config.test deleted file mode 100644 index 7237d11..0000000 --- a/tests/source_config.test +++ /dev/null @@ -1,52 +0,0 @@ -# Test file for source_config(). - - -# Load source_config(). -. ../shell/env - - -# Make sure the old temporary directory is removed. -rm -rf tmp -# Create the test directories/files. -mkdir tmp -mkdir tmp/bash -mkdir tmp/shell -mkdir tmp/zsh tmp/zsh/host tmp/zsh/os -echo echo loaded bash/env.zucker > tmp/shell/env.zucker -echo echo loaded shell/env.zucker > tmp/shell/env.zucker -echo echo loaded shell/logout > tmp/shell/logout -echo echo loaded zsh.env.local > tmp/zsh/env.local -echo echo loaded zsh/rc.local > tmp/zsh/rc.local -echo echo loaded zsh/host/rc.zucker > tmp/zsh/host/rc.zucker -echo echo loaded zsh/os/rc.Darwin > tmp/zsh/os/rc.Darwin - - -function tests() { - source_config tmp/zsh os rc Darwin nolocal - echo -n $source_file$source_file_local - source_config tmp/zsh host rc zucker - echo -n $source_file$source_file_local - - source_config tmp/zsh os env Darwin nolocal - echo -n $source_file$source_file_local - source_config tmp/zsh host env zucker - echo -n $source_file$source_file_local - - source_config tmp/bash host rc zucker - echo -n $source_file$source_file_local - - source_config tmp/shell "" env zucker - echo -n $source_file$source_file_local - - source_config tmp/shell "" logout - echo -n $source_file$source_file_local - source_config tmp/shell "" doesnt-exist - echo -n $source_file$source_file_local -} - -# Run tests without and with debug output. -tests -echo -DEBUG=1 tests - -# vim: ft=sh diff --git a/tests/source_config.test.out b/tests/source_config.test.out deleted file mode 100644 index 693a4af..0000000 --- a/tests/source_config.test.out +++ /dev/null @@ -1,35 +0,0 @@ -loaded zsh/os/rc.Darwin -loaded zsh/host/rc.zucker -loaded zsh.env.local -loaded shell/env.zucker -loaded shell/logout - -source_config(): checking if tmp/zsh/os/rc.Darwin exists -source_config(): checking if tmp/zsh/rc.local exists -source_config(): -> sourcing tmp/zsh/os/rc.Darwin -loaded zsh/os/rc.Darwin -source_config(): checking if tmp/zsh/host/rc.zucker exists -source_config(): checking if tmp/zsh/rc.local exists -source_config(): -> sourcing tmp/zsh/host/rc.zucker -loaded zsh/host/rc.zucker -source_config(): checking if tmp/zsh/os/env.Darwin exists -source_config(): checking if tmp/zsh/env.local exists -source_config(): -> neither exists -source_config(): checking if tmp/zsh/host/env.zucker exists -source_config(): checking if tmp/zsh/env.local exists -source_config(): -> sourcing tmp/zsh/env.local -loaded zsh.env.local -source_config(): checking if tmp/bash/host/rc.zucker exists -source_config(): checking if tmp/bash/rc.local exists -source_config(): -> neither exists -source_config(): checking if tmp/shell//env.zucker exists -source_config(): checking if tmp/shell/env.local exists -source_config(): -> sourcing tmp/shell//env.zucker -loaded shell/env.zucker -source_config(): checking if tmp/shell//logout exists -source_config(): checking if tmp/shell/logout.local exists -source_config(): -> sourcing tmp/shell//logout -loaded shell/logout -source_config(): checking if tmp/shell//doesnt-exist exists -source_config(): checking if tmp/shell/doesnt-exist.local exists -source_config(): -> neither exists diff --git a/zsh/env b/zsh/env index aaeb493..be6c528 100644 --- a/zsh/env +++ b/zsh/env @@ -1,35 +1,18 @@ # Zsh configuration file for environment related options. -# Get the current hostname (first part before a dot). -host=${$(hostname)//.*/} - -# Load environmental related settings used by all shells. -if [[ -f ~/.shell/env ]]; then - . ~/.shell/env -# Fallback functions as ~/.shell/env couldn't be loaded. -else - function source_debug() { - echo $@ - } - function source_config() { - echo "Couldn't load source_config(), can't source files." >&2 - } -fi +. ~/.shell/functions source_debug ". ~/.zsh/env" +source_config ~/.shell/env + # Make sure elements in PATH are unique. typeset -U path PATH -# Load global env file for current hostname (first part before a dot) or -# global env.local. -source_config ~/.shell "" env $host - -# Load env file for current hostname (first part before a dot) or env.local. -source_config ~/.zsh host env $host +source_config ~/.zsh/env.local source_debug ". ~/.zsh/env (done)" diff --git a/zsh/host/env.nightwish b/zsh/host/env.nightwish deleted file mode 100644 index 2f7759d..0000000 --- a/zsh/host/env.nightwish +++ /dev/null @@ -1,8 +0,0 @@ -# Zsh configuration file for environment related options for my father's G5. - - -# Update the default PATH to include MacPorts, X11, and /usr/local. -typeset -U path -path=(/opt/local/bin /opt/local/sbin /usr/local/bin $path /usr/X11R6/bin) - -# vim: ft=zsh diff --git a/zsh/host/env.rammstein b/zsh/host/env.rammstein deleted file mode 100644 index da59565..0000000 --- a/zsh/host/env.rammstein +++ /dev/null @@ -1,14 +0,0 @@ -# Zsh configuration file for environment related options for my local computer. - - -# Path to my local "unix" directory where my scripts, configuration files and -# other unix related data is stored. -MYUNIX=~/Documents/unix - -# Add my bin/ directory, macports bin/ and sbin/ and the X11 bin/ directory to -# the default PATH. -g is necessary as the file is loaded by source_config(), -# otherwise the path wouldn't be changed outside the function. -typeset -g -U path -path=($MYUNIX/bin /opt/local/bin /opt/local/sbin $path /usr/X11R6/bin) - -# vim: ft=zsh diff --git a/zsh/host/rc.rammstein b/zsh/host/rc.rammstein deleted file mode 100644 index 6dba948..0000000 --- a/zsh/host/rc.rammstein +++ /dev/null @@ -1,23 +0,0 @@ -# Zsh configuration file for my local computer. - - -# Shortcuts for the prompt and to cd to important directories. -unix=~/Documents/unix -macports=${unix}/macports -htdocs=/Library/WebServer/Documents -page=${htdocs}/page -# Activate these shortcuts. -: ~unix ~macports ~htdocs ~page - -# Aliases for easy and fast cd to important directories. -alias cdu='cd ~unix' -alias cdm='cd ~macports' -alias cdh='cd ~htdocs' -alias cdp='cd ~page' - -# Path to my mail spoolfile. -MAIL=/var/mail/$USER -# Check for new mails every ten seconds. -MAILCHECK=10 - -# vim: ft=zsh diff --git a/zsh/host/rc.zucker b/zsh/host/rc.zucker deleted file mode 100644 index afbb955..0000000 --- a/zsh/host/rc.zucker +++ /dev/null @@ -1,14 +0,0 @@ -# Zsh configuration file for zucker.schokokeks.org. - - -# Shortcuts for the prompt and to cd to important directories. -htdocs=~/websites/ruderich.org/htdocs -logs=/var/log/apache2/ruderich -# Activate these shortcuts. -: ~htdocs ~logs - -# Aliases for easy and fast cd to important directories. -alias cdh='cd ~htdocs' -alias cdl='cd ~logs' - -# vim: ft=zsh diff --git a/zsh/logout b/zsh/logout index f231a31..c360815 100644 --- a/zsh/logout +++ b/zsh/logout @@ -3,8 +3,7 @@ source_debug ". ~/.zsh/logout" -# Load logout file usable by all shells. -source_config ~/.shell "" logout +source_config ~/.shell/logout source_debug ". ~/.zsh/logout (done)" diff --git a/zsh/rc b/zsh/rc index b94e24e..e0bf4c7 100644 --- a/zsh/rc +++ b/zsh/rc @@ -613,8 +613,7 @@ fi # LOAD ADDITIONAL CONFIGURATION FILES -# Load rc file for current hostname (first part before a dot) or rc.local. -source_config ~/.zsh host rc ${$(hostname)//.*/} +source_config ~/.zsh.rc.local # RUN COMMANDS