Showing posts with label terminal. Show all posts
Showing posts with label terminal. Show all posts

November 23, 2014

Replacing Windows cmd terminal with Console2 and Cygwin shell

In my last post I set up Cygwin to emulate a UNIX environment. We now have some added features that can be used via command line, but at the end of the day, Cygwin's shell is merely being invoked from the default Windows terminal. Yuck.

Console2 is an open-source replacement for Windows' native terminal. "Features include: multiple tabs, text editor-like text selection, different background types, alpha and color-key transparency, configurable font, different window styles". So basically, it is all the goodness of UNIX terminals brought to Windows. As of the time of this writing, the last update to this software was done over a year ago, yet there are still 5000+ downloads a week from SourceForge - a great testament to its ongoing popularity.

After downloading the 32-bit package (don't bother looking for the nonexistent 64-bit version), simply extract the Console2 folder to your Program Files directory, and run the Console.exe program within. You should see something like this:


Ok... now it just looks like a windows shell inside our new terminal... which is exactly what it is, and is exactly the opposite of how Cygwin is currently running a UNIX shell inside the Windows terminal. Let's hook the two up!

Instead of invoking cmd to access the Windows terminal, you'll now be using Console2 as its replacement, so pin it, desktop it, shortcut it, whatever - you'll be using it from now on. In Console2's menu, select Edit -> Settings... and from the Console setting in the sidemenu, point the unconfigured Shell to Cygwin.bat. Note that you may have to view All Files in the Files of Type dropdown:


It also won't hurt to set up a few sane copy/paste/mouse commands, and these can be done from the Hotkeys and Hotkeys -> Mouse settings. It is strange that Console2 isn't configured out-of-the-box to select text with the mouse cursor, but this is a nice quality-of-life improvement that we take for granted on a Unix terminal. As for copy/paste shortcuts, don't choose Ctrl+C for copying. Cygwin seems unable to distinguish between the shell being process-locked versus not, so Ctrl+C cannot be used for both copying and halting - the user definition overrides the innate process-halting definition.

Close Console2 after saving your settings, and reopen it to Cygwin's glorious UNIX shell within the enhanced goodness of Console2!

November 22, 2014

Setting up Git, SVN, curl and SSH on Windows using Cygwin terminal

I have previously mentioned that on my home computer, which is a Windows-running machine, I use Cygwin shell with a Console2 terminal. I have gotten used to Unix commands and infrastructure as I use them at work, and the Windows CLI just felt... well, flat in comparison.

Cygwin and Console2 are a nice remedy to implement a familiar interface for Windows. Let's start with Cygwin.

In their own words, Cygwin is "a large collection of GNU and Open Source tools which provide functionality similar to a Linux distribution on Windows". And frankly, this is the least finicky way I've been able to use Git on Windows. A lot of other GUI-based Git interfaces are pretty bad, and it's always better practices to learn and know the command line commands. So, speaking of, once you downloaded Cygwin, you choose your install directory, as well as a downloaded packages directory - it is here that "modules" such as Git gets installed into Cygwin. Get to know and love the Packages interface in Cygwin, chances are that if you are missing a module and need to install it later, you will be running Cygwin's installation program again (which now skips right to the packages window) to add what you need.

For a first-time install, I usually kick off my setup with a few choice packages such as:

  • vim (ironically for a UNIX emulator, this is actually not enabled by default)
  • OpenSSH
  • AutoSSH
  • PHP interpreter
  • curl
  • PHP-curl
  • Git (be sure to select the ca-certificates and libsasl2 packages as well - oddly they are not chosen as dependencies (unless you install the curl package as above). See here for more info, else you'll be running into "cannot open shared object file: No such file or directory" HTTPS git errors!)
  • Git/SVN
  • lib-mcrypt

These make it convenient to run commands straight from the Cygwin shell, for example if I need to run a quick cURL call or something. The SSH client is pure command line, so no need to fiddle around with crappy Windows GUI clients or yet another terminal emulator like PuTTY.

After selecting your desired Cygwin packages, you can complete the installation, noting the prompt to install dependencies for your selected packages. I usually go back and disable a few at this point, because - for example - blanket enabling the entire PHP5 package would then enable other packages like PHP5-apache2, which then have their own dependencies like the large Apache2 package which I personally won't need at all.

After installing, you can open your Cygwin shell, and see something like this message on the first load:
Copying skeleton files.
These files are for the users to personalise their cygwin experience.

They will never be overwritten nor automatically updated.

'./.bashrc' -> '/home/User//.bashrc'
'./.bash_profile' -> '/home/User//.bash_profile'
'./.inputrc' -> '/home/User//.inputrc'
'./.profile' -> '/home/User//.profile'

User@location ~
$ |

Right now, you're probably thinking that it's nice to have a UNIX shell, but the default Windows terminal that still wraps it is not very nice. I am of the same opinion. In the next post we will spruce things up a bit with Console2, entirely replacing the vanilla cmd terminal that the Cygwin shell still defaults to, and in a future post go over some Cygwin-specific tips.

April 28, 2014

Bash shell: Incremental history searching

From using Git, Linux/Ubuntu apt-repositories, or general Bash folder navigation, you may have noticed that pushing the tab button halfway through typing an item/folder name will autocomplete it if it exists. Similarly, we can build an autocomplete feature for user commands that have been entered in the past! They are obviously stored in history somewhere, because you can already chronologically "scroll" through every single command you've issued, or just see it all by entering history. It would be nice to have a quick way to access something specific, complex or lengthy, especially if you already know how it starts.

All you need to do to find a previous command, is to start entering the first few letters of it, then you can navigate all commands you previously issued that started with your entered phrase, by using the up/down arrows! Here's how you set it up:

In terminal, open or create:
gedit  ~/.inputrc

Copy/paste the following there, and save (you may also have to close and reopen a terminal, or reload this way):
"\e[A": history-search-backward
"\e[B": history-search-forward
"\e[C": forward-char
"\e[D": backward-char

And done! Now, for example, if I am now looking for the command...
sudo apt-get update

...all I need to do is enter the first few letters, something like...
sud

...and scrolling up/down through my now-selective bash history will allow me to easily locate the command in its entirety for use again!

Adapted from: Ubuntu User Community