Background: I use cygwin on win11 with its /bin in my julia PATH so I can
use the cygwin stuff from the REPL shell mode.
As I am in a mixed windows (julia and the host OS) and cygwin (the wonderful
POSIX world) I’m trying to improve the interoperability. I’ve implemented a
bash function to allow changing directory into the location represented by
a windows shell link (a.k.a. shortcut).
# This is a start at a CD routine (change directory) that can
# CD into directories represented by windows shell link files.
# Ultimately, I would like to parse the binary structure fully
# but in the interest of getting something working, I'm using
# this hack/algorithm:
#
# 1. Find strings in the *.lnk file longer than 6 characters
# containing the character '\'
#
# It should be a windows path string. Inspection suggests
# that the paths will all look like this
#
# <drive letter>:\[^A-z].*
#
# Six characters will ensure that there are at least 3 chars
# in the directory path name past the drive root
#
# 2. For each string, check if it is a directory
#
# 3. If there are multiple candidate directories, pick the
# one with the longest string pathname.
#
# 4. CD to this directory
for c in $(strings -n 6 "$1" | grep \\\\) ; do
if [ -d "$c" ]
then
echo "'$c' is a dir"
else
echo "skipping '$c'"
fi
done
It works in bash but now I want to run in in the REPL shell mode.
Is there a way to quote/escape a julia function so it can be called in shell mode?
I took a look at the REPL.jl source but couldn’t make enough sense of it to know
where to start.
One “trick” I have used is to define a julia find
set to the windows path of the
cygwin find command which lets me call cygwin find as $find
from shell mode.
julia> find = "C:\\cygwin64\\bin\\find"
"C:\\cygwin64\\bin\\find"
shell> $find . -type d -maxdepth 1
./AppData
This allows me to call the cygwin find
command from shell mode rather than
the windows system ```find``. Cygwin paths are necessarily after the win32 ones
so I don’t break the native windows operations in/by julia.
If I could call a mycd() julia function that would be great!
Is there already a way to write code to do that without toggling to julia mode?
I’ve enjoyed how you can switch to shell mode from either julia mode
or pkg mode by typing a ;
. Would it be possible to allow toggling from
shell mode to pkg mode by typing a ]
as the first character?
It seems like it could work…?