Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 1 | #! /bin/bash |
| 2 | # |
Jari Aalto | b72432f | 1999-02-19 17:11:39 +0000 | [diff] [blame] | 3 | # aliasconv.bash - convert csh aliases to bash aliases and functions |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 4 | # |
Jari Aalto | b72432f | 1999-02-19 17:11:39 +0000 | [diff] [blame] | 5 | # usage: aliasconv.bash |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 6 | # |
| 7 | # Chet Ramey |
| 8 | # chet@po.cwru.edu |
| 9 | # |
Chet Ramey | 0001803 | 2011-11-21 20:51:19 -0500 | [diff] [blame] | 10 | trap 'rm -f $TMPFILE' 0 1 2 3 6 15 |
| 11 | |
| 12 | TMPFILE=$(mktemp -t cb.XXXXXX) || exit 1 |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 13 | |
| 14 | T=$'\t' |
| 15 | |
Chet Ramey | 0001803 | 2011-11-21 20:51:19 -0500 | [diff] [blame] | 16 | cat << \EOF >$TMPFILE |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 17 | mkalias () |
| 18 | { |
Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 19 | case $2 in |
| 20 | '') echo alias ${1}="''" ;; |
| 21 | *[#\!]*) |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 22 | comm=$(echo $2 | sed 's/\!\*/"$\@"/g |
| 23 | s/\!:\([1-9]\)/"$\1"/g |
| 24 | s/#/\#/g') |
| 25 | echo $1 \(\) "{" command "$comm" "; }" |
Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 26 | ;; |
Jari Aalto | 95732b4 | 2005-12-07 14:08:12 +0000 | [diff] [blame] | 27 | *) echo alias ${1}=\'$(echo "${2}" | sed "s:':'\\\\'':g")\' ;; |
Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 28 | esac |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 29 | } |
| 30 | EOF |
| 31 | |
Jari Aalto | b72432f | 1999-02-19 17:11:39 +0000 | [diff] [blame] | 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 | |
Chet Ramey | 0001803 | 2011-11-21 20:51:19 -0500 | [diff] [blame] | 36 | sed -e "s:':\\'\\\'\\':" -e "s/^\([a-zA-Z0-9_-]*\)$T\(.*\)$/mkalias \1 '\2'/" >>$TMPFILE |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 37 | |
Chet Ramey | 0001803 | 2011-11-21 20:51:19 -0500 | [diff] [blame] | 38 | $BASH $TMPFILE | sed -e 's/\$cwd/\$PWD/g' \ |
Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 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 |