Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Suggestions
➜ Repeat last command with '!' prefix
Repeat last command with '!' prefix
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Kahenraz
(75 posts) 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. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) 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 | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) 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>
 |
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 | Top |
|
Posted by
| Kahenraz
(75 posts) Bio
|
Date
| Reply #3 on Sun 14 Aug 2016 12:57 AM (UTC) |
Message
| That works great. Thank you! | 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.
15,296 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top