43c414cb5a26d1dc412db640f2cd218cf368ceb1
[feisty_meow.git] / scripts / core / unter_alia.sh
1 #!/bin/bash
2
3 # generates alias files for different operating systems and shell scripts.
4 # or really, mainly for bash these days, on linux.  but we also run under
5 # msys and cygwin to some degree.
6 #
7 # The "common.alias" file is used in the generated aliases file as a base
8 # set of generally useful aliases.  Shorter aliases based on any scripts
9 # we can find in the feisty meow script hierarchy are added in as well.
10 #
11 # If any other alias files are found in the scripts/custom folder, they
12 # are pulled in as additions and overrides for the basic feisty meow command
13 # set.
14
15 if [ ! -z "$SHELL_DEBUG" ]; then echo rebuiling generated aliases file...; fi
16
17 # create our generated shells directory if it's not already.
18 if [ ! -d $FEISTY_MEOW_GENERATED ]; then mkdir $FEISTY_MEOW_GENERATED; fi
19
20 # test if we can use color in ls...
21 test_color=$(ls --help 2>&1 | grep -i color)
22
23 ALIAS_DEFINITION_FILES=("$FEISTY_MEOW_SCRIPTS/core/common.alias")
24 # if custom aliases files exist, add them to the list.
25 for i in "$FEISTY_MEOW_SCRIPTS/custom/*.alias"; do
26 echo adding $i
27   ALIAS_DEFINITION_FILES+=("$i")
28 done
29 echo "alias files:"
30 for i in "${ALIAS_DEFINITION_FILES[@]}"; do
31   echo "  $(basename $(dirname $i))/$(basename $i)"
32 done
33
34 # write the aliases for sh and bash scripts.
35
36 GENERATED_ALIAS_FILE="$FEISTY_MEOW_GENERATED/aliases.sh"
37 echo "writing $GENERATED_ALIAS_FILE..."
38
39 #hmmm: perhaps a good place for a function to create the header,
40 #      given the appropriate comment code.
41
42 echo "##" >$GENERATED_ALIAS_FILE
43 echo "## generated file: $GENERATED_ALIAS_FILE" >>$GENERATED_ALIAS_FILE
44 echo "## please do not edit." >>$GENERATED_ALIAS_FILE
45 echo "##" >>$GENERATED_ALIAS_FILE
46
47 if [ ! -z "$test_color" ]; then
48   echo "color_add=--color=auto" >>$GENERATED_ALIAS_FILE
49 else
50   echo "color_add=" >>$GENERATED_ALIAS_FILE
51 fi
52
53 # plow in the full set of aliases into the file.
54 for i in "${ALIAS_DEFINITION_FILES[@]}"; do
55   cat $i >>$GENERATED_ALIAS_FILE 
56 done
57
58 if [ ! -z "$SHELL_DEBUG" ]; then echo done rebuiling generated aliases file.; fi
59