tasty changes for going live
[feisty_meow.git] / scripts / core / launch_feisty_meow.sh
1 #!/bin/bash
2
3 ##############
4
5 # Fred Hamster's Feisty Meow Concerns Ltd. Startup Profile.
6 #
7 # This file is useful within .profile or other initialization scripts.
8 #
9 # Author: Chris Koeritz
10
11 ##############
12
13 # DEBUG_FEISTY_MEOW: if this variable is non-empty, then it causes the feisty meow
14 # scripts to print more diagnostic information when they run.  not all
15 # scripts support this, but the core ones do.
16
17 #export DEBUG_FEISTY_MEOW=true
18
19 ##############
20
21 # some preconditions we want to establish before loading anything...
22
23 # make sure that aliases can be used in non-interactive shells.
24 shopt -s expand_aliases
25
26 # patch the user variable if we were launched by one of our cron jobs.
27 if [ -z "$USER" -a ! -z "$CRONUSER" ]; then
28   export USER="$CRONUSER"
29 fi
30
31 ##############
32
33 export ERROR_OCCURRED=
34   # there have been no errors to start with, at least.  we will set this
35   # to non-empty if something bad happens.
36
37 if [ -z "$FEISTY_MEOW_LOADING_DOCK" ]; then
38   # FEISTY_MEOW_LOADING_DOCK is where the generated files are located.
39   # this is our single entry point we can use without knowing any variables
40   # yet in the initialization process.
41   export FEISTY_MEOW_LOADING_DOCK="$HOME/.zz_feisty_loading"
42 #hmmm: the above is kind of a constant.  that's not so great.
43
44   # make sure our main variables are established.
45   FEISTY_MEOW_VARIABLES_LOADING_FILE="$FEISTY_MEOW_LOADING_DOCK/fmc_variables.sh"
46   if [ ! -f "$FEISTY_MEOW_VARIABLES_LOADING_FILE" ]; then
47     echo -e "\
48
49 The feisty meow scripts need initialization via the bootstrap process.  For\n\
50 example, if the feisty meow folder lives in '$DEFAULT_FEISTYMEOW_ORG_DIR', then this\n\
51 command bootstraps feisty meow:\n\
52 \n\
53   bash $example_dir/feisty_meow/scripts/core/reconfigure_feisty_meow.sh\n\
54 \n\
55 \n"
56     ERROR_OCCURRED=true
57   fi
58
59   ##############
60
61   if [ -z "$ERROR_OCCURRED" ]; then
62
63     # pull in our generated variables that are the minimal set we need to find
64     # the rest of our resources.
65     source "$FEISTY_MEOW_VARIABLES_LOADING_FILE"
66
67     # Set up the temporary directory.
68     source "$FEISTY_MEOW_SCRIPTS/core/create_tempdir.sh"
69   fi
70
71 fi
72
73 ##############
74
75 if [ -z "$ERROR_OCCURRED" ]; then
76
77   # load the larger body of standard feisty meow variables into the environment.
78   # we actually want this to always run also; it will decide what variables need
79   # to be set again.
80   source "$FEISTY_MEOW_SCRIPTS/core/variables.sh"
81
82   ##############
83   
84   # include helpful functions.  we do this every time rather than making it part
85   # of variable initialization, because functions cannot be exported to
86   # sub-shells in bash.
87   source "$FEISTY_MEOW_SCRIPTS/core/functions.sh"
88   
89   # load some helper methods for the terminal which we'll use below.
90   source "$FEISTY_MEOW_SCRIPTS/tty/terminal_titler.sh"
91
92   ##############
93   
94   # check hash table before searching path.
95   shopt -s checkhash
96   # don't check path for sourced files.
97   shopt -u sourcepath
98   # ignore duplicate lines.
99   HISTCONTROL=ignoredups
100   # append to the history file.
101   shopt -s histappend
102   # automatically update window size if needed.
103   shopt -s checkwinsize
104
105   ##############
106
107   # make history writes immediate to avoid losing history if bash is zapped.
108   echo $PROMPT_COMMAND | grep -q history
109   if [ $? -ne 0 ]; then
110     # we only change the prompt command if we think it hasn't already been done.
111     export PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
112   fi
113   
114   ##############
115   
116   # perform the bulkier parts of the initialization process.
117   
118   if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then echo "heavyweight init begins..."; fi
119   
120   # set up the aliases for the shell, but only if they are not already set.
121   type CORE_ALIASES_LOADED &>/dev/null
122   if [ $? -ne 0 ]; then
123     if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then
124       echo "the aliases were missing, now they are being added..."
125     fi
126     source "$FEISTY_MEOW_LOADING_DOCK/fmc_core_and_custom_aliases.sh"
127   fi
128   
129   #echo before the new labelling, terminal titles have:
130   #show_terminal_titles
131   
132   # a minor tickle of the title of the terminal, unless we already have some history.
133   label_terminal_with_info
134   
135   if [ ! -z "$DEBUG_FEISTY_MEOW" ]; then echo "heavyweight init is done."; fi
136   
137   if [ -z "$ERROR_OCCURRED" ]; then
138     # set a sentinel variable to say we loaded the feisty meow environment.
139     export FEISTY_MEOW_SCRIPTS_LOADED=true
140   fi
141
142 fi  # no error occurred.
143