summaryrefslogtreecommitdiffstats
path: root/examples/misc/aliasconv.sh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:38:56 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:38:56 +0000
commit6c20c8ed2cb9ab69a1a57ccb2b9b79969a808321 (patch)
treef63ce19d57fad3ac4a15bc26dbfbfa2b834111b5 /examples/misc/aliasconv.sh
parentInitial commit. (diff)
downloadbash-6c20c8ed2cb9ab69a1a57ccb2b9b79969a808321.tar.xz
bash-6c20c8ed2cb9ab69a1a57ccb2b9b79969a808321.zip
Adding upstream version 5.2.15.upstream/5.2.15upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'examples/misc/aliasconv.sh')
-rw-r--r--examples/misc/aliasconv.sh42
1 files changed, 42 insertions, 0 deletions
diff --git a/examples/misc/aliasconv.sh b/examples/misc/aliasconv.sh
new file mode 100644
index 0000000..fe975d6
--- /dev/null
+++ b/examples/misc/aliasconv.sh
@@ -0,0 +1,42 @@
+#! /bin/bash
+#
+# aliasconv.sh - convert csh aliases to bash aliases and functions
+#
+# usage: aliasconv.sh
+#
+# Chet Ramey
+# chet@po.cwru.edu
+#
+trap 'rm -f $TMPFILE' 0 1 2 3 6 15
+TMPFILE=$(mktemp -t cb.XXXXXX) || exit 1
+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:':'\\\\\\\\'':"`\' ;;
+ 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
+
+sh $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