Skip to content

Commit 42d0037

Browse files
committedMay 3, 2021
add special command '%cd [path]'
1 parent 87da03e commit 42d0037

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed
 

‎README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,19 @@ $ docker run -it -p 8888:8888 -v /path/to/local/notebooks:/path/to/notebooks/in/
200200
201201
- Have fun!
202202
203+
## Special commands
204+
205+
In addition to Go code, the following special commands are also supported - they must be on a line by their own:
206+
- %cd [path]
207+
- %go111module {on|off}
208+
- %help
209+
- $ shell_command [args...]
210+
203211
## Limitations
204212
205213
gophernotes uses [gomacro](https://github.com/cosmos72/gomacro) under the hood to evaluate Go code interactively. You can evaluate most any Go code with gomacro, but there are some limitations, which are discussed in further detail [here](https://github.com/cosmos72/gomacro#current-status). Most notably, gophernotes does NOT support:
206214
207-
- third party packages when running natively on Windows - This is a current limitation of the Go `plugin` package.
215+
- importing third party packages when running natively on Windows - This is a current limitation of the Go `plugin` package.
208216
- some corner cases on interpreted interfaces, as interface -> interface type switch and type assertion, are not implemented yet.
209217
- some corner cases on recursive types may not work correctly.
210218
- conversion from typed constant to interpreted interface is not implemented. Workaround: assign the constant to a variable, then convert the variable to the interpreted interface type.

‎kernel.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -719,8 +719,9 @@ func evalSpecialCommands(ir *interp.Interp, outerr OutErr, code string) string {
719719
func evalSpecialCommand(ir *interp.Interp, outerr OutErr, line string) {
720720
const help string = `
721721
available special commands (%):
722-
%help
722+
%cd [path]
723723
%go111module {on|off}
724+
%help
724725
725726
execute shell commands ($): $command [args...]
726727
example:
@@ -734,7 +735,18 @@ $ls -l
734735
arg = args[1]
735736
}
736737
switch cmd {
737-
738+
case "%cd":
739+
if arg == "" {
740+
home, err := os.UserHomeDir()
741+
if err != nil {
742+
panic(fmt.Errorf("error getting user home directory: %v", err))
743+
}
744+
arg = home
745+
}
746+
err := os.Chdir(arg)
747+
if err != nil {
748+
panic(fmt.Errorf("error setting current directory to %q: %v", arg, err))
749+
}
738750
case "%go111module":
739751
if arg == "on" {
740752
ir.Comp.CompGlobals.Options |= base.OptModuleImport

0 commit comments

Comments
 (0)
Please sign in to comment.