Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

134 lines (116 sloc) 2.829 kB
# -*- mode: sh -*-
#
# .ns - Nice Shell
# ^^^^^^^^^^^^^^^^ don't touch this line
# (short name for quick invocation from other shells)
#
# Source this to get a decent setup from another account.
#
# $Id$
#
if [ -n "$DEBUG_NS" ]; then
set -x
fi
detect_current_shell () {
current_shell=
if [ -n "$ZSH_VERSION" ]; then
current_shell=zsh
if [ -n "$BASH_VERSION" ]; then
echo "BUG! Both {BASH,ZSH}_VERSION set" >&2
return 1
fi
elif [ -n "$BASH_VERSION" ]; then
current_shell=bash
else
case "$SHELL" in
*bash) current_shell=bash ;;
*zsh) current_shell=zsh ;;
esac
fi
}
find_me () {
if [ -n "$1" ] && grep -q '# .ns - Nice Shell' "$1"; then
me="$1"
return 0
fi
if [ -n "${BASH_SOURCE[0]}" ]; then
me="${BASH_SOURCE[0]}"
else
me="$0"
fi
case "$here" in
-*)
echo "Couldn't figure out where to look for .zshrc; please specify ZDOTDIR. Aborting." >&2
return 1
;;
esac
return 0
}
find_zdotdir () {
here="`dirname $me`"
if ! [ -e $here/.zshrc ]; then
echo "$here missing .zshrc, aborting." >&2
return 1
fi
# Not sure why I bothered with this.
# here="`$here/bin/shortcuts/abs $0`"
# here="`dirname $here`"
if ! [ -e $here/.zshrc ]; then
echo "abs failed"
return 1
fi
ZDOTDIR="$here"
return 0
}
detect_current_shell
# We have to intelligently guess where this file is.
# When this file is sourced:
# in sh/bash/ksh, $0 becomes the interpreter name (i.e. 'bash' etc.)
# in zsh, $0 becomes the argument to source (i.e. this file)
case "$current_shell" in
bash)
find_me || return $?
;;
zsh)
find_me "$0" || return $?
;;
*)
echo "FIXME: current_shell=$current_shell not yet supported" >&2
return 1
;;
esac
if [ -z "$ZDOTDIR" ]; then
find_zdotdir || return $?
fi
if [ -z "$ZDOTDIR" ]; then
echo "BUG: find_zdotdir failed?!" >&2
return 1
fi
export ZDOTDIR # but see caveat at EOF
[ -z "$shared_env_loaded" ] && source "$ZDOTDIR/.shared_env"
# Don't do anything with non-interactive shells.
[ -z "$shell_interactive" ] && return 1
if [ -n "$DEBUG_NS" ]; then
set +x
fi
case "$current_shell" in
bash)
source "$ZDOTDIR/.bashenv"
source "$ZDOTDIR/.bashrc"
# Are you feeling lucky, punk?
SHLVL=force_danger source "$ZDOTDIR/.switch_shell" "$@"
;;
zsh)
source "$ZDOTDIR/.zshenv"
source "$ZDOTDIR/.zshrc"
;;
*)
source "$ZDOTDIR/.switch_shell" "$@"
;;
esac
# N.B. If this file was source'd via:
# ZDOTDIR=/home/aspiers source /home/aspiers/.ns
# or similar, as soon as the "source-ing" finishes,
# for some reason ZDOTDIR vanishes. So better to
# do an explicit export of ZDOTDIR at invocation time.
# Dunno if this is a bug or feature.
Jump to Line
Something went wrong with that request. Please try again.