Skip to content

Instantly share code, notes, and snippets.

@ruskotron
Last active December 18, 2015 04:59
Show Gist options
  • Save ruskotron/5729776 to your computer and use it in GitHub Desktop.
Save ruskotron/5729776 to your computer and use it in GitHub Desktop.
Windows command-shell initialisation - if you're used to developing under linux and you want to enjoy some of the same command-line luxuries under windows unfortunately there's nothing you can do to get command-line history beyond your current seesion :-(
rem lines starting with "rem" are commented out similar to '#' in unix-land
rem so you want to have a useful windows command-line?
rem put this file in some standard location like "C:\myscripts"
rem then right-click, "New > Shortcut" and enter the following for location:
rem C:\Windows\System32\cmd.exe /K "C:\myscripts\mycmd.cmd"
rem give it a name you like and then 'finish'
rem then right-click on the shortcut, go to "Properties" and set "Start in:" to be your "Home Directory"
rem I've tried to explain some of the peculiarities of windows "batch-file" and "doskey" scripting below ...
rem the commands "echo off" or "echo on" disable/enable command-line echoing
rem lines starting with @ will NOT be echoed to shell output regardless of whether echo is on or off
@rem disables echoing of the commands in this script
@echo off
rem initialise cmd.exe title bar to current working directory
title mycmd: %CD%
rem "echo." simply writes a single newline!
echo.
echo ****************************************************
echo **** configuring custom development environment ****
echo ****************************************************
rem reenable echoing so that I can see how my environment variables are being set.
@echo on
@echo.
@echo !!! JDK Configuration Options !!!
@rem HEY! look how I preceded these rem-lines with '@' because echo is 'on'
@rem in windows "set variable=value" works similarly to unix-land for environment variables
@rem look how we reference other variables though ...
@rem ... we surround name with %...% instead of preceding with '$' ...
@rem ... and we separate PATH expressions with ";" (semicolons) instead of ":" (colons)!
set JAVA_HOME=c:\Program Files\Java\jdk1.6.0_43
set PATH=%JAVA_HOME%\bin;%PATH%
@echo.
@echo !!! ANT Configuration Options !!!
set ANT_HOME=C:\Program Files\apache-ant-1.9.0
set PATH=%ANT_HOME%\bin;%PATH%
@echo.
@echo !!! Maven Configuration Options !!!
set M2_HOME=C:\Program Files\apache-maven-3.0.5
set M2=%M2_HOME%\bin
set PATH=%M2%;%PATH%
@echo.
@echo !!! Python Configuration Options !!!
set PYTHON_HOME=C:\Python27
set PATH=%PYTHON_HOME%;%PATH%
@echo.
@echo !!! Groovy Configuration Options !!!
set GROOVY_HOME="C:\Program Files (x86)\Groovy\Groovy-2.1.3"
set PATH=%GROOVY_HOME%\bin;%PATH%
@rem below here we will configure aliases, similar to the 'alias' command
@echo.
echo !!! Aliases !!!
@rem I constantly get confused by using 'dir' instead of 'ls' so alias that here
@rem (note that $* relays all of the original command-line options)
doskey ls=dir $*
@rem If I want to edit this configuration quickly and easily from the command-line
@rem (the variable %0% is the filename of THIS script)
doskey mycfg=notepad %0%
@rem the 'type' command works similarly to 'cat' in unix
@rem (windows already has 'more' command that works similarly)
doskey cat=type $*
@rem windows 'cd' command is very poor compared to his unix cousin ...
@rem ... this alias attempts to remedy some shortcomings ...
@rem ... firstly there are multiple commands to do this, each separated by "^&^&" ...
@rem ... the first command uses 'pushd' to save current directory so that 'popd' command
@rem can be used to return to previous directory similar to "cd -" in unix ...
@rem ... then the actual 'cd' command is invoked using $* to pass the command-line args ...
@rem ... and finally the window-title is set to "mycmd: <new-dir>" so I can tell it apart
@rem on the windows task-bar!
doskey cd=pushd . ^&^& cd $* ^&^& title mycmd: $*
@rem this is just a command of my own
doskey splat=java -jar "C:\scripts\mycoolscript" $*
@rem and finally switch the command echos off again
@echo off
rem look I no longer need to prefix my rem-lines with '@'!
echo.
echo %0% Ready!
rem initialisation complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment