0

Do you know any tool that allows you to store command lines and easy execute them (maybe even supporting parameters)? Something like:

c:\foo\bar\baz.exe --foo [play]
c:\foo\bar\qux.exe --bzz [play]

It can also be a VSCode extension.

6
  • Is there a reason that batch files wont work? May 6, 2023 at 20:28
  • @RohitGupta it's a bit stupid to have dozens of batch files, each with only a single command for all the things you do. I'd be much easier to deal with them in a notepad fashion. Just type everything in and execute a line or the selected ones.
    – mr-nobody
    May 7, 2023 at 10:26
  • Thats your choice to make. You can easily have few or even one batch file - and you did mention parameters !!! And you did not say how many commands you wanted to do. May 7, 2023 at 10:29
  • @RohitGupta but how do you execute a single command in a multi-command batch? You can't. Let's say I have one line to create a python package, one line to check typing hints, one line to publish it and this repeated a couple of times for multiple packages. Then a couple of lines to install them in the editable mode in another environment. How would you execute them on demand one by one from a single file?
    – mr-nobody
    May 7, 2023 at 10:32
  • run it using batch_file param. Then compare the param to decide which command to execute inside the batch file. I would give you an example, but I wanted to know why you were discounting this approach, first. May 10, 2023 at 13:17

2 Answers 2

4

For regular Windows cmd, use clink. It has command history that you can configure.

History features include but aren't limited to:

  • master history file:

When the history.save setting is enabled, then the command history is loaded and saved as follows (or when the setting is disabled, then it isn't saved between sessions).

Every time a new input line starts, Clink reloads the master history list and prunes it not to exceed the history.max_lines setting.

  • shared command history:

When the history.shared setting is enabled, then all instances of Clink update the master history file and reload it every time a new input line starts. This gives the effect that all instances of Clink share the same history -- a command entered in one instance will appear in other instances' history the next time they start an input line.

  • history timestamps:

History items can optionally save the timestamp when they were added, and the timestamps can be shown in the history command.

  • auto suggestions:

Clink can suggest commands as you type, based on command history and completions.

To turn on automatic suggestions, run clink set autosuggest.enable true. When the cursor is at the end of the input line, a suggestion may appear in a muted color. If the suggestion isn't what you want, just ignore it. Or accept the whole suggestion with the Right arrow or End key, accept the next word of the suggestion with Ctrl + Right, or accept the next full word of the suggestion up to a space with Shift + Right.

0
1

I've accidentally found a nice workaround.

Create a ps1 file and open it with VSCode. Then type in your commands and add | Invoke-Expression after each of them at the end of the same line like this:

"C:\foo\bar\baz.exe --foo --bar" | Invoke-Expression

In order to execute it, just select the entire line and press F8! Isn't that awsome?!


It's also possible to use variables and the good news is that you can initialize the variables first (select the line(s) + F8) and later run other lines independently in any order!

$baz="C:\foo\bar\baz.exe" # <-- select and hit F8
"$baz --foo --bar" | Invoke-Expression # <-- select and hit F8 later!

There's more one can do (Three Ways To Run .Exe Files In PowerShell), but the examples here cover the most basic and common usage.

6
  • @RohitGupta: I guess the -1 for the question I got from you? ;P Anyways, here's a workaround that pretty much does what I need. What do you think? ;-]
    – mr-nobody
    May 8, 2023 at 17:00
  • @Destroy666: how about this?
    – mr-nobody
    May 8, 2023 at 17:03
  • yes but only because the question needed more details. It's best to edit and add those details. Had you edited, I could and would have withdrawn the -1. I am unclear here as well. Does it show the file with the cursor at the line that matches? May 10, 2023 at 13:26
  • 1
    plus oned it. See if you can make it clearer and more obvious for others. May 10, 2023 at 13:39
  • 1
    @RohitGupta done! I rephrased it. Would say it's better now?
    – mr-nobody
    May 10, 2023 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.