Suggestion - GUI to change directory

I find that in the REPL I start by cd(“directory where the data is”) constantly, and this irritates me. By that I mean repeated cd() calls till I get to the directory with the correct data file.
Yes, I know I could set a filepath variable and use that joined tot the filename.

My suggestion is to have a quick and dirty GUI utility which would pop up and change the current working directory. Written in Julia, natch.
I think a Julia curses utility was recently announced. Perhaps perfect for this task.
Note to self - get your backside in gear and write it.

1 Like

My opinion is that if you constantly do cd() in the REPL (or even in scripts), you are doing something “wrong”. I am even more confused since you are asking for a GUI, which makes it even slower and more sluggish to change a directory (waiting for the GUI to pop up, orientate, grab the mouse, clicking, closing etc.).

Besides that, integrating a GUI functionality into the REPL would be a significant amount of work, considering that people are running the REPL on macOS, Windows, Linux, *BSD and even in arbitrary Terminals like Jupyter Notebook/LAB. There is no common library which would unite all of them so you will definitely end up with all sorts of GUIs and dependencies needed.

If you ask me, this is definitely not worth it :wink:

2 Likes

I would put something into
~/.julia/config/startup.jl
e.g. a selection of pathes to choose of (in the REPL of course, no GUI).

And I just tried and found out, in the REPL:
cd("<TAB>
works also quite well.
Pressing TAB gives you all folders available in the current working dir. (Windows here)

Here’s a “quick and dirty” macOS version:

function changefolder()
    !Sys.isapple() && exit()
    command = """
    try
        set af to (choose folder with prompt "Folder?")
        set result to POSIX path of af
    on error
        beep
        set result to "$(pwd())"
    end
    result
    """
    cd(chomp(read(`osascript -e $command`, String)))
    println(pwd())
end

changefolder()

but to be honest it’s quicker to type cd :slight_smile:

6 Likes

Same idea for windows (10):

function changefolder()
    !Sys.iswindows() && exit()
    command = """
	Function Get-Folder(\$initialDirectory) {
		[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")|Out-Null

		\$foldername = New-Object System.Windows.Forms.FolderBrowserDialog
		\$foldername.Description = "Select a folder"
		\$foldername.rootfolder = "MyComputer"

		if(\$foldername.ShowDialog() -eq "OK")
		{
			\$folder += \$foldername.SelectedPath
		}
		return \$folder
	}

	Get-Folder
    """
    cd(chomp(read(`powershell -Command $command`, String)))
    println(pwd())
end

changefolder()

powershell code from here:
https://stackoverflow.com/questions/25690038/how-do-i-properly-use-the-folderbrowserdialog-in-powershell

7 Likes

And in Ubuntu or any Linux with zenity:

function changefolder()
       !Sys.islinux() && exit()
       cd(chomp(read(`zenity  --file-selection --directory`, String)))
       println(pwd())
end
6 Likes

Thankyou for all the replies.
Actually cd(" TAB completion is a great answer!

I use z to jump around. Works best if folders have unique names.

Link: GitHub - rupa/z: z - jump around

I prefer to use the ranger terminal file manager, I contributed to it so that it also preview djvu files :slight_smile:

function ranger()
    dir = joinpath(homedir(),".julia","config","cd")
    run(`ranger --choosedir=$dir`)
    cd(read(`cat $dir`,String))
    pwd()
end
1 Like

If you cd to that directory very often, then

cd<press UP arrow>

is even faster that TAB completion

julia-repl has a function julia-repl-cd (bound to C-c C-p by default) that sends a cd command to the REPL with the directory of the file that belongs to the buffer. I use this for small projects.

But if you are doing this regularly, consider defining something like

project_path(parts...) = normpath(joinpath(@__DIR__, "..", parts...))

in the project you are working on, so that you can write pathnames independent of the current directory in a convenient way. Or even just cd(project_path()).

Squeee!

And if you don’t want to take your hands off the home-row, you can do:
cd <ctrl+p>
or
<ctrl+r> cd
(using the built-in emacs style bindings)