forked from Andersbakken/nrdp-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc_dispatch
executable file
·94 lines (70 loc) · 2.59 KB
/
.bashrc_dispatch
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
#!/bin/bash
# Launch different bash configuration for Linux vs OSX, interactive vs batch
#
# More info at https://github.com/josephwecker/bashrc_dispatch
#
# License: Public Domain.
# Author: Joseph Wecker, 2012
# Configuration
# -------------
#
# EXPORT_FUNCTIONS: export SHELL_PLATFORM and shell_is_* functions for use
# in other scripts.
EXPORT_FUNCTIONS=true
# Code
# ----
# Avoid recursive invocation
[ -n "$BASHRC_DISPATCH_PID" ] && [ $$ -eq "$BASHRC_DISPATCH_PID" ] && return
BASHRC_DISPATCH_PID=$$
# Setup the main shell variables and functions
if [ -z "$SHELL_PLATFORM" ]; then
SHELL_PLATFORM='OTHER'
case "$OSTYPE" in
*'linux'* ) SHELL_PLATFORM='LINUX' ;;
*'darwin'* ) SHELL_PLATFORM='OSX' ;;
*'freebsd'* ) SHELL_PLATFORM='BSD' ;;
esac
fi
if ! type -p shell_is_login ; then
shell_is_linux () { [[ "$OSTYPE" == *'linux'* ]] ; }
shell_is_osx () { [[ "$OSTYPE" == *'darwin'* ]] ; }
shell_is_login () { shopt -q login_shell ; }
shell_is_interactive () { test -n "$PS1" ; }
shell_is_script () { ! shell_is_interactive ; }
fi
shell_dispatch_brief() {
# echo "Brief: $@"
true
}
# Make $BASH_ENV the same in interactive and non-interactive scripts
[ -z "$BASH_ENV" ] && export BASH_ENV="$BASH_SOURCE"
# Make these available to the potentially convoluted bashrc_* startup scripts
if $EXPORT_FUNCTIONS ; then
export SHELL_PLATFORM
export -f shell_is_linux
export -f shell_is_osx
export -f shell_is_login
export -f shell_is_interactive
export -f shell_is_script
fi
# Now dispatch special files
PRF="${HOME}/."
[ -f "${PRF}bashrc_once" ] && [ -z "$BRCD_RANONCE" ] && shell_dispatch_brief "exe_once" && . "${PRF}bashrc_once" && export BRCD_RANONCE=true
[ -f "${PRF}bashrc_all" ] && shell_dispatch_brief "exe_all" && . "${PRF}bashrc_all"
[ -f "${PRF}bashrc_script" ] && shell_is_script && shell_dispatch_brief "exe_script" && . "${PRF}bashrc_script"
[ -f "${PRF}bashrc_interactive" ] && shell_is_interactive && shell_dispatch_brief "exe_interative" && . "${PRF}bashrc_interactive"
[ -f "${PRF}bashrc_login" ] && shell_is_login && shell_dispatch_brief "exe_login" && . "${PRF}bashrc_login"
# Unset variables if necessary to avoid env polution
if ! $EXPORT_FUNCTIONS ; then
unset SHELL_PLATFORM
unset -f shell_is_linux
unset -f shell_is_osx
unset -f shell_is_login
unset -f shell_is_interactive
unset -f shell_is_script
fi
# Unset local variables
unset fn_cmd
unset EXPORT_FUNCTIONS
unset BASHRC_DISPATCH_PID
unset PRF