-
Notifications
You must be signed in to change notification settings - Fork 13
/
.ns
131 lines (114 loc) · 2.75 KB
/
.ns
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# -*- 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.
#
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.