i-bash/examples/misc/aliasconv.bash

45 lines
981 B
Bash
Raw Normal View History

1996-12-23 17:02:34 +00:00
#! /bin/bash
#
1999-02-19 17:11:39 +00:00
# aliasconv.bash - convert csh aliases to bash aliases and functions
1996-12-23 17:02:34 +00:00
#
1999-02-19 17:11:39 +00:00
# usage: aliasconv.bash
1996-12-23 17:02:34 +00:00
#
# Chet Ramey
# chet@po.cwru.edu
#
2011-11-21 20:51:19 -05:00
trap 'rm -f $TMPFILE' 0 1 2 3 6 15
TMPFILE=$(mktemp -t cb.XXXXXX) || exit 1
1996-12-23 17:02:34 +00:00
T=$'\t'
2011-11-21 20:51:19 -05:00
cat << \EOF >$TMPFILE
1996-12-23 17:02:34 +00:00
mkalias ()
{
2004-07-27 13:29:18 +00:00
case $2 in
'') echo alias ${1}="''" ;;
*[#\!]*)
1996-12-23 17:02:34 +00:00
comm=$(echo $2 | sed 's/\!\*/"$\@"/g
s/\!:\([1-9]\)/"$\1"/g
s/#/\#/g')
echo $1 \(\) "{" command "$comm" "; }"
2004-07-27 13:29:18 +00:00
;;
2005-12-07 14:08:12 +00:00
*) echo alias ${1}=\'$(echo "${2}" | sed "s:':'\\\\'':g")\' ;;
2004-07-27 13:29:18 +00:00
esac
1996-12-23 17:02:34 +00:00
}
EOF
1999-02-19 17:11:39 +00:00
# the first thing we want to do is to protect single quotes in the alias,
# since they whole thing is going to be surrounded by single quotes when
# passed to mkalias
2011-11-21 20:51:19 -05:00
sed -e "s:':\\'\\\'\\':" -e "s/^\([a-zA-Z0-9_-]*\)$T\(.*\)$/mkalias \1 '\2'/" >>$TMPFILE
1996-12-23 17:02:34 +00:00
2011-11-21 20:51:19 -05:00
$BASH $TMPFILE | sed -e 's/\$cwd/\$PWD/g' \
1996-12-23 17:02:34 +00:00
-e 's/\$term/\$TERM/g' \
-e 's/\$home/\$HOME/g' \
-e 's/\$user/\$USER/g' \
-e 's/\$prompt/\$PS1/g'
exit 0