How to add command line arguments to your piger commands
First the basics
1 |
am_execute( cmd, args, admin); |
The first argument is the command we wish to execute, the second one is the command line argument and the last one is if we wish to run as administrator or not, (with privileged access).
How to get the arguments?
You have various commands to get the arguments entered.
You can get the ones typed by the user
1 2 3 4 5 6 7 8 |
-- the number of arguments local sizeOf = am_getCommandCount(); -- argument number 0 is the action itself, (what he user typed in). local action= am_getCommand( 0 ); ... -- argument number 1 local cmd= am_getCommand( 1 ); |
Or you can also get the selected folder if there is one
Remember that we could have selected more than one folder
1 2 |
-- do we have a folder? local thisFolder = am_getfolder( 0, false ); |
Putting it all together
If you have an app like cmder or even the default command line app you can put it all together
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
-- the location of the cmder.exe if it is not in the path. local cmderPath = [[c:\path\to\your\cmder\Cmder.exe]]; -- do we have a folder? local thisFolder = am_getfolder( 0, false ); -- if we don't have a folder, guess what we are looking for. if thisFolder == false then local sizeOf = am_getCommandCount(); if sizeOf == 0 then -- no arguments. am_say( "<i>Going to <b>home</b> drive</i>.", 400, 10 ) am_execute( cmderPath, [[/START %HOMEDRIVE%\]], true ); else local thisWord = am_getCommand( 1 ); if thisWord == "home" or thisWord == "h" then am_say( "<i>Going to <b>home</b> drive</i>.", 400, 10 ) am_execute( cmderPath, [[/START %HOMEDRIVE%\]], true ); elseif thisWord == "system" or thisWord == "s" then am_say( "<i>Going to <b>system</b> drive</i>.", 400, 10 ) am_execute( cmderPath, [[/START %SYSTEMDRIVE%\]], true ); else am_execute( cmderPath, "", true ); end end else -- go to the selected folder and in case of multiple drives, change the drive letter. am_say( "<i>Going to <b>".. thisFolder .."</b></i>.", 400, 10 ) am_execute( cmderPath, "/START \"" .. thisFolder .. "\"", true); end |
And save the file and call it “cmder.lua” and save it in your root command folder, (or subdirectory).
Then if the user types
- cmder home – they will go to their home directory
- cmder – they will go to their system drive
- cmder (with the cursor over a folder name) – they will go to that folder.
More?
You can get more information on the piger github page
Recent Comments