My USB stick setup

Some notes on setting a portable development environment in a USB stick. Ah well, let me start from the end. Here’s how my setup looks like currently :)

Portable Development Enviroment Setup

Portable Development Enviroment Setup

Directory structure in the device

\Documents — Place for all documents, ebooks, todo.txt etc..
\Documents\{Music, Videos, Pictures}

\Env — Place for Languages, CoreOS utils, Development enviroment
\Env\{Python26, Ruby191}
\Env\{CygWin, GnuWin32}
\Env\Bin                      – Homegrown scripts and utilities go here (mostly small .ps1 and .py files). We add this path to $env:PATH.
\Env\Path                   — Interesting external tools. E.g. ProcExp, Reflector etc.. We add this path to $env:PATH.
\Env\Env.ps1            – This file is sourced into powershell. Sets up paths. Source below.
\Env\Profile.ps1      – Setups some powershell customizations. See below.

\PortableApps — All other utilities etc. go here. PortableApps.com suite builds up a Menu from this folder. Cool stuff.
\PortableApps\{7zipPortable, gVimPortable, Console}
\PortableApps\{Git, PuttyPortable, WinSCPPortable}
\PortableApps\PortableApps.com

Softwares for the USB stick

Install Portable Apps Platform (download | for the brave souls, beta version is here)

Languages

Editors/Shells

  • GVim Portable (download) — doesn’t have Python + Ruby. Install this and the play the replace magic ;)
  • CygWin Portable (how to)
  • Console (download latest *_32bit.zip from here). ConsolePortable from PortableApps.com includes extra stuff which I don’t use.
  • Customized Powershell. See below.

Source control

  • MSysGit – Portable git installation (download PortableGit*.7z file)

Utilities

  • 7zip portable – Archive/Extract files (download)
  • MRemoteNG – Manages your remote desktop connections (download)
  • Putty – Telnet, SSH client (download)
  • WinSCP Portable (download)

Customized Powershell in Stick

Following modification requires powershell to be installed in the host machine. Comes by default with Windows 7. For other windows versions download here. Take my word, you will enjoy every minute w/ Powershell :)

Our goal here is:

  • Hook up powershell with Console
  • Setup Python and GIT paths appropriately

Modify \PortableApps\Console\Console.xml to start Powershell at start

 <tabs>
   <tab title="shell" use_default_icon="0">
     <console shell="%SystemRoot%\system32\windowspowershell\v1.0\powershell.exe -NoExit -NoProfile -File ..\..\Env\Env.ps1" Init_dir="" run_as_user="0" user=""/>
     <cursor style="5" r="0" g="255" b="0"/>
     <background type="0" r="0" g="0" b="0">
       <image file="" relative="0" extend="0" position="0">
         <tint opacity="0" r="0" g="0" b="0"/>
       </image>
     </background>
   </tab>
 </tabs>
</settings>

Contents of \Env\Env.ps1

## Portable start script
## Created: Sat 15 Jan 2011 01:45:57 PM India Standard Time
## Last Modified: Sat 15 Jan 2011 02:51:52 PM India Standard Time

Write-Host -ForegroundColor Green "--> Setup start"
Write-Host -ForegroundColor Green "--> Setting enviroment variables"

## Globals
# Environment variables
$env:PortableRoot = $(pwd).Drive.Root
$env:PortableEnv = Join-Path $(pwd).Drive.Root "Env"
$env:PortableApps = Join-Path $(pwd).Drive.Root "PortableApps"
$env:PortableDocs = Join-Path $(pwd).Drive.Root "Documents"

$env:TERM = 'cygwin'
$env:LESS = 'FRSX'
Write-Host -ForegroundColor Green "     > Portable Root: $env:PortableRoot"
Write-Host -ForegroundColor Green "     > Portable Env: $env:PortableEnv"
Write-Host -ForegroundColor Green "     > Portable Apps: $env:PortableApps"
Write-Host -ForegroundColor Green "     > Portable Docs: $env:PortableDocs"

# Languages
$env:PATH = "$env:PortableEnv\Python26\App;$env:PortableEnv\Python26\App\Scripts;" + $env:PATH

# GIT
$env:PLINK_PROTOCOL = "ssh"
$env:GIT_INSTALL_ROOT = "$env:PortableApps\git"
$env:PATH += ";$env:GIT_INSTALL_ROOT\cmd"

# Load custom profile
$customProfile = $(Join-Path $(Get-ChildItem $MyInvocation.MyCommand.Path).Directory.FullName "\Profile.ps1")

if (Test-Path $customProfile)
{
    Write-Host -ForegroundColor Green "--> Loading custom profile: "$customProfile
    . $customProfile
}

Write-Host -ForegroundColor Green "--> Setup complete`r`n"

Contents of \Env\Profile.ps1

## Portable Profile
## Created: Sat 15 Jan 2011 02:15:57 PM India Standard Time
## Last Modified: Sat 15 Jan 2011 03:02:54 PM India Standard Time

## prompt
function prompt
{
    $date = $(date)
    $dateString = $date.Hour.ToString()+":"+$date.Minute.ToString()+":"+$date.Second.ToString()
    Write-Host $dateString" ["$(get-location)"]" -foregroundcolor green
    Write-Host $((get-history -count 1).Id+1)"$" -nonewline
    return " "
}

## Aliases
#set-alias la ls -recurse
rm -force alias:where
rm -force alias:cd

set-alias cal gadget-calendar
set-alias cd pushd;set-location
set-alias cd- popd
set-alias grep select-string
set-alias l get-childitem
set-alias whereis where
set-alias wc measure-object

## Globals
# Environment variables
$env:Path = "$env:PortableEnv\Path;$env:PortableEnv\GnuWin32\bin;" + $env:Path
$env:SCRIPTDIR = Resolve-Path("$env:PortableEnv\bin").ToString()
$env:EDITOR = "gvim"

# Script Directory
$env:PATH += ";"+$env:SCRIPTDIR+";."

## User applications
# ACK
function ack
{
    & $env:PortableApps\git\bin\perl.exe "$env:PortableEnv\bin\standalone-ack" $args
}

# YaGTD
function gtd
{
    & $env:PortableEnv\Python26\App\Python.exe $env:PortableEnv\Python26\App\Scripts\yagtd.py -q $args $env:PortableDocs\todo.txt
}

The script \Env\Env.ps1 provides following environment variables for your scripting needs.

  1. $env:PortableRoot  – Root of the USB stick
  2. $env:PortableDocs  – Path to \Documents
  3. $env:PortableEnv    – Path to \Env
  4. $env:PortableApps — Path to \PortableApps

Enjoy the portability.

Down the memory lane,  last time I used usb sticks was in 2005-8. Used to be a life saver for the labs, the days before project/ppt deadlines (all kinds of file sync, backup and what not. Poor man’s dropbox :D . Ok, DC++ did revolutionize things too).

My primary toolset then was DevC++, VNCViewer/WinSCP/Putty (escape switch for boring labs, to connect to dorm desktop :P ). I was quite a bit into Java then, so Eclipse was there too. Good ol’ times.

Well this time, primary reason was my GTD setup. More on that in another post.

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s