Suggestion - GUI to change directory


#1

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.


#2

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:


#3

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


#4

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)


#5

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

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:


#7

And in Ubuntu or any Linux with zenity:

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

#8

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


#9

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

Link: https://github.com/rupa/z/


#10

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

#11

If you cd to that directory very often, then

cd<press UP arrow>

is even faster that TAB completion


#12

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


#13

Squeee!


#14

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)