Skip to content

Commit d39cf84

Browse files
committed
Handle "$ cmd" to run "cmd", and display "$ cmd" as prompt
Fixes invenia#1.
1 parent 855e6e5 commit d39cf84

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

sphinxcontrib/runcmd/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,25 @@ def run(self):
7676
# Grab a cache singleton instance
7777
cache = CMDCache()
7878

79+
# Handle "$ foo" to run "foo", but display it as prompt (enabled
80+
# "prompt" flag).
81+
if self.arguments[0] in ("$", "%"):
82+
command = " ".join(self.arguments[1:])
83+
prompt = " ".join(self.arguments)
84+
else:
85+
command = " ".join(self.arguments)
86+
if "prompt" in self.options:
87+
prompt = command
88+
else:
89+
prompt = False
90+
7991
# Get the command output
80-
command = " ".join(self.arguments)
8192
output = cache.get(command)
8293

8394
# Grab our custom commands
8495
syntax = self.options.get("syntax", "text")
8596
replace = self.options.get("replace", "")
8697
reader = csv.reader([replace], delimiter=",", escapechar="\\")
87-
prompt = "prompt" in self.options
8898
dedent_output = self.options.get("dedent-output", 0)
8999

90100
# Dedent the output if required
@@ -93,7 +103,7 @@ def run(self):
93103

94104
# Add the prompt to our output if required
95105
if prompt:
96-
output = "{}\n{}".format(command, output)
106+
output = "{}\n{}".format(prompt, output)
97107

98108
# Do our "replace" syntax on the command output
99109
for items in reader:

0 commit comments

Comments
 (0)