9fa72eb1c6fef1ea1e3dae21567a6a36a586682f
[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 scripts/custom folder are loaded also.
9
10 if [ ! -z "$SHELL_DEBUG" ]; then echo rebuiling generated aliases file...; fi
11
12 # create our generated shells directory if it's not already.
13 if [ ! -d $FEISTY_MEOW_GENERATED ]; then mkdir $FEISTY_MEOW_GENERATED; fi
14
15 # test if we can use color in ls...
16 test_color=$(ls --help 2>&1 | grep -i color)
17
18 # the main one is our common alias set.
19 ALIAS_DEFINITION_FILES=("$FEISTY_MEOW_SCRIPTS/core/common.alias")
20
21 # if custom aliases files exist, add them to the list.
22 for i in "$FEISTY_MEOW_SCRIPTS/custom/*.alias"; do
23   ALIAS_DEFINITION_FILES+=("$i")
24 done
25 echo "alias files:"
26 for i in "${ALIAS_DEFINITION_FILES[@]}"; do
27   echo "  $(basename $(dirname $i))/$(basename $i)"
28 done
29
30 # write the aliases for sh and bash scripts.
31
32 GENERATED_ALIAS_FILE="$FEISTY_MEOW_GENERATED/core_and_custom_aliases.sh"
33 echo "writing generated aliases in $GENERATED_ALIAS_FILE..."
34
35 #hmmm: perhaps a good place for a function to create the header,
36 #      given the appropriate comment code.
37
38 echo "##" >$GENERATED_ALIAS_FILE
39 echo "## generated file: $GENERATED_ALIAS_FILE" >>$GENERATED_ALIAS_FILE
40 echo "## please do not edit." >>$GENERATED_ALIAS_FILE
41 echo "##" >>$GENERATED_ALIAS_FILE
42
43 if [ ! -z "$test_color" ]; then
44   echo "color_add=--color=auto" >>$GENERATED_ALIAS_FILE
45 else
46   echo "color_add=" >>$GENERATED_ALIAS_FILE
47 fi
48
49 # plow in the full set of aliases into the file.
50 for i in "${ALIAS_DEFINITION_FILES[@]}"; do
51   cat $i >>$GENERATED_ALIAS_FILE 
52 done
53
54 if [ ! -z "$SHELL_DEBUG" ]; then echo done rebuiling generated aliases file.; fi
55