Archive

Posts Tagged ‘Lua’

How to add command line arguments to your piger commands

April 1st, 2020 No comments

First the basics

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

-- 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

-- 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

-- 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

Categories: Cheat-sheet, Myoddweb Piger Tags: ,

Released piger 0.3.2

February 27th, 2016 Comments off

I released the first version of Piger on Github after moving from sourceforge.net

This new release is pretty much the same as the previous one just brought to the 21st century …

The changes are

  1. Python 3.5.1
  2. Python is not required on the host machine, (something that was causing a break before!)
  3. Lua 5.2
  4. x64 or x86 build, (not for memory reasons, but for env. variable reasons).
  5. Moved from Sourceforge.net, (I added a readme.md to redirect to github). Please Google for some well documented reasons to move away from them…

Please try it and tell me if you see something cool that should be added.

I am also looking for cool scripts to be added to my list, so please, send them my way!

Categories: Myoddweb Piger Tags: , , ,