first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / scripts / core / unter_alia.sh
1 #!/bin/bash
2
3 # generates alias files for different operating systems and shell scripts.
4 #
5 # This script generates command alias definitions for a variety of different
6 # shells.  The "common_aliases.txt" file is used in all of the generated
7 # files as a base set of generally useful aliases.  Then the appropriate
8 # shell's specific aliases are added in; these are named after the shell that
9 # they support, e.g. "sh_aliases.txt" is used with the sh and bash shells.
10 # The third component of the file is a set of aliases generated automatically
11 # from the names of all the shell scripts in SHELLDIR.
12 #
13 # Additionally, if a file named "c_common_aliases.txt" is found in the
14 # $SHELLDIR/custom directory, then it is added in after the other alias files
15 # and can override any existing aliases or provide additional local aliases.
16 # This file is not included with the YETIcode scripts, since it is intended
17 # to be provided by individual users.
18 #
19 # Further, if any other shell-specific alias files are found mirrored under
20 # the custom folder, they are pulled in as overrides for that kind of shell.
21 # For example, there is a sh_aliases.txt in the scripts directory for sh,
22 # but if there's also scripts/custom/c_sh_aliases.txt, then that will be
23 # plugged in as well.
24
25 # create our generated shells directory if it's not already.
26 if [ ! -d $GENERADIR ]; then mkdir $GENERADIR; fi
27
28 # test if we can use color in ls...
29 test_color=$(ls --help 2>&1 | grep -i color)
30
31 export COMMON_FILES=$SHELLDIR/core/common_aliases.txt
32 if [ -f "$SHELLDIR/custom/c_common_aliases.txt" ]; then
33   # if the custom aliases file exists, add it to the list.
34   export COMMON_FILES="$COMMON_FILES $SHELLDIR/custom/c_common_aliases.txt"
35 fi
36 #echo common files is... $COMMON_FILES
37
38 # write the aliases for sh and bash scripts.
39
40 export ALIASES_FILE="$GENERADIR/aliases.sh"
41 echo "writing $ALIASES_FILE..."
42
43 #hmmm: perhaps a good place for a function to create the header,
44 #      given the appropriate comment code.
45
46 echo "##" >$ALIASES_FILE
47 echo "## generated file: $ALIASES_FILE" >>$ALIASES_FILE
48 echo "## please do not edit." >>$ALIASES_FILE
49 echo "##" >>$ALIASES_FILE
50
51 if [ ! -z "$test_color" ]; then
52   echo "color_add=--color=auto" >>$ALIASES_FILE
53 else
54   echo "color_add=" >>$ALIASES_FILE
55 fi
56
57 # we process the alias file to add the word "alias" to the first of every
58 # line that's not a comment.
59 cat $COMMON_FILES | sed -e 's/^\([^#]\)/alias \1/' >>$ALIASES_FILE 
60 echo "##" >>$ALIASES_FILE
61 echo "## now including shell specific additions..." >>$ALIASES_FILE
62 echo "##" >>$ALIASES_FILE
63 # then just dump the sh specific alias stuff into the file.
64 cat $SHELLDIR/core/sh_aliases.txt >>$ALIASES_FILE 
65 # add in customized sh aliases if they exist.
66 if [ -f "$SHELLDIR/custom/c_sh_aliases.txt" ]; then
67   cat $SHELLDIR/custom/c_sh_aliases.txt >>$ALIASES_FILE 
68 fi
69
70 exit 0;
71