Usage of GNU Emacs by non-programmers ...... Edit shell mode 4th set History commands

Source: Internet
Author: User

In day-to-day shell work, History commands are edited, just like command line editing. As mentioned above, software quality testing faces a large number of complex system environments and involves a lot of complex work in these system environments. Although a large amount of work is complicated, there are also many duplicates, some of which are reflected in the duplication between different instances of complex applications, in addition, some complex commands are repeated between different systems and machines.

 

Bash's history command editing function is quite good. Not only! Commands can reference historical commands that have been executed and their parameters, and ^ commands can be used to quickly edit previous historical commands. These functions are essential for my daily work, however, there is still a lot of work that is hard to achieve by relying solely on the Bash History command editing function.

Let's look at a simple example. Enter a command to start an application that is used every day.

Bin/itmcmd agent-O qmcod, qmcm, qmb, qmd start MQ

This command starts four instances of an application, and then I enter the next command to check whether they are running correctly.

bin/cinfo -r

Then I need to stop the four instances... The command to stop them is like this.

bin/itmcmd agent -o QMCOD,QMCM,QMB,QMD stop mq

We can see that this is only one word different from the command used to start the four instances, that is, to change start to stop, but I cannot use this historical command editing function to get it.

^ Start ^ stop

Why? Because there is an additional Cinfo after that start command... Have you seen it? This is the case... Obviously, I am unlikely to use it! The command references all the parameters except start in the startup command. Not to mention the input so much! The reference itself is not worth the candle. In fact, if you want to know the history code of a command at any time, you also need to change the bash Profile settings first, right? Now again, you can realize that working on your own exclusive, well-configured, and armed machines with teeth is different from working on a large number of complicated machines, and working on machines that are changing at any time is a completely different feeling, right?

This is the difference between our actual working environment and the bash design idea. As can be seen from the above example, bash puts forward two kinds of assumptions. One assumption is that most people want to execute a slight "variant" based on the previous command ", therefore, you can use the ^ command to quickly edit the command you just executed. Another assumption is that people usually need to reference it in subsequent commands, or reuse some parts used in previous commands.

For the first assumption of bash, it is unfortunate that the distance between this method is too small, and sometimes some people just knock a ls because of the "cheap, then the chance of editing the previous command using the ^ function is lost forever. The second assumption of bash seems to have enough working distance on the surface, but on the one hand, getting the historical code itself is quite troublesome, in addition, in my work, I usually need to reference the vast majority of the content of a history command. Only one or two parameters are different. This is a lot of time! 334: 1! 334: 2! 334: 3... it is a very uneconomical thing. It is better to re-enter the command.

In this case, the shell-mode of Emacs is needed. The solution of Emacs is actually very simple, that is, the control right of command input is taken back to Emacs, but this time it is a little different, or more Emacs...

As we all know, Emacs is a text editor and a full-screen text editor. So after we take the control right of command input back to Emacs, it is not just as easy as obtaining the right from the shell side, at the same time, we upgraded shell's original command line editing function to a new "Full Screen Editing" level. In other words, all the content in Emacs shell-buffer can be edited, which is the same as editing an article or code!

Have you noticed that Emacs is amazing? In fact, in the shell-mode of Emacs, I only need to move the cursor to the position where the command is located,

Bin/itmcmd agent-O qmcod, qmcm, qmb, qmd start MQ

Although he is now the screen output part of the shell, as long as he is still in the shell-buffer of Emacs, I can edit him as I like. After moving the past, you just need to edit the start on the screen to stop, and press enter to let Emacs send the edited content to the bash behind it. Everything is fine.

The shell-mode of Emacs also provides the comint-previous-Prompt and comint-next-Prompt commands, so that we can easily move between command lines in Shell-buffer. These two commands are usually bound to the Ctrl-C Ctrl-P and Ctrl-C Ctrl-N shortcut keys. Or, sometimes, because ThinkPad's red dot is in the middle of the keyboard, I often use the red dot "Mouse" directly ", move the cursor to the desired command.

Of course, the saying goes back. If I leave zhangtu, I will not eat pig with hair. Bash can also do this, but after all, the layout of the up and down arrow keys on the keyboard is too far away from the central area of the keyboard, for countless times of work every day, saving a second is quite impressive.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.