Skip to content

Commit

Permalink
feat: added command exec to execute commands without using the system…
Browse files Browse the repository at this point in the history
…'s default shell

FossilOrigin-Name: 47be30862e5eef080e3f059459e272c303aed96323007048d7c1dcee1807b28f
  • Loading branch information
thindil committed Jan 1, 2024
1 parent 8e32b59 commit 4ad1386
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/nish.nim
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ proc main() {.sideEffect, raises: [], tags: [ReadIOEffect, WriteIOEffect,
if userInput.kind == cmdArgument:
commandName = userInput.key
# Set the command arguments
let arguments: UserInput = try:
var arguments: UserInput = try:
initLimitedString(capacity = maxInputLength, text = $getArguments(
userInput = userInput, conjCommands = conjCommands))
except CapacityError:
Expand Down Expand Up @@ -574,6 +574,20 @@ proc main() {.sideEffect, raises: [], tags: [ReadIOEffect, WriteIOEffect,
# Delete environment variable
of "unset":
returnCode = unsetCommand(arguments = arguments, db = db)
# Execute the command without using the system's default shell
of "exec":
let spaceIndex: int = arguments.find(sub = ' ')
if spaceIndex > 0:
commandName = $(arguments[0 .. spaceIndex - 1])
arguments = initLimitedString(capacity = maxInputLength, text = $(
arguments[spaceIndex + 1 .. ^1]))
else:
commandName = $arguments
arguments = emptyLimitedString(capacity = maxInputLength)
returnCode = executeCommand(commands = commands,
commandName = commandName, arguments = arguments,
inputString = inputString, db = db, aliases = aliases,
cursorPosition = cursorPosition, withShell = false)
# Execute command (the shell's or external) or the shell's alias
else:
returnCode = executeCommand(commands = commands,
Expand Down

0 comments on commit 4ad1386

Please sign in to comment.