summaryrefslogtreecommitdiffstats
path: root/examples/misc/aliasconv.bash
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 18:33:23 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 18:33:23 +0000
commit1d5cace9db9aef76f26b2d7ba54bbb76443b00b2 (patch)
tree314a15dd1aa103da13bdc83ba1d2105a290bc5ba /examples/misc/aliasconv.bash
parentInitial commit. (diff)
downloadbash-upstream.tar.xz
bash-upstream.zip
Adding upstream version 5.0.upstream/5.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-xexamples/misc/aliasconv.bash44
1 files changed, 44 insertions, 0 deletions
diff --git a/examples/misc/aliasconv.bash b/examples/misc/aliasconv.bash
new file mode 100755
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