3 # cshtobash - convert csh aliases, environment variables, and variables to
6 # usage: cshtobash [filename]
8 # If filename is given, that file is sourced. Note that csh always
9 # sources .cshrc. To recreate your csh login environment, run
10 # `cshtobash ~/.login'.
12 # Inspired by (and some borrowed from) a similar program distributed with
18 trap 'rm -f /tmp/cb$$.? cshout cshin' 0 1 2 3 6 15
22 SOURCE="${1:+source $1}"
31 # give csh a minimal environment, similar to what login would provide
32 /usr/bin/env - USER=$USER HOME=$HOME PATH=/usr/bin:/bin:/usr/ucb:. TERM=$TERM SHELL=$SHELL /bin/csh -i < ./cshin > cshout 2>&1
34 # First convert aliases
36 cat << \EOF >/tmp/cb$$.1
40 '') echo alias ${1}="''" ;;
42 comm=$(echo $2 | sed 's/\!\*/"$\@"/g
43 s/\!:\([1-9]\)/"$\1"/g
45 echo $1 \(\) "{" command "$comm" "; }"
47 *) echo alias ${1}=\'$(echo "${2}" | sed "s:':'\\\\'':")\' ;;
52 sed "s/^\([a-zA-Z0-9_]*\)$T\(.*\)$/mkalias \1 '\2'/" < /tmp/cb$$.a >>/tmp/cb$$.1
57 $BASH /tmp/cb$$.1 | sed -e 's/\$cwd/\$PWD/g' \
58 -e 's/\$term/\$TERM/g' \
59 -e 's/\$home/\$HOME/g' \
60 -e 's/\$user/\$USER/g' \
61 -e 's/\$prompt/\$PS1/g'
63 # Next, convert environment variables
65 echo '# csh environment variables'
68 # Would be nice to deal with embedded newlines, e.g. in TERMCAP, but ...
71 -e "s/'/'"\\\\"''"/g \
72 -e "s/^\([A-Za-z0-9_]*=\)/export \1'/" \
73 -e "s/$/'/" < /tmp/cb$$.e
75 # Finally, convert local variables
77 echo '# csh variables'
80 sed -e 's/'"$T"'/=/' \
81 -e "s/'/'"\\\\"''"/g \
82 -e '/^[A-Za-z0-9_]*=[^(]/{
86 sed -e '/^argv=/d' -e '/^cwd=/d' -e '/^filec=/d' -e '/^status=/d' \
95 -e '/^home=/s//HOME=/' \
96 -e '/^prompt=/s//PS1=/' \
97 -e '/^histfile=/s//HISTFILE=/' \
98 -e '/^history=/s//HISTSIZE=/' \
99 -e '/^savehist=$/s//HISTFILESIZE=${HISTSIZE-500}/' \
100 -e '/^savehist=/s//HISTFILESIZE=/' \
101 -e '/^ignoreeof=$/s/^.*$/set -o ignoreeof # ignoreeof/' \
102 -e '/^ignoreeof=/s//IGNOREEOF=/' \
103 -e '/^noclobber=/s/^.*$/set -C # noclobber/' \
104 -e '/^notify=/s/^.*$/set -b # notify/' \
105 -e '/^noglob=/s/^.*$/set -f # noglob/' \
108 # now some special csh variables converted to bash equivalents
110 echo '# special csh variables converted to bash equivalents'
113 sed -e 's/'"$T"'/=/' < /tmp/cb$$.v |
121 sed -e 's/'"$T"'/=/' < /tmp/cb$$.v |
126 s/mail=/MAILPATH=/' |
127 sed -e 's/MAILPATH=\([0-9][0-9][^:]*\)$/MAILCHECK=\1/' \
128 -e 's/MAILPATH=\([0-9][0-9][^:]*\):\(.*\)/MAILCHECK=\1 MAILPATH=\2/'