Initial commit (version 0.1.0).
This commit is contained in:
		
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					*.sw?
 | 
				
			||||||
 | 
					nimcache/
 | 
				
			||||||
 | 
					cmd_shell
 | 
				
			||||||
							
								
								
									
										30
									
								
								cmd_shell.nim
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								cmd_shell.nim
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										11
									
								
								cmd_shell.nimble
									
									
									
									
									
										Normal 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"]
 | 
				
			||||||
		Reference in New Issue
	
	Block a user