1

I am not so sure whether this has become more of a general issue or whether it is just me working a lot with OpenStack, lately. Anyways, I noticed some commands, for example the entire set of OpenStack commands and git, offer information about their submodules using the help subcommand, e.g.

  • neutron help security-group-rule-create
  • git help clone

This is not really nice to work with, because every time I feel uncertain about something or even encounter errors I have to

  1. scroll way over to the left,
  2. add in "help",
  3. press enter,
  4. read the help,
  5. press arrow up,
  6. scroll all the way to the left,
  7. delete "help",
  8. press enter

I know for git there are man pages available, I just wanted to add another example than OpenStack commands.

I would much rather have some key combination or even a short command which modifies the last command (the one I can recall by pressing the the arrow-up-key) and either inserts "help" as the second word or removes the second word, if it's "help".

I am using Bash, so I was thinking along the lines of using fc and aliases, but I cannot make this work at all. I think fc's patterns are restricted to mere string replacement and cannot cope with complex things like "the second word".

The most awesome solution would be a modifier for "enter", so I can search for commands, either using the arrow-up-key, or ctrl+r and when I found the desired command I hit ctrl+enter to execute it, but before execution "help" is automagically inserted as the second word of the command. Alternatively, when I hit alt+enter to execute the desired command "help" is removed as the second word of the command before execution. Yet, I have no idea to go about this.

  • 2
    This doesn't answer your larger question, but there are keyboard shortcuts that can simplify your scrolling etc. in your eight steps: Ctrl+A goes to the beginning of the line, Alt+right moves right by one word, Alt+D deletes the following word... So adding help is Ctrl+A, Alt+right, "help " and Enter; removing help is Ctrl+A, Alt+right, Alt+D and Enter. – Stephen Kitt Sep 5 '16 at 13:52
  • 2
    At step 5, why not press arrow up a second time, and skip straight to step 8? – JigglyNaga Sep 5 '16 at 15:38
  • @JigglyNaga because that is not always a good idea. Shall I draw a decision tree and spell out every possibility I can end up in the described situation and also discuss approaches for all other more or less similar situations? That would make the question even broader and I have already received a close vote for being too broad. – Bananguin Sep 5 '16 at 15:56
  • Use "git cl<ctrl-PageUp>" to get only "git clone ..."commands from your history (/etc/inputrc: history-search-backward). BTW you can also use git clone --help. And ctrl-k removes the rest of the line. – rudimeier Sep 5 '16 at 16:11
1

We can cheat and make a simple command called h, and put it on your path:

eg

#!/bin/sh

cmd="$1"
shift

echo Running $cmd help "$@"
$cmd help "$@"

Now you can simply do h !! to insert the help message eg

$ git foo bar baz
....
$ h !!
h git foo bar baz
Running git help foo bar baz
...

Your h comamnd can be made as complex as you want; eg special parsing for any command that may require more than just putting help in front.

Once you've read the help you can just press up-arrow twice to get back the real command.

  • This is very much what I initially had in mind! Of course I can add some logic to add or remove "help" as needed. I guess this helps most use cases. – Bananguin Sep 5 '16 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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