From 6c20c8ed2cb9ab69a1a57ccb2b9b79969a808321 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 17:38:56 +0200 Subject: Adding upstream version 5.2.15. Signed-off-by: Daniel Baumann --- examples/misc/aliasconv.bash | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 examples/misc/aliasconv.bash (limited to 'examples/misc/aliasconv.bash') diff --git a/examples/misc/aliasconv.bash b/examples/misc/aliasconv.bash new file mode 100644 index 0000000..22a0447 --- /dev/null +++ b/examples/misc/aliasconv.bash @@ -0,0 +1,44 @@ +#! /bin/bash +# +# aliasconv.bash - convert csh aliases to bash aliases and functions +# +# usage: aliasconv.bash +# +# Chet Ramey +# chet@po.cwru.edu +# +trap 'rm -f $TMPFILE' 0 1 2 3 6 15 + +TMPFILE=$(mktemp -t cb.XXXXXX) || exit 1 + +T=$'\t' + +cat << \EOF >$TMPFILE +mkalias () +{ + case $2 in + '') echo alias ${1}="''" ;; + *[#\!]*) + comm=$(echo $2 | sed 's/\!\*/"$\@"/g + s/\!:\([1-9]\)/"$\1"/g + s/#/\#/g') + echo $1 \(\) "{" command "$comm" "; }" + ;; + *) echo alias ${1}=\'$(echo "${2}" | sed "s:':'\\\\'':g")\' ;; + esac +} +EOF + +# 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 + +sed -e "s:':\\'\\\'\\':" -e "s/^\([a-zA-Z0-9_-]*\)$T\(.*\)$/mkalias \1 '\2'/" >>$TMPFILE + +$BASH $TMPFILE | sed -e 's/\$cwd/\$PWD/g' \ + -e 's/\$term/\$TERM/g' \ + -e 's/\$home/\$HOME/g' \ + -e 's/\$user/\$USER/g' \ + -e 's/\$prompt/\$PS1/g' + +exit 0 -- cgit v1.2.3