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