]> git.ipfire.org Git - thirdparty/bash.git/blob - examples/misc/aliasconv.bash
Bash-4.1 distribution source
[thirdparty/bash.git] / examples / misc / aliasconv.bash
1 #! /bin/bash
2 #
3 # aliasconv.bash - convert csh aliases to bash aliases and functions
4 #
5 # usage: aliasconv.bash
6 #
7 # Chet Ramey
8 # chet@po.cwru.edu
9 #
10 trap 'rm -f $TMPFILE' 0 1 2 3 6 15
11
12 TMPFILE=$(mktemp -t cb.XXXXXX) || exit 1
13
14 T=$'\t'
15
16 cat << \EOF >$TMPFILE
17 mkalias ()
18 {
19 case $2 in
20 '') echo alias ${1}="''" ;;
21 *[#\!]*)
22 comm=$(echo $2 | sed 's/\!\*/"$\@"/g
23 s/\!:\([1-9]\)/"$\1"/g
24 s/#/\#/g')
25 echo $1 \(\) "{" command "$comm" "; }"
26 ;;
27 *) echo alias ${1}=\'$(echo "${2}" | sed "s:':'\\\\'':g")\' ;;
28 esac
29 }
30 EOF
31
32 # the first thing we want to do is to protect single quotes in the alias,
33 # since they whole thing is going to be surrounded by single quotes when
34 # passed to mkalias
35
36 sed -e "s:':\\'\\\'\\':" -e "s/^\([a-zA-Z0-9_-]*\)$T\(.*\)$/mkalias \1 '\2'/" >>$TMPFILE
37
38 $BASH $TMPFILE | sed -e 's/\$cwd/\$PWD/g' \
39 -e 's/\$term/\$TERM/g' \
40 -e 's/\$home/\$HOME/g' \
41 -e 's/\$user/\$USER/g' \
42 -e 's/\$prompt/\$PS1/g'
43
44 exit 0