2

I'd like to have a keyboard shortcut do the following:

I select a file in nautilus and press the key-combination, it opens a terminal window, starts julia in it and loads the file in the julia environment (i.e. include("file.jl")).

Is there an easy way to do this in Ubuntu?

1 Answers1

1

There is no really easy way, but there are ways. Nautilus supports scripts by itself. You can write them, then store them in ~/.local/share/nautilus/scripts/ and use them by rightclicking on the file(s) and select the script to use. This is covered in more detail e.g. here: https://help.ubuntu.com/community/NautilusScriptsHowto

By using the environment-variables initialized by Nautilus..

NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
- newline-delimited paths for selected files (only if local) 
NAUTILUS_SCRIPT_SELECTED_URIS
- newline-delimited URIs for selected files

..you can then do a script like:

#!/bin/bash

cd $NAUTILUS_SCRIPT_CURRENT_URI
eval ${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS##*/}

gnome-terminal -x sh -c 'julia -L ${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS##*/}; exec bash'

where you change into the current directory, eval if something is selected at all and with gnome-terminal -x start a new shell with the continous-option -c and launch Julia. The -L flag imports a file into your Julia shell. the ##*/ takes everything from the string starting at the last /.

store the script in ~/.local/share/nautilus/scripts/, make sure to set the right privileges with chmod +x yourScript.sh and try running it by selecting a file in nautilus, rightclicking it and running the script.

for the keybinding check out Changing nautilus key

I hope this works for you,

Gewure

Gewure
  • 363
  • 3
  • 10