Initial commit (version 0.1.0).

This commit is contained in:
Jonathan Bernard 2017-08-25 18:03:51 -05:00
commit 8b5fcc7bfc
3 changed files with 44 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.sw?
nimcache/
cmd_shell

30
cmd_shell.nim Normal file
View File

@ -0,0 +1,30 @@
import cliutils, linenoise, os, osproc, sequtils, strutils
proc writeOutput(msg, errMsg: TaintedString, cmd: string): void =
if msg != nil: stdout.writeLine(msg)
if errMsg != nil: stderr.writeLine(errMsg)
when isMainModule:
if paramCount() == 0:
stderr.writeLine "cmd_shell: no arguments"
quit(QuitFailure)
let cmdPrompt = paramStr(1)
let cmd = '"' & cmdPrompt & '"'
let args =
if paramCount() > 1: commandLineParams()[1..^1].mapIt("'" & $it & "'").join(" ")
else: ""
discard historySetMaxLen(
if existsEnv("HISTSIZE"): (cint)parseInt(getEnv("HISTSIZE"))
else: (cint)1000)
var line = readLine(cmdPrompt & "> ")
while line != nil:
discard exec(cmd & " " & args & $line, "", [], nil, {poUsePath, poEvalCommand}, writeOutput)
historyAdd(line)
line = readLine(cmdPrompt & "> ")

11
cmd_shell.nimble Normal file
View File

@ -0,0 +1,11 @@
# Package
version = "0.1.0"
author = "Jonathan Bernard"
description = "Wrapper around CLI commands (passing input as arguments)."
license = "MIT"
bin = @["cmd_shell"]
# Dependencies
requires @["nim >= 0.16.1", "cliutils"]