Yippie-Kay-Yay Micro$oft SFU !!!

Test one: I wonder if Console is a decent replacement for cmd.exe ‘s terminal emulator — It is

Test two: I wonder if the SFU pdksh can do completion? — It can, just had to find the ‘bind’ commands for it

Test three: I wonder if SFU’s pdksh will work with my %PATH% — it did

Problem one: SFU pdksh seems to require the formal name, e.g. ‘foo.exe’ for programs outside of it’s regular path and runwin32’s search path — That’s ok, I don’t mind much and can alias out stuff like flock.

Problem two: Because SFU follows the unix-style of open it, see if there is a she-bang line (e.g. #!/bin/sh) saying what to run it with, else pass it on to the shell…. It feeds .bat files into it’s pdksh unless they are manually executed, e.g. ‘runwin32 cmd /C foo.bat’ — that is bad, several programs I use wrap themselves in ‘batch’ files on Windows and ‘shell’ scripts on Unix.

Problem three: My universal bourne-based shrc (~/.${USER}_shrc) sets itself to the current Bourne-style shell (e.g. sh, bash, ksh-family, zsh) and Operating System (e.g. BSD, Linux, generic Unix) needs to inspect the $SHELL environment variable to determin what shell to set stuff for. — For some odd reason the SFU pdksh doesn’t seem to set SHELL !!!! To top it off, $USER is not set, but at least the Windows var: %USERNAME% is converted to $USERNAME.

Fix for problem one:

$ mkdir /dev/fs/P/bin      # creates P:bin
$ touch binmaker.sh && chmod +x binmaker.sh
$ vi binmaker.sh
#!/bin/sh
BINDIR=/dev/fs/P/bin

for CMD in `echo $PATH | sed 's/:/ /g' | awk '{ print $0 }'`
do
for EXE in `ls $CMD`; do
echo $EXE | grep -E '.*.exe$' > /dev/null &&
ln -s ${CMD}/${EXE} ${BINDIR}/`echo $EXE | sed 's/.exe$//g'` && echo "made link for: ${CMD}/$EXE"
done
done

$ ./binmaker.sh
.... # symlinks all foo.exe in $PATH to /dev/fs/P/bin/foo

Fix for problem two:

Launch a new session of cmd.exe through windows (e.g. not via SFU; use the run dialog, start menu, or desktop /or quicklaunch icon).

U:Terry> echo %PATH% > mypath.win

Return to SFU korn shell (pdksh):

$ touch batmaker.sh && chmod +x batmaker.sh
$ vi batmaker.sh

#!/bin/sh
BINDIR=/dev/fs/P/bin

make_wrapper() {
[ -e $2 ] && return # file exists, no wrapper needed
local MYFILE=`basename $2`
cd $BINDIR && [ ! -e $MYFILE ] && touch $MYFILE

echo '#/bin/sh' >> $MYFILE
echo 'exec cmd /C "set PATH=`cat ~/mypath.win` && `basename $0`"' >> $MYFILE

echo "${BINDIR}/$MYFILE created"
}

for CMD in `echo $PATH | sed 's/:/ /g' | awk '{ print $0 }'`
do
for EXE in `ls $CMD`; do
echo $EXE | grep -E '.*.bat$' > /dev/null &&
make_wrapper ${CMD}/${EXE} "${BINDIR}/`echo $EXE | sed 's/.bat$//g'`"
done
done

$ ./batmaker.sh
... makes wrapper shell scripts in /dev/fs/P/bin/ for all foo.bat in $PATH

The wrapper scripts this creates look like this:

Terry@SAL1600-$ cat bin/irb
#/bin/sh

exec cmd /C "set PATH=`cat ~/mypath.win` && `basename $0`"

Terry@SAL1600-$

it’s neccessary to set the Windows %PATH% before launch, so it can execute the program — using the path from the invocation environment won’t work, e.g. /dev/fs/P/Devel/Langauges/Ruby/bin/irb in SFU Shells but this woudl translate to CurrentDriveLetter:dev/fs/P/Devel/Langauges/Ruby/bin/irb which won’t work. Note, the program must be executed as P:DevelLanguagesRubybinirb.bat in Windows cmd shell, as that is where it is located on my system.

Fix for problem three:

I modified my ~/.profile from OpenBSD to take care of the $USER and $SHELL issues, which is also nice enough to load my custom initialization file.

$ vi .profile

export TERM HOME
USER=$USERNAME; export USER
SHELL="/dev/fs/P/Utilities/Services_For_UNIX/bin/ksh"; export SHELL

echo "Waiting for screen repaint...."
sleep 2
echo 'Korn power !!!'

ENV=${HOME}/.${USER}_shrc

I set the path to the physical rather then the /bin/ksh ‘shorty’ in SFU, so that if I later find any compatibility issues, I can always work around it ‘specifically’ if necessary.

I’m not sure if it is a problem with the Console2-Devel build I’ve installed or with how SFU’s korn shell expects to run. But a few seconds after startup the prompt disappears as if from a ‘clear’, giving any I/O that results in a line being drawn causes a fix. Since I haven’t figured this part out yet, I’ve just ‘side stepped’ the problem. It takes roughly the amount of time to sleep and echo the message before I am returned to my prompt. A quick parse of my $ENV and we’re ready to rock and all the output on the Console tab is from my ${USER}_shrc file.

I copied an old version of initialization file and made a quick edit. In the file I check for the systems unix name and use it to record the operating system type. The Services For UNIX subsystem still identifies itself as ‘Interix’ even though it’s been under Microsoft’s thumb for a bit.


case `uname -s` in
'FreeBSD') isFreeBSD=1
LSCOLORS='CxGxxxxxBxexExcxdx'; export LSCOLORS
;; # FreeBSD
'OpenBSD') isOpenBSD=1;;
'NetBSD') isNetBSD=1;;
'Linux') isLinux=1;;
'Unix') isUnix=1;;
'Interix') isUnix=1;isSFU=1;;
esac

I want to make a few changes to my shrc, but I don’t think they will work *properly* with SFU. My shrc file also pulls in a local ‘extension’ of itself, called ~/.site_shrc that makes things specific to the current system, for example adding the TexLive binaries to my $PATH on FreeBSD and noting the IP address or doing things that won’t work in the shells/v7sh that I use for testing. It looks like I’m going to have to write a site_shrc for Windows hahaha !!!

There’s more then one way to skin a cat, and this bloody hoge-podge of an operating system ain’t gonna best me !!! I will have a decent CLI interface if I’ve got to invoke a hex editor…