blob: fe975d66f1a3bf5ae2d4883aefe11fd4a827e493 [file] [log] [blame]
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001#! /bin/bash
2#
Jari Aaltob72432f1999-02-19 17:11:39 +00003# aliasconv.sh - 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.sh
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
11TMPFILE=$(mktemp -t cb.XXXXXX) || exit 1
Jari Aaltoccc6cda1996-12-23 17:02:34 +000012T=' '
13
Chet Ramey00018032011-11-21 20:51:19 -050014cat << \EOF >$TMPFILE
Jari Aaltoccc6cda1996-12-23 17:02:34 +000015mkalias ()
16{
Jari Aaltob80f6442004-07-27 13:29:18 +000017 case $2 in
18 '') echo alias ${1}="''" ;;
19 *[#\!]*)
Jari Aaltoccc6cda1996-12-23 17:02:34 +000020 comm=`echo $2 | sed 's/\\!\*/"$\@"/g
21 s/\\!:\([1-9]\)/"$\1"/g
22 s/#/\#/g'`
23 echo $1 \(\) "{" command "$comm" "; }"
Jari Aaltob80f6442004-07-27 13:29:18 +000024 ;;
25 *) echo alias ${1}=\'`echo "${2}" | sed "s:':'\\\\\\\\'':"`\' ;;
26 esac
Jari Aaltoccc6cda1996-12-23 17:02:34 +000027}
28EOF
29
Jari Aaltob72432f1999-02-19 17:11:39 +000030# 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
Chet Ramey00018032011-11-21 20:51:19 -050034sed -e "s:':\\'\\\'\\':" -e "s/^\([a-zA-Z0-9_-]*\)$T\(.*\)$/mkalias \1 '\2'/" >>$TMPFILE
Jari Aaltoccc6cda1996-12-23 17:02:34 +000035
Chet Ramey00018032011-11-21 20:51:19 -050036sh $TMPFILE | sed -e 's/\$cwd/\$PWD/g' \
Jari Aaltoccc6cda1996-12-23 17:02:34 +000037 -e 's/\$term/\$TERM/g' \
38 -e 's/\$home/\$HOME/g' \
39 -e 's/\$user/\$USER/g' \
40 -e 's/\$prompt/\$PS1/g'
41
42exit 0