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