Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm often compiling stuff and therefore repeating the same command over and over, so I'd like to benefit from my "visual memory" and have a sort of "repeat last command" button attached to a terminal. More precisely, here is how I see it:

  • My "special" terminal would be just like a standard terminal emulator, with an extra input line at the bottom, which would have a "run" button attached to it. Clicking the button would run the command without erasing it.
  • Maybe even an arbitrary number of such commands could be stacked (since I often need to alternate between 2 or 3 commands).

I know I can use just Enter with the keyboard to redo the last command, but what often happens is that I forget I just had to type another command (to fix something, or whatever) so will not bring the right command from the history. So instead of a reflex, I have to actually read (at least skim) the command before pressing Enter.

Is there such a contraption somewhere? I often use several terminals precisely to make sure each always has the "right" command as last, but my Alt+Tab skills usually make me tab to the wrong window. And I need terminal information, such as the environment and cwd, so I cannot just try and "integrate" it in my code editor. I mean, using Alt+F2 and then Enter would not work (since I also need the read the output from the terminal). I just want to be able to use the best of both keyboard and visual memory (via clicks) at the same time.

share|improve this question
1  
How about an alias with your compile command - a very short alias, like two or three letters? –  Emanuel Berg Jul 18 '12 at 16:09
2  
How would your button know which command you need if "up-Enter" isn't always what you want? Most shells have sophisticated tools for recalling and executing commands in the history, in bash !m would recall the last command entered starting with m (e.g. make). –  donothingsuccessfully Jul 18 '12 at 17:37
1  
Have a look at difference between termian and a shell. The problem is that the terminal typically knows nothing about your shell, e.g. it doesn't know in which directory (or host) you currently are and can't execute the command. You should try to enhance your setup and build from within your ide/editor. –  Ulrich Dangel Jul 18 '12 at 18:00
    
Thank you very much for your ideas! I'll read them in detail. Anyway, I think a "fake screenshot" could help explain what I was thinking about. (Images are taken from the internet BTW). This is how I'd see my "extended terminal": !My Terminal Just a plain terminal attached to a "command bar" at the bottom. The idea is: in the event of a click on the "Run" button, the current command line in the shell is removed and the text in the "command bar" becomes the current command, which is sent to the terminal. Very simple, no autocompletion or anything necessary. –  dhekir Jul 20 '12 at 15:44
    
(sorry, I cannot post longer messages). Also, when the button is clicked, the text remains in place, so I don't have to type it again. The idea would be to later make some kind of "hover" bar (like on this fake screenshot: !IDE example that stays on top of the IDE. Its position is more or less fixed, so I can use my visual memory to execute the command. Even if there are several of them, I find it easier to manage than the history (though those advanced commands may help). –  dhekir Jul 20 '12 at 15:48
show 1 more comment

4 Answers

I think that history expansion might be very helpful here. For example, typing !p will execute the last command starting with 'p'. Similarly !vi will execute the last command starting with 'vi', and so on. More info here. If you are not sure which of those was the last one, you can set shell option histverify (shopt -s histverify), so you can still edit (or inspect) the command before you execute it. More on this here.

Alternatively, you can use the history search functionality. In bash, hit Ctrl+R and type the command you want to find in the history (starting with the most recent one that matches the criteria). Hitting Ctrl+R repeateadly then will bring back older commands that match your criteria. More info here and here

If you are keen, you can modify your readline's inputrc, such that the up/down arrows do the history search for you. More info here and here.

share|improve this answer
    
In addition to this answer: unix.stackexchange.com/a/67/14084 –  Bernhard Jul 19 '12 at 7:31
add comment

Take a look at the history functionality of your shell. In my zsh:

!!

repeats the last command.

Type history to take a look at the last few entries.

To get your desired buffer in the shell:

man zshzle

or

man readline

Also, you can tab expand the completions

make long_target
ls some_path
...
make l<TAB> # prints 'make long_target' without running it

use wildcards, expansions... not one bit of your use case lies outside of this functionality.

share|improve this answer
add comment

Using zsh you can do just that with Esc+A. Type a command then press Esc+A instead of Enter. The command will be executed and the same command will be on the line buffer after the command completes.

share|improve this answer
add comment

It looks like you need a very simple answer. Since you mentioned Alt+Tab, I assume you are using (X)windows. You highlight the command with the mouse before you press "Enter". It is automatically copied to the clip board when you highlight it. To paste it, press the middle mouse button (scroll wheel) or type Shift+Insert.

share|improve this answer
2  
I got the impression that he has the habit of hitting that command often, and, if so, using the mouse isn't a good idea. –  Emanuel Berg Jul 18 '12 at 19:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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