How to use terminal on Windows without going crazy…

How to use terminal on Windows without going crazy…

Last modified by Jakub Jirůtka on 2014-08-27, 18:19

Windows is really horrible system for developers and especially for devops. It doesn’t even have a usable terminal and shell, so working with command line is really pain in the ass. If you really don’t want to switch to any usable system (OS X, Linux, BSD…), then this guide should help you to setup somewhat reasonable environment – usable terminal, proper shell, ssh client, git and Sublime Text as a default editor for shell.

This is extended version of the guide that I’ve published on Gist.

Install stuff

  1. Download and install Git for Windows* with:
    • [✘] Use Git from the Windows Command Prompt
    • [✘] Checkout as-is, commit Unix-style line endings
  2. Download ConEmu Installer (stable or preview) and install x86 (32bit**) version.
  3. Download and install Sublime Text 3 – text editor for real coders. emoticon_wink
    • If you’re using 64bit Windows, then download the 64bit version. If you don’t know what the heck this means, just pick the 32bit version.

* Wait a moment… why Git? Well, every developer needs a Version Control System and git is the best one! However, the main reason is that “Git for Windows” is not just a git, it’s a bundle of some basic “unix utilities” – the easiest way to install it on Windows.

** Why 32bit version when you’re maybe running 64bit Windows? Well, just because I didn’t want to test this guide twice, or risk that something will be different on 64bit version and people start to complain…

Configure ConEmu

  1. Start ConEmu (press Win key, write ConEmu and hit enter), the fast configuration screen should appear on the first launch, check these settings:
    • [✘] Enable automatic updates
    • [✘] Stable
  2. Open Settings (Win+Alt+P) and set *:

    • Startup:
      • [✘] Specified named task: {Git bash}
    • Startup/Tasks:
      • Click on {Git bash} and replace "%ProgramFiles%\Git\bin\sh.exe... with:
        set LANG=en_GB.UTF-8 & set LC_ALL=en_GB.UTF-8 & "%ProgramFiles%\Git\bin\sh.exe" --login -i
    • Main:
      • [✘] Clear Type
    • Main/Confirm:
      • [_] Confirm creating new console/tab (Win+W, toolbar [+])
      • [_] Confirm tab closing
  3. Restart ConEmu.

* Or just import settings from this export instead.

Configure shell, ssh and git

  1. Generate SSH key, if you don’t have one yet:

    ssh-keygen
    • Use default key file location.
    • Enter some password to protect your SSH key! You’ll be prompted to enter this password after opening terminal, but just once per Windows session (i.e. only after Windows reboot).
  2. Enable SSH Agent Forwarding and set default username in .ssh/config:

    cd; echo 'ForwardAgent yes\nUser YOUR-USERNAME' >> .ssh/config

    Replace YOUR-USERNAME with your actual school username in lowercase and copy&paste it to the terminal.

  3. Download preconfigured .bashrc (just copy&paste to terminal):

    cd; curl https://gist.githubusercontent.com/jirutka/99d57c82fa8981f56fb5/raw/.bashrc > .bashrc

  4. Configure git:

    git config --global user.name "Your Name"
    git config --global user.email "your-username@fit.cvut.cz"
  5. Restart ConEmu.

Add your SSH key to LDAP

If you’ve got access to some server on Department of Development FIT, then you can store your public SSH key in the faculty LDAP. This is useful when you’re connecting to many servers – you don’t need to copy your SSH key to all these servers.

  1. Copy public part of your SSH key to clipboard:

    cd; clip < .ssh/id_rsa.pub
  2. Connect to some server using SSH:

    ssh SERVER-ADDRESS
  3. Use ssh-ldap-pubkey utility to add your SSH key to the faculty LDAP:

    echo 'INSERT-KEY-HERE' | ssh-ldap-pubkey add -

    Use Ctrl+V to paste your SSH key from clipboard in place of INSERT-KEY-HERE (don’t remove quotes around!).

Learn new tricks

Just some basic shortcuts and commands for a decent productivity.

ConEmu

  • Open new tab:
    • Win+W
  • Close the tab:
    • Win+Del
  • Switch to next tab:
    • Win+Alt+Arrow right
  • Switch to previous tab:
    • Win+Alt+Arrow left
  • Cycle tabs:
    • Ctr+Tab
  • Copy text from console to the system clipboard:
    • Press and hold Shift, use arrows to make a selection and then hit Ctrl+C.
    • Press and hold left mouse button, make a selection and release the button.
  • Paste text from the system clipboard to console:
    • Press Ctrl+V to paste the first line from the clipboard, or Shift+Insert to paste all the clipboard content (use with caution!)
    • Press right mouse button to paste all the clipboard content.

Bash

Alternative keys in parenthesis are environment-specific (works in ConEmu).

  • Autocomplete file/directory name:
    • Type first few characters of the file/directory name and then hit Tab.
  • Scroll your command history:
    • Arrow up and Arrow down
  • Search your commands history backwards:
    • Press Ctrl+R, start typing what you’re looking for; hit Ctrl+R again and again to scroll through history.
  • Move cursor to the beginning of the line:
    • Ctrl+A (or Home)
  • Move cursor to the end of the line:
    • Ctrl+E (or End)
  • Move cursor back (left) one word:
    • Alt+B
  • Move cursor forward (right) one word:
    • Alt+F
  • Remove one word before the cursor:
    • Ctrl+W (or Alt+Backspace)

Basic bash commands

Alternative commands in parenthesis are aliases specified in .bashrc file that you’ve downloaded before.

  • List content of the current directory:
    • ls (or ll)
  • Go up one directory:
    • cd .. (or ..)
  • Go to a subdirectory:
    • cd DIRECTORY
  • Go to the home directory:
    • cd
  • Connect to a remote machine as specified user using SSH (remote user may be omitted if it’s  the same as your default username configured in .ssh/config):
    • ssh REMOTE-USER@SERVER-DOMAIN
  • Open file in the default text editor (Sublime Text 3 if you’ve installed it):
    • edit FILE *
  • Copy content of a file to system clipboard (then you can paste it using Ctrl+V):
    • cat FILE > clip *

* This will work only on your local computer, not on a remote server via SSH!

Tags:
Created by Jakub Jirůtka on 2014-08-27, 17:20

My Recent Modifications


This wiki is licensed under a Creative Commons BY-SA 3.0 license
XWiki Enterprise 5.4.1 - Documentation