# Can you call a julia function in REPL shell mode?

**URL:** <https://discourse.julialang.org/t/can-you-call-a-julia-function-in-repl-shell-mode/119709>\
**Category:** General Usage\
**Tags:** repl\
**Created:** [September 22, 2024, 4:30pm UTC](https://discourse.julialang.org/t/can-you-call-a-julia-function-in-repl-shell-mode/119709 "2024-09-22T16:30:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![devel-chm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/devel-chm/32/3572_2.png) [@devel-chm](https://discourse.julialang.org/u/devel-chm)\
**Post date:** [September 22, 2024, 4:31pm UTC](https://discourse.julialang.org/t/can-you-call-a-julia-function-in-repl-shell-mode/119709/1 "2024-09-22T16:31:00Z")

</div>

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).

> ****
>
> ```bash
> # 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
> 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…?
