[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Suggestions
. . -> [Subject]  Repeat last command with '!' prefix
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Repeat last command with '!' prefix

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Kahenraz   (42 posts)  [Biography] bio
Date Sat 13 Aug 2016 10:16 PM (UTC)
Message
I use the Bash for a lot of command-line scripting which is kind-of-sort-of similar to Mush's command window.

One feature I wish Mush had would be to execute the last command as denoted by the prefix '!'.

For example,

HISTORY:
quest status 123
quest status 456
quest status 789

'!' would execute the last command where as whereas !q or any combination of characters matching up to the last match would execute that command from history.

'!q' in this example, would execute 'quest status 789' because it's the last command to being with this prefix.

This can be further filtered by adding additional characters.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sat 13 Aug 2016 11:52 PM (UTC)
Message
Before addressing your main question, note that Ctrl+R repeats the last command.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sun 14 Aug 2016 12:04 AM (UTC)

Amended on Sun 14 Aug 2016 12:06 AM (UTC) by Nick Gammon

Message
This alias should do what you want:


<aliases>
  <alias
   match="^!([A-Za-z]*)$"
   enabled="y"
   omit_from_command_history="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

local recentCommands = GetCommandList (0)

if not recentCommands  then
  ColourNote ("red", "", "No commands in command history")
  return
end -- if no commands

-- check for any argument, if none execute last command
if "%1" == "" then
  Execute (recentCommands [1])
  return
end -- if no argument

-- search backwards for matching command
for k, v in ipairs (recentCommands) do 
  if string.match (v, "^%1") then
    Execute (v)
    return
  end -- if a match
end  -- of for

-- nothing?
ColourNote ("red", "", "No command matching: %1")
</send>
  </alias>
</aliases>


Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


I am assuming you want to match an earlier alphabetic command - if not change the regular expression in the alias, but be careful that it is being used as a regular expression in string.match further down.

The function GetCommandList gets all the command history into a table. If you don't specify an argument (ie. you type "!") then it executes the most recent one. If you do, it searches for a match, and executes that one if found.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Kahenraz   (42 posts)  [Biography] bio
Date Reply #3 on Sun 14 Aug 2016 12:57 AM (UTC)
Message
That works great. Thank you!
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


2,069 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]