blob: 22a0447242c53aad513401137f6e4901c814a999 [file] [log] [blame]
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001#! /bin/bash
2#
Jari Aaltob72432f1999-02-19 17:11:39 +00003# aliasconv.bash - convert csh aliases to bash aliases and functions
Jari Aaltoccc6cda1996-12-23 17:02:34 +00004#
Jari Aaltob72432f1999-02-19 17:11:39 +00005# usage: aliasconv.bash
Jari Aaltoccc6cda1996-12-23 17:02:34 +00006#
7# Chet Ramey
8# chet@po.cwru.edu
9#
Chet Ramey00018032011-11-21 20:51:19 -050010trap 'rm -f $TMPFILE' 0 1 2 3 6 15
11
12TMPFILE=$(mktemp -t cb.XXXXXX) || exit 1
Jari Aaltoccc6cda1996-12-23 17:02:34 +000013
14T=$'\t'
15
Chet Ramey00018032011-11-21 20:51:19 -050016cat << \EOF >$TMPFILE
Jari Aaltoccc6cda1996-12-23 17:02:34 +000017mkalias ()
18{
Jari Aaltob80f6442004-07-27 13:29:18 +000019 case $2 in
20 '') echo alias ${1}="''" ;;
21 *[#\!]*)
Jari Aaltoccc6cda1996-12-23 17:02:34 +000022 comm=$(echo $2 | sed 's/\!\*/"$\@"/g
23 s/\!:\([1-9]\)/"$\1"/g
24 s/#/\#/g')
25 echo $1 \(\) "{" command "$comm" "; }"
Jari Aaltob80f6442004-07-27 13:29:18 +000026 ;;
Jari Aalto95732b42005-12-07 14:08:12 +000027 *) echo alias ${1}=\'$(echo "${2}" | sed "s:':'\\\\'':g")\' ;;
Jari Aaltob80f6442004-07-27 13:29:18 +000028 esac
Jari Aaltoccc6cda1996-12-23 17:02:34 +000029}
30EOF
31
Jari Aaltob72432f1999-02-19 17:11:39 +000032# 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 Ramey00018032011-11-21 20:51:19 -050036sed -e "s:':\\'\\\'\\':" -e "s/^\([a-zA-Z0-9_-]*\)$T\(.*\)$/mkalias \1 '\2'/" >>$TMPFILE
Jari Aaltoccc6cda1996-12-23 17:02:34 +000037
Chet Ramey00018032011-11-21 20:51:19 -050038$BASH $TMPFILE | sed -e 's/\$cwd/\$PWD/g' \
Jari Aaltoccc6cda1996-12-23 17:02:34 +000039 -e 's/\$term/\$TERM/g' \
40 -e 's/\$home/\$HOME/g' \
41 -e 's/\$user/\$USER/g' \
42 -e 's/\$prompt/\$PS1/g'
43
44exit 0