summaryrefslogtreecommitdiff
path: root/examples/misc
diff options
context:
space:
mode:
Diffstat (limited to 'examples/misc')
-rwxr-xr-xexamples/misc/aliasconv.bash42
-rwxr-xr-xexamples/misc/aliasconv.sh42
-rwxr-xr-xexamples/misc/cshtobash130
-rw-r--r--examples/misc/suncmd.termcap30
4 files changed, 244 insertions, 0 deletions
diff --git a/examples/misc/aliasconv.bash b/examples/misc/aliasconv.bash
new file mode 100755
index 0000000..2245f06
--- /dev/null
+++ b/examples/misc/aliasconv.bash
@@ -0,0 +1,42 @@
+#! /bin/bash
+#
+# aliasconv.bash - convert csh aliases to bash aliases and functions
+#
+# usage: aliasconv.bash
+#
+# Chet Ramey
+# chet@po.cwru.edu
+#
+trap 'rm -f /tmp/cb$$.?' 0 1 2 3 6 15
+
+T=$'\t'
+
+cat << \EOF >/tmp/cb$$.1
+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'/" >>/tmp/cb$$.1
+
+$BASH /tmp/cb$$.1 | 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
diff --git a/examples/misc/aliasconv.sh b/examples/misc/aliasconv.sh
new file mode 100755
index 0000000..75db077
--- /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 /tmp/cb$$.?' 0 1 2 3 6 15
+
+T=' '
+
+cat << \EOF >/tmp/cb$$.1
+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'/" >>/tmp/cb$$.1
+
+sh /tmp/cb$$.1 | 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
diff --git a/examples/misc/cshtobash b/examples/misc/cshtobash
new file mode 100755
index 0000000..8e2b05c
--- /dev/null
+++ b/examples/misc/cshtobash
@@ -0,0 +1,130 @@
+#! /bin/bash
+#
+# cshtobash - convert csh aliases, environment variables, and variables to
+# bash equivalents
+#
+# usage: cshtobash [filename]
+#
+# If filename is given, that file is sourced. Note that csh always
+# sources .cshrc. To recreate your csh login environment, run
+# `cshtobash ~/.login'.
+#
+# Inspired by (and some borrowed from) a similar program distributed with
+# zsh-3.0.
+#
+# Chet Ramey
+# chet@po.cwru.edu
+#
+trap 'rm -f /tmp/cb$$.? cshout cshin' 0 1 2 3 6 15
+
+T=$'\t'
+
+SOURCE="${1:+source $1}"
+
+cat << EOF >cshin
+$SOURCE
+alias >! /tmp/cb$$.a
+setenv >! /tmp/cb$$.e
+set >! /tmp/cb$$.v
+EOF
+
+# give csh a minimal environment, similar to what login would provide
+/usr/bin/env - USER=$USER HOME=$HOME PATH=/usr/bin:/bin:/usr/ucb:. TERM=$TERM SHELL=$SHELL /bin/csh -i < ./cshin > cshout 2>&1
+
+# First convert aliases
+
+cat << \EOF >/tmp/cb$$.1
+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
+
+sed "s/^\([a-zA-Z0-9_]*\)$T\(.*\)$/mkalias \1 '\2'/" < /tmp/cb$$.a >>/tmp/cb$$.1
+
+echo '# csh aliases'
+echo
+
+$BASH /tmp/cb$$.1 | 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'
+
+# Next, convert environment variables
+echo
+echo '# csh environment variables'
+echo
+
+# Would be nice to deal with embedded newlines, e.g. in TERMCAP, but ...
+sed -e '/^SHLVL/d' \
+ -e '/^PWD/d' \
+ -e "s/'/'"\\\\"''"/g \
+ -e "s/^\([A-Za-z0-9_]*=\)/export \1'/" \
+ -e "s/$/'/" < /tmp/cb$$.e
+
+# Finally, convert local variables
+echo
+echo '# csh variables'
+echo
+
+sed -e 's/'"$T"'/=/' \
+ -e "s/'/'"\\\\"''"/g \
+ -e '/^[A-Za-z0-9_]*=[^(]/{
+ s/=/='"'/"'
+ s/$/'"'/"'
+ }' < /tmp/cb$$.v |
+sed -e '/^argv=/d' -e '/^cwd=/d' -e '/^filec=/d' -e '/^status=/d' \
+ -e '/^verbose=/d' \
+ -e '/^term=/d' \
+ -e '/^home=/d' \
+ -e '/^path=/d' \
+ -e '/^user=/d' \
+ -e '/^shell=/d' \
+ -e '/^cdpath=/d' \
+ -e '/^mail=/d' \
+ -e '/^home=/s//HOME=/' \
+ -e '/^prompt=/s//PS1=/' \
+ -e '/^histfile=/s//HISTFILE=/' \
+ -e '/^history=/s//HISTSIZE=/' \
+ -e '/^savehist=$/s//HISTFILESIZE=${HISTSIZE-500}/' \
+ -e '/^savehist=/s//HISTFILESIZE=/' \
+ -e '/^ignoreeof=$/s/^.*$/set -o ignoreeof # ignoreeof/' \
+ -e '/^ignoreeof=/s//IGNOREEOF=/' \
+ -e '/^noclobber=/s/^.*$/set -C # noclobber/' \
+ -e '/^notify=/s/^.*$/set -b # notify/' \
+ -e '/^noglob=/s/^.*$/set -f # noglob/' \
+
+
+# now some special csh variables converted to bash equivalents
+echo
+echo '# special csh variables converted to bash equivalents'
+echo
+
+sed -e 's/'"$T"'/=/' < /tmp/cb$$.v |
+grep "^cdpath=" |
+sed 's/(//
+ s/ /:/g
+ s/)//
+ s/cdpath=/CDPATH=/'
+
+
+sed -e 's/'"$T"'/=/' < /tmp/cb$$.v |
+grep "^mail=" |
+sed 's/(//
+ s/ /:/g
+ s/)//
+ s/mail=/MAILPATH=/' |
+sed -e 's/MAILPATH=\([0-9][0-9][^:]*\)$/MAILCHECK=\1/' \
+ -e 's/MAILPATH=\([0-9][0-9][^:]*\):\(.*\)/MAILCHECK=\1 MAILPATH=\2/'
+
+exit 0
diff --git a/examples/misc/suncmd.termcap b/examples/misc/suncmd.termcap
new file mode 100644
index 0000000..c3422fb
--- /dev/null
+++ b/examples/misc/suncmd.termcap
@@ -0,0 +1,30 @@
+#Posted-Date: Fri, 9 Mar 90 18:34:29 EST
+#Date: Fri, 9 Mar 90 18:34:29 EST
+#From: "Eirik Fuller" <wonton.tn.cornell.edu!eirik@ucsbcsl.UUCP>
+#To: bfox@ai.mit.edu (Brian Fox)
+#Subject: Patch to bash 1.05 for SunView
+#
+#I think this works:
+#
+Mu|sun-cmd:am:bs:km:pt:li#34:co#80:cl=^L:ce=\E[K:cd=\E[J:rs=\E[s:
+#
+#Another alternative is to send the ti string at startup time (and, I
+#guess, the te string at exit time); that is how vi works in a cmdtool.
+#The best reason to not do this is that this also disables scrolling
+#which, as I understand it, is why anyone would use cmdtool in the
+#first place. Sending the ti string at startup time would do strange
+#things on other systems too; in xterm it would use the alternate
+#screen.
+#
+#The problem with cmdtool, in case that is less than obvious, is that
+#almost none of the capabilities advertised in /etc/termcap are enabled
+#while scrolling is enabled. It has other problems too, like being
+#part of an outdated proprietary windowing system, but there's probably
+#no need to dwell on that. In a sense, though, the sun-cmd termcap
+#entry doesn't lie about the capabilities; I think the termcap man page
+#does warn about some terminals having cursor motion capabilities only
+#in the "ti/te window".
+#
+#A general solution to this problem would require a termcap capability
+#which somehow tells which features are available outside of the ti/te
+#window. There is no such capability in termcap now, of course.