📄 cshtobash
字号:
#! /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 15T=$'\t'SOURCE="${1:+source $1}"cat << EOF >cshin$SOURCEalias >! /tmp/cb$$.asetenv >! /tmp/cb$$.eset >! /tmp/cb$$.vEOF# 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 aliasescat << \EOF >/tmp/cb$$.1mkalias (){ if [ -z "$2" ]; then echo alias ${1}="''" elif echo "$2" | egrep -s '(\!|#)' >/dev/null 2>&1; then comm=$(echo $2 | sed 's/\!\*/"$\@"/g s/\!:\([1-9]\)/"$\1"/g s/#/\#/g') echo $1 \(\) "{" command "$comm" "; }" else echo alias ${1}=\'$(echo "${2}" | sed "s:':'\\\\'':")\' fi}EOFsed "s/^\([a-zA-Z0-9_]*\)$T\(.*\)$/mkalias \1 '\2'/" < /tmp/cb$$.a >>/tmp/cb$$.1echo '# 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 variablesechoecho '# 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 variablesechoecho '# csh variables'echosed -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 equivalentsechoecho '# special csh variables converted to bash equivalents'echosed -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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -