wuub / SublimeREPL

SublimeREPL - run an interpreter inside ST2 (Clojure, CoffeeScript, F#, Groovy, Haskell, Lua, MozRepl, NodeJS, Python, R, Ruby, Scala, shell or configure one yourself)
https://github.com/wuub/SublimeREPL
Other
2.14k stars 312 forks source link

Introduce Bash and Command Prompt #213

Open Alexander-Shukaev opened 10 years ago

Alexander-Shukaev commented 10 years ago

Hello Sir,

First of all, good job, nice package, keep it up!

I'm writing with improvement for this package here. So, to begin with, I found the idea of Shell REPL a bit jerky. It combines 2 types of shells depending on platform, i.e.

                    "cmd": {"windows": ["cmd"],
                            "linux": ["sh", "-i"],
                            "osx": ["sh", "-i"]},

That's quite inflexible for everyone, and especially unfair for Windows users. Here are the reasons:

What I propose is to remove Shell REPL, and introduce separate Command Prompt (for Windows only), Bash (for all), Sh or Shell again (for all). Please, take a look at the patch I'm sending you, it will give you an idea:

From 736b845884306a4d8f1eb0176e8f8c040f18e2df Mon Sep 17 00:00:00 2001
From: Haroogan <Haroogan@gmail.com>
Date: Mon, 22 Jul 2013 23:45:45 +0200
Subject: [PATCH] Introduce Bash and Command Prompt

---
 config/Bash/Default.sublime-commands           | 10 ++++++++
 config/Bash/Main.sublime-menu                  | 33 ++++++++++++++++++++++++++
 config/Command Prompt/Default.sublime-commands | 10 ++++++++
 config/Command Prompt/Main.sublime-menu        | 29 ++++++++++++++++++++++
 4 files changed, 82 insertions(+)
 create mode 100644 config/Bash/Default.sublime-commands
 create mode 100644 config/Bash/Main.sublime-menu
 create mode 100644 config/Command Prompt/Default.sublime-commands
 create mode 100644 config/Command Prompt/Main.sublime-menu

diff --git a/config/Bash/Default.sublime-commands b/config/Bash/Default.sublime-commands
new file mode 100644
index 0000000..7c13805
--- /dev/null
+++ b/config/Bash/Default.sublime-commands
@@ -0,0 +1,10 @@
+[
+    {
+        "caption": "SublimeREPL: Bash",
+        "command": "run_existing_window_command", "args":
+        {
+            "id": "repl_bash",
+            "file": "config/Bash/Main.sublime-menu"
+        }
+    }
+]
diff --git a/config/Bash/Main.sublime-menu b/config/Bash/Main.sublime-menu
new file mode 100644
index 0000000..1842ed6
--- /dev/null
+++ b/config/Bash/Main.sublime-menu
@@ -0,0 +1,33 @@
+[
+     {
+        "id": "tools",
+        "children":
+        [{
+            "caption": "SublimeREPL",
+            "mnemonic": "r",
+            "id": "SublimeREPL",
+            "children":
+            [
+                {"command": "repl_open",
+                 "caption": "Bash",
+                 "id": "repl_bash",
+                 "mnemonic": "b",
+                 "args": {
+                    "type": "subprocess",
+                    "encoding": {"windows": "utf-8",
+                                 "linux": "utf-8",
+                                 "osx": "utf-8"},
+                    "cmd": {"windows": ["bash", "-i", "-l", "-c", "cd '$file_path'; bash -i"],
+                            "linux": ["bash", "-i", "-l", "-c", "cd '$file_path'; bash -i"],
+                            "osx": ["bash", "-i", "-l", "-c", "cd '$file_path'; bash -i"]},
+                    "cwd": "$file_path",
+                    "cmd_postfix": "\n",
+                    "env": {},
+                    "suppress_echo": true,
+                    "syntax": "Packages/Text/Plain text.tmLanguage"
+                    }
+                }
+            ]
+        }]
+    }
+]
diff --git a/config/Command Prompt/Default.sublime-commands b/config/Command Prompt/Default.sublime-commands
new file mode 100644
index 0000000..51aad90
--- /dev/null
+++ b/config/Command Prompt/Default.sublime-commands    
@@ -0,0 +1,10 @@
+[
+    {
+        "caption": "SublimeREPL: Command Prompt",
+        "command": "run_existing_window_command", "args":
+        {
+            "id": "repl_command_prompt",
+            "file": "config/Command Prompt/Main.sublime-menu"
+        }
+    }
+]
diff --git a/config/Command Prompt/Main.sublime-menu b/config/Command Prompt/Main.sublime-menu
new file mode 100644
index 0000000..3be6765
--- /dev/null
+++ b/config/Command Prompt/Main.sublime-menu   
@@ -0,0 +1,29 @@
+[
+     {
+        "id": "tools",
+        "children":
+        [{
+            "caption": "SublimeREPL",
+            "mnemonic": "r",
+            "id": "SublimeREPL",
+            "children":
+            [
+                {"command": "repl_open",
+                 "caption": "Command Prompt",
+                 "id": "repl_command_prompt",
+                 "mnemonic": "c",
+                 "args": {
+                    "type": "subprocess",
+                    "encoding": {"windows": "$win_cmd_encoding"},
+                    "cmd": {"windows": ["cmd"]},
+                    "cwd": "$file_path",
+                    "cmd_postfix": "\n",
+                    "env": {},
+                    "suppress_echo": true,
+                    "syntax": "Packages/Text/Plain text.tmLanguage"
+                    }
+                }
+            ]
+        }]
+    }
+]
-- 
1.8.3.3

Also see how I added support for login shells, while preserving the correct directory. I think it's much more natural to provide users with login shells, rather than barely interactive ones.

I've tested this patch and I'm currently using it.

Looking forward to your comments.

wuub commented 10 years ago

Looks very interesting, especially the bash login hack :) I'll check if it terminates correctly under killablerprocess and if it does there is a very high chance it'll be integrated into SublimeREPL.

Thank you for contributing :+1:

Alexander-Shukaev commented 10 years ago

Cool, thank you! :)

emestee commented 10 years ago

This makes me wonder, could one use Sublime syntax to implement ANSI colors in a console? Case in point: Vagrant + Puppet on Windows.

wuub commented 10 years ago

@emestee in theory you could, but I don't recall a way to leave control codes in the source text, but hide them from view. Maybe a modified font with some very narrow glyphs? I was doing insane hacks in SublimePTY to get colours working, I would love a simpler way...

dfyx commented 8 years ago

SublimeANSI appears to be exaclty what @emestee needs.

janxkoci commented 4 years ago

Was this ever implemented? When I try to run lines from bash script, my sublime complains that

Cannot find REPL for 'shell.bash'

and in the list of available REPLs there is only shell, not bash or any other of those proposed here. 😞