3

I open a shell (like sbt or node debug from my bash). Then inside this shell, I open another one (using scala or node repl respectively). Now I want to close the last shell and come back to the first one I opened (e.g. the sbt), but when I use CTRL + C, all shell hierarchy is being closed and I come back to the original bash terminal.

As I learnt from here, this behavior is not standard and is undesirable for me.

EDIT: I'm struggling this issue with node debug, so actually the issue isn't about sbt and scala.I used them to perform an experiment that shows a general nonstandard behavior of my bash. I found a similar issue with windows here, but I use Ubuntu 14.04

  • 3
    Generally when at any sort of interactive prompt from which you wish to exit, you should use CTRL + D. – Patrick May 24 '14 at 19:06
  • CTRL + D closing the terminal completely, while I wish to come back to the first interactive prompt (e.g. sbt) – leonprou May 24 '14 at 19:58
  • @leonprou - can you give us more details around what your're doing to launch this other "command" from within sbt or node debug? I have sbt installed and cannot understand what you're doing inside of it, that would require the break as you've described. – slm May 25 '14 at 8:43
  • @slm in the sbt i type console to open scala repl, than I wish to quit scala and come back to sbt. But when I press <kbd>CTRL</kbd> + <kbd>C</kbd> both scala and sbt are being closed. – leonprou May 25 '14 at 17:01
  • @leonprou - typing exit works to leave console. – slm May 25 '14 at 17:31
1

Typing the command exit or quit will exit the console that's been nested inside of sbt. You can also abbreviate these commands like so:

scala> :q
Not interrupting system thread Thread[process reaper,10,system]

[success] Total time: 138 s, completed May 25, 2014 1:33:22 PM
> 

Or as :e. This info is covered in the help page of console.

scala> :help
All commands can be abbreviated, e.g. :he instead of :help.
Those marked with a * have more detailed help, e.g. :help imports.

:cp <path>                 add a jar or directory to the classpath
:help [command]            print this summary or command-specific help
:history [num]             show the history (optional num is commands to show)
:h? <string>               search the history
:imports [name name ...]   show import history, identifying sources of names
:implicits [-v]            show the implicits in scope
:javap <path|class>        disassemble a file or class name
:load <path>               load and interpret a Scala file
:paste                     enter paste mode: all input up to ctrl-D compiled together
:power                     enable power user mode
:quit                      exit the interpreter
:replay                    reset execution and replay all previous commands
:reset                     reset the repl to its initial state, forgetting all session entries
:sh <command line>         run a shell command (result is implicitly => List[String])
:silent                    disable/enable automatic printing of results
:type [-v] <expr>          display the type of an expression without evaluating it
:warnings                  show the suppressed warnings from the most recent line which had any

scala> 

Keyboard shortcuts in console?

What you're really after here is to find out what keyboard shortcuts if any are available to you via console. To that end this post would seem to indicate that there are few to use:

I found the key shourtcut in scala interpreter, only support ctl+a,ctl+e,and ctl+f,ctl+b, and even tab key not supprt , not to mention code autocompletion (like f#'s)

Source: Subject: scala interpreter console keyboard shortcut and code autocompletion? - msg#00309

What about REPL?

According to this SO Q&A titled: Is there a way to use ctrl-d as forward delete in Scala's REPL? you can either make use of the default keybindings in Scala 2.9's REPL via the :keybindings.

You can also apparently override the keybindings with your own custom ones like so:

$ scala -Djline.keybindings=/path/to/keybindings.properties

See the SO Q&A referenced above for more details.

  • Well thanks, but my question was about more general behavior of sub-shells and not about sbt-scala repl (that was just a known example). Actually, I have difficulties with node debug repl sub-shell, so if anyone would figure out this specific case he'd solve my problem. Hope your answer will help some other poor folks :) – leonprou May 25 '14 at 18:18
  • @leonprou - I didn't say this directly but the point is the keybindings aren't generic like you're thinking, they're determined by the shells themselves. The shells being scala's console, sbt, etc. etc. – slm May 25 '14 at 20:56
0

If you type on the commandline: kill -l, you will see all the different interupts that exist. Not all are user-configurable.

stty will set your action (interrupt) with the keys (Ctrlc, Ctrl\, Ctrlz, etc)

stty intr ^C will set the key Ctrlc as you expect.

Another interesting feature is trapping.

If you use: trap 'echo tried it' 2, it will trap your interrupt and substitute it for echo tried it

This is a nice way to shield your shell-script from aborting to the commandline.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.