cleaned up behavior when no custom files are defined yet.
[feisty_meow.git] / scripts / core / unter_alia.sh
1 #!/bin/bash
2
3 # generates alias files for bash.
4 #
5 # The "common.alias" file is used in the generated aliases file as a base
6 # set of generally useful aliases.  We also add aliases for any script files
7 # (perl, bash, python, etc) that we find in the feisty meow script hierarchy.
8 # Any *.alias files found in the $FEISTY_MEOW_GENERATED/custom folder are
9 # loaded also.
10
11 if [ ! -z "$SHELL_DEBUG" ]; then echo rebuiling generated aliases file...; fi
12
13 # create our generated shells directory if it's not already.
14 if [ ! -d $FEISTY_MEOW_GENERATED ]; then mkdir $FEISTY_MEOW_GENERATED; fi
15
16 # test if we can use color in ls...
17 test_color=$(ls --help 2>&1 | grep -i color)
18
19 # the main one is our common alias set.
20 ALIAS_DEFINITION_FILES=("$FEISTY_MEOW_SCRIPTS/core/common.alias")
21
22 # if custom aliases files exist, add them to the list.
23 for i in "$FEISTY_MEOW_GENERATED/custom/*.alias"; do
24   if [ -f "$i" ]; then
25     ALIAS_DEFINITION_FILES+=("$i")
26   fi
27 done
28 echo "alias files:"
29 for i in "${ALIAS_DEFINITION_FILES[@]}"; do
30   echo "  $(basename $(dirname $i))/$(basename $i)"
31 done
32
33 # write the aliases for sh and bash scripts.
34
35 GENERATED_ALIAS_FILE="$FEISTY_MEOW_GENERATED/fmc_core_and_custom_aliases.sh"
36 echo "writing generated aliases in $GENERATED_ALIAS_FILE..."
37
38 #hmmm: perhaps a good place for a function to create the header,
39 #      given the appropriate comment code.
40
41 echo "##" >$GENERATED_ALIAS_FILE
42 echo "## generated file: $GENERATED_ALIAS_FILE" >>$GENERATED_ALIAS_FILE
43 echo "## please do not edit." >>$GENERATED_ALIAS_FILE
44 echo "##" >>$GENERATED_ALIAS_FILE
45
46 if [ ! -z "$test_color" ]; then
47   echo "color_add=--color=auto" >>$GENERATED_ALIAS_FILE
48 else
49   echo "color_add=" >>$GENERATED_ALIAS_FILE
50 fi
51
52 # plow in the full set of aliases into the file.
53 for i in "${ALIAS_DEFINITION_FILES[@]}"; do
54   cat $i >>$GENERATED_ALIAS_FILE 
55 done
56
57 if [ ! -z "$SHELL_DEBUG" ]; then echo done rebuiling generated aliases file.; fi
58