YaKuake is for you if you ever wished for summoning a customizable terminal with a single keypress. Being in KDE extragear, it is most likely contained in your repositories. To check it out, install the yakuake package and start it from the K Menu.
Once it is started, press F12 to show/hide the Yakuake terminal. Nice and practical, isn't it? What makes this application even better is that it supports splitting the view, as well as detaching of inline shells into separate tabs, which is similar in behavior to the console-based screen, tmux or dvtm window managers.
All functionality is (also) accessible via keyboard shortcuts. To split the view horizontally/vertically, press CTRL-SHIFT-T and CTRL-SHIFT-L, respectively. Create a new tab with CTRL-SHIFT-N. You can close shells using CTRL-SHIFT-R, or by logging out of that shell using CTRL-D or the exit command.
Navigation is straightforward. You can cycle through the shells within a split view using CTRL-SHIFT-Up/Down, and go through tabs with SHIFT-Left/Right. CTRL-SHIFT-Left/Right lets you move a tab to another position.
As with every shell related application, I consider it crucial to customize the settings to my likings and requirements for a streamlined workflow. You might want to increase YaKuake's height to make better use of your screen estate. I also set the application to not stay open when it loses focus, so I can click somewhere and have it out of the way. I also activate the "highlight terminals when they are activated" thing, which is very useful in splitscreen. You can access the settings by clicking the little down arrow on the right of YaKuake's "bottom bar".
Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts
09 January 2010
28 December 2009
dvtm - a console based tiled window manager
In my last post, I outlined how to do some form of rudimentary multitasking in Bash, but I was still not satisfied. Further research showed that there would be no way around a terminal multiplexer, however screen sucks for me due to its steep and unintuitive learning curve. On K.Mandla's great blog I found the solution: dvtm, a very lightweight tiled window manager for the console. Its beauty lies in that it occupies just around 100k of disk space, does not hog the memory and does not try to accomplish more than it is supposed to.
Becoming familiar with dvtm is a matter of minutes. Install the package from your distribution repositories, go to a console or open an xterm, then input dvtm. You will see Bash within a blue frame. The blue frame indicates that this is the active window. Now press CTRL-G C (press CTRL-G, release the keys, then type a C). A new Bash window pops open next to the existing one and becomes the active window. You can close that window by either logging out of that instance (input exit or press CTRL-D), or by pressing CTRL-G X.
With multiple windows open, you can input CTRL-G <number> to activate window <number> (as designated by its "title bar" text), or CTRL-G J / CTRL-G K to activate the next/previous window. CTRL-G . minimizes or unminimizes the active window. CTRL-G M maximizes the active window. Use CTRL-G SPACE to toggle between grid layouts; this is also the only way to unmaximize a window. CTRL-G ENTER moves the active window in and out of the "master area", which is usually the tile of the biggest size. Finally, dvtm can be left by means of CTRL-G Q, or logging off all hosted shells.
If you need a lightweight multi-window shell environment, dvtm should be surely worth checking out.
Becoming familiar with dvtm is a matter of minutes. Install the package from your distribution repositories, go to a console or open an xterm, then input dvtm. You will see Bash within a blue frame. The blue frame indicates that this is the active window. Now press CTRL-G C (press CTRL-G, release the keys, then type a C). A new Bash window pops open next to the existing one and becomes the active window. You can close that window by either logging out of that instance (input exit or press CTRL-D), or by pressing CTRL-G X.
With multiple windows open, you can input CTRL-G <number> to activate window <number> (as designated by its "title bar" text), or CTRL-G J / CTRL-G K to activate the next/previous window. CTRL-G . minimizes or unminimizes the active window. CTRL-G M maximizes the active window. Use CTRL-G SPACE to toggle between grid layouts; this is also the only way to unmaximize a window. CTRL-G ENTER moves the active window in and out of the "master area", which is usually the tile of the biggest size. Finally, dvtm can be left by means of CTRL-G Q, or logging off all hosted shells.
If you need a lightweight multi-window shell environment, dvtm should be surely worth checking out.
20 December 2009
How to work with multiple jobs in Bash
An important feature often overlooked by novice console users is job control. It allows some amount of multitasking on a shell by delegating processes to the background and resuming them at a later point. That way, you don't have to launch a second shell or use additional utilities like screen to manage multiple tasks.
Job control is easy. Let's say you have Midnight Commander running. Hit CTRL+Z and you end up back at the shell prompt. You will notice a line above the prompt stating that mc is suspended. The beginning of the line shows mc's job number in square brackets (1 in this case). Ok, let's use that job number to resurrect mc. Input %1 and voĆla, mc is back! Similarly, you can use %1 & to unsuspend mc and continue running it as a background job. Note that background jobs are detached from the terminal and will be suspended as soon as they try to read from or write to it.
When working with multiple jobs, you will find the jobs command very useful, which lists the running jobs with their numbers and status.
A more intuitive way to unsuspend a job is to give part of its command line. %mc will unsuspend Midnight Commander, however if you have multiple instances running it will result in an error. Finally, just inputting % will unsuspend the most recently suspended job.
As you can certainly see, this feature is a real time-saver by allowing you to get running applications out of the way and resume them later.
Job control is easy. Let's say you have Midnight Commander running. Hit CTRL+Z and you end up back at the shell prompt. You will notice a line above the prompt stating that mc is suspended. The beginning of the line shows mc's job number in square brackets (1 in this case). Ok, let's use that job number to resurrect mc. Input %1 and voĆla, mc is back! Similarly, you can use %1 & to unsuspend mc and continue running it as a background job. Note that background jobs are detached from the terminal and will be suspended as soon as they try to read from or write to it.
When working with multiple jobs, you will find the jobs command very useful, which lists the running jobs with their numbers and status.
A more intuitive way to unsuspend a job is to give part of its command line. %mc will unsuspend Midnight Commander, however if you have multiple instances running it will result in an error. Finally, just inputting % will unsuspend the most recently suspended job.
As you can certainly see, this feature is a real time-saver by allowing you to get running applications out of the way and resume them later.
24 November 2009
How to generate PHP code from Bash
If you are into server side web programming, you will probably have had some exposure to PHP. Advantages of the language are that it is very widely supported, and that it can be freely mixed with HTML within the same file.
You might want to have some script running on the server for the purpose of generating PHP code. Unfortunately, you cannot throw everything at Bash's string functions as-is because some special characters are used to denote expansion or redirection. One totally unexciting but have-to-know bash feature comes into play here, called quoting.
Quoting is the art of using single or double quotes or backslashes to protect a range of characters in a string from being interpreted by Bash. In short, single quotes protect everything inbetween them so the input is taken 1:1, double quotes allow variable expansion (via $dollar sign) and command substition (via `backticks`) and protect mostly everything else, and the backslash protects the character following it. Mixed or nested quoting is often necessary and one of the most unintuitive things on earth, but for this howto, I will keep it as simple as possible.
Ok, let's do a "Hello World" in PHP, via Bash.
echo -e "<?php\n echo \"Hello World\";\n?>"
Output:
<?php
echo "Hello World";
?>
Why do I use the -e parameter? It allows the echo command to interpret C-style backslash escape sequences (like \n for a newline, \t for a tab). In addition, I'm enclosing the whole string in double quotes, as this allows for interpreting shell variables and escapes without messing up on most other stuff. The \n after the opening PHP tag is a line break, then two spaces follow for intendation. I have to escape the double quotes around "Hello World" ("protect" them) to not have them interpreted as string quoting, and output them literally instead. After that comes the semicolon that ends the PHP command, another newline and the closing PHP tag.
But, you might complain now, the PHP code itself might contain backslash quotes too! How to escape that, dude? Well, in that case we protect the backslash by writing a double backslash.
echo -e "<?php\n echo \"Hello \\\"World\\\"\";\n?>"
Output:
<?php
echo "Hello \"World\"";
?>
The parts with three backslashes in a row are a backslash protecting a backslash, followed by a backslash protecting a double quote.
Because of the "weak" double quoting, we can use shell variables and command substitution.
echo -e "<?php\n echo \"Script generated by $SHELL\";\n?>"
Output:
<?php
echo "Script generated by /bin/bash";
?>
<?php\n echo \"Script generated by $SHELL on `uname`\";\n?>"
Output:
<?php
echo "Script generated by /bin/bash on Linux";
?>
You can build on this from this point on: Just keep in mind that quoting with double quotes protects all characters except ", \, $, and `, so you have to escape them with a backslash if you want to output them literally.
You might want to have some script running on the server for the purpose of generating PHP code. Unfortunately, you cannot throw everything at Bash's string functions as-is because some special characters are used to denote expansion or redirection. One totally unexciting but have-to-know bash feature comes into play here, called quoting.
Quoting is the art of using single or double quotes or backslashes to protect a range of characters in a string from being interpreted by Bash. In short, single quotes protect everything inbetween them so the input is taken 1:1, double quotes allow variable expansion (via $dollar sign) and command substition (via `backticks`) and protect mostly everything else, and the backslash protects the character following it. Mixed or nested quoting is often necessary and one of the most unintuitive things on earth, but for this howto, I will keep it as simple as possible.
Ok, let's do a "Hello World" in PHP, via Bash.
echo -e "<?php\n echo \"Hello World\";\n?>"
Output:
<?php
echo "Hello World";
?>
Why do I use the -e parameter? It allows the echo command to interpret C-style backslash escape sequences (like \n for a newline, \t for a tab). In addition, I'm enclosing the whole string in double quotes, as this allows for interpreting shell variables and escapes without messing up on most other stuff. The \n after the opening PHP tag is a line break, then two spaces follow for intendation. I have to escape the double quotes around "Hello World" ("protect" them) to not have them interpreted as string quoting, and output them literally instead. After that comes the semicolon that ends the PHP command, another newline and the closing PHP tag.
But, you might complain now, the PHP code itself might contain backslash quotes too! How to escape that, dude? Well, in that case we protect the backslash by writing a double backslash.
echo -e "<?php\n echo \"Hello \\\"World\\\"\";\n?>"
Output:
<?php
echo "Hello \"World\"";
?>
The parts with three backslashes in a row are a backslash protecting a backslash, followed by a backslash protecting a double quote.
Because of the "weak" double quoting, we can use shell variables and command substitution.
echo -e "<?php\n echo \"Script generated by $SHELL\";\n?>"
Output:
<?php
echo "Script generated by /bin/bash";
?>
<?php\n echo \"Script generated by $SHELL on `uname`\";\n?>"
Output:
<?php
echo "Script generated by /bin/bash on Linux";
?>
You can build on this from this point on: Just keep in mind that quoting with double quotes protects all characters except ", \, $, and `, so you have to escape them with a backslash if you want to output them literally.
17 November 2009
Make commands behave nicely by default, using shell aliases
You have surely been in situations where a command needed an unwieldy parameter list to do things in a specific way, and editing a config or parameter file, or creating a shell script for the task, was not an option. I already wrote an article on how to search your command history, but in many cases you will not be executing the command interactively; it will be called from a script or such. Well, you are not out of luck. Let me show you one nice trait of bash aliases.
Your .bashrc might contain something like this:
alias ls='ls --color=auto'
This line defines an alias for the ls command, named ls. Weird? Not at all. Aliases override commands and builtins of the same name. The above example results in ls always displaying colorful directory listings, because Bash checks whether a word is an alias before looking for a builtin or command.
Another example: If you frequently ssh into boxes on your local network and start GUI programs on them, the following enables X forwarding by default.
alias ssh='ssh -X'
Aliases also work for programs that are started from the menu in a desktop environment. If you are over 25 and happen to like classical console games, meaning you probably have ZSNES installed, you can fix issues with missing audio using
alias zsnes='zsnes -ad sdl'
Add that to .bashrc, then log out and in and clicky-clicky on the icon.
Your .bashrc might contain something like this:
alias ls='ls --color=auto'
This line defines an alias for the ls command, named ls. Weird? Not at all. Aliases override commands and builtins of the same name. The above example results in ls always displaying colorful directory listings, because Bash checks whether a word is an alias before looking for a builtin or command.
Another example: If you frequently ssh into boxes on your local network and start GUI programs on them, the following enables X forwarding by default.
alias ssh='ssh -X'
Aliases also work for programs that are started from the menu in a desktop environment. If you are over 25 and happen to like classical console games, meaning you probably have ZSNES installed, you can fix issues with missing audio using
alias zsnes='zsnes -ad sdl'
Add that to .bashrc, then log out and in and clicky-clicky on the icon.
16 November 2009
Quick & dirty intro to Bash history search
So you typed that loooong incredibly useful command a week ago and no amount of pressing the Up key will unearth it, or you just want to save a few keystrokes on a command you use regularly? Let me introduce you to Bash's builtin history search, a feature that tends to be underused and only partly understood.
There are two ways for quickly searching the history: Incremental search and plain string search. The good thing about both is that you only need to know part of the command you typed, in most cases three or four consecutive letters are enough.
Ok. Let's say you are SSHing into your other box regularly using the command ssh mylogin@myotherbox. Open a terminal and hit CTRL-R. The prompt changes to say "reverse-i-search". Start typing what you search for. Chances are that as soon as you have typed "s" and another "s", it will fill in the ssh command for logging into myotherbox. Hit Enter and it executes the command. If you don't want to, cancel the reverse i-search with CTRL-G. Whatever you started typing before the search will still be there, nice!
If you had happened to ssh into other boxes and didn't get the right result, you can press CTRL-R several times during the i-search to go to the previous occurence (towards the start of the history), or CTRL-S to search towards the end of the history. Note that CTRL-S is often bound to stopping the terminal, but that can be fixed by issuing stty stop ^Q, which rebinds stopping to CTRL-Q.
Bash also has a plain non-interactive search mode that can be entered using ALT-P, or ALT-N in the unlikely case you want/have to do a forward search. The prompt changes to a simple colon then and you can cancel as always with CTRL-G. Type a few letters and hit Enter. The first match will be filled in at the prompt but will not execute, which is great because you can edit it first this way.
Well, there is also a third very non-interactive way of search: Type a bang (exclamation mark) followed by what you search for. !ssh will likely result in this:
$ !ssh
ssh mylogin@myotherbox
mylogin@myotherbox's password:
Useful for quickly repeating commands you use regularly, although dangerous if you don't exactly know what the bang-search will find and execute.
Subscribe to:
Posts (Atom)



