nice cleanup removes nastygrams if not configured
[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 # SHELL_DEBUG: 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 SHELL_DEBUG=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 '\n\n'
48     echo -e "\
49 The feisty meow scripts need initialization via the bootstrap process, which\n\
50 can be accomplished if one knows where the scripts are stored.  For example,\n\
51 if feisty_meow is in the home directory, then this command will bootstrap the\n\
52 script configuration:\n\
53 \n\
54   bash $HOME/feisty_meow/scripts/core/reconfigure_feisty_meow.sh\n\
55 \n\
56 Or, if the feisty_meow folder is installed system-wide in a location such as\n\
57 /usr/local/feisty_meow, then this command would bootstrap the scripts:\n\
58 \n\
59   bash /usr/local/feisty_meow/scripts/core/reconfigure_feisty_meow.sh\n\
60 \n"
61     ERROR_OCCURRED=true
62   fi
63
64   ##############
65
66   if [ -z "$ERROR_OCCURRED" ]; then
67
68     # pull in our generated variables that are the minimal set we need to find
69     # the rest of our resources.
70     source "$FEISTY_MEOW_VARIABLES_LOADING_FILE"
71
72     # Set up the temporary directory.
73     source "$FEISTY_MEOW_SCRIPTS/core/create_tempdir.sh"
74   fi
75
76 fi
77
78 ##############
79
80 if [ -z "$ERROR_OCCURRED" ]; then
81
82   # load the larger body of standard feisty meow variables into the environment.
83   # we actually want this to always run also; it will decide what variables need
84   # to be set again.
85   source "$FEISTY_MEOW_SCRIPTS/core/variables.sh"
86
87   ##############
88   
89   # include helpful functions.  we do this every time rather than making it part
90   # of variable initialization, because functions cannot be exported to
91   # sub-shells in bash.
92   source "$FEISTY_MEOW_SCRIPTS/core/functions.sh"
93   
94   # load some helper methods for the terminal which we'll use below.
95   source "$FEISTY_MEOW_SCRIPTS/tty/terminal_titler.sh"
96
97   ##############
98   
99   # check hash table before searching path.
100   shopt -s checkhash
101   # don't check path for sourced files.
102   shopt -u sourcepath
103   # ignore duplicate lines.
104   HISTCONTROL=ignoredups
105   # append to the history file.
106   shopt -s histappend
107   # automatically update window size if needed.
108   shopt -s checkwinsize
109
110   ##############
111
112   # make history writes immediate to avoid losing history if bash is zapped.
113   echo $PROMPT_COMMAND | grep -q history
114   if [ $? -ne 0 ]; then
115     # we only change the prompt command if we think it hasn't already been done.
116     export PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
117   fi
118   
119   ##############
120   
121   # perform the bulkier parts of the initialization process.
122   
123   if [ ! -z "$SHELL_DEBUG" ]; then echo "heavyweight init begins..."; fi
124   
125   # set up the aliases for the shell, but only if they are not already set.
126   type CORE_ALIASES_LOADED &>/dev/null
127   if [ $? -ne 0 ]; then
128     if [ ! -z "$SHELL_DEBUG" ]; then
129       echo "the aliases were missing, now they are being added..."
130     fi
131     source "$FEISTY_MEOW_LOADING_DOCK/fmc_core_and_custom_aliases.sh"
132   fi
133   
134   #echo before the new labelling, terminal titles have:
135   #show_terminal_titles
136   
137   # a minor tickle of the title of the terminal, unless we already have some history.
138   label_terminal_with_info
139   
140   if [ ! -z "$SHELL_DEBUG" ]; then echo "heavyweight init is done."; fi
141   
142   if [ -z "$ERROR_OCCURRED" ]; then
143     # set a sentinel variable to say we loaded the feisty meow environment.
144     export FEISTY_MEOW_SCRIPTS_LOADED=true
145   fi
146
147 fi  # no error occurred.
148