Skip to content

Instantly share code, notes, and snippets.

@denmerc
Forked from LukasKnuth/README
Created September 9, 2012 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save denmerc/3686503 to your computer and use it in GitHub Desktop.
Save denmerc/3686503 to your computer and use it in GitHub Desktop.
A simple script that helps setting up your portable tools in the msysgit-shell.
-- Add Portable software to your msysgit-PATH --
If you like to work with your *nix shell even under Windows, you'll
likely use the git-bash provided by msysgit a lot.
A problem might be, that you don't have your tools in the PATH of that
shell and therefore can't use them. Those tools might be on the same
USB-drive as the git-shell, so you would have to adjust the PATH
(if you're allowed to) every time the drive-letter changes.
So, let's make it easy to add your tools to the git-shell PATH!
--- Adding the script ---
Setting up the tools in your PATH is simply done in a shell-script by
using the "export"-command.
To make the script ("env_setup.sh") execute every time the git-shell is
started, you'll want to put the script into the "etc/"-directory in your
msysgit-folder.
After that, you'll need to edit the "profile"-file, which is executed by
the shell every time it's launched.
Add the following line at the end of the file:
# Setup the environment-variables
. /etc/env_setup.sh
This will execute your "env_setup.sh"-script every time you start the git-
shell.
--- Adding the tools ---
Now that we have set up the script, let's add our tools to the PATH.
Open the "env_setup.sh"-script in your favorite editor and add the
directories your tools are in to the PATH by using the
"export"-command. The file already contains some examples of how
this can be done.
If you want to dynamically add applications from your USB-drive to your PATH,
you can use the "FLASH"-variable, which will contain the USB-drive-letter
the script (e.g. your msysgit) is on. The script also contains examples of
how you can use it.
---- Have fun! ----
#!/bin/bash
# Resources:
# http://stackoverflow.com/questions/623518
# http://stackoverflow.com/questions/59895
# http://markashleybell.com/articles/portable-git-windows-setting-home-environment-variable
# Get the directory this script is in:
DIR=$(cd $(dirname "$0"); pwd)
# Get only the Flash-Drive letter (e.g. "F")
FLASH=${DIR:1:1}
echo "We determined your USB-drive to be on $FLASH:\\"
# Set the home-path to the Flash-drive to get portable SSH-keys:
# --- You'll want to change this to your prefered Home-directory!
export HOME=/$FLASH/PortableApps/git/home/luke
echo "I set your Home-directory to '$HOME'";
### --- EXAMPLES ---
# Set the Java-Home variable to a JDK on USB-Stick:
export JAVA_HOME=/$FLASH/JDK1.6
# Add the Java-Tools to the JDK-folder:
export PATH=$PATH:/$FLASH/JDK1.6/bin
# Add a Maven from your USB-drive to the PATH:
export PATH=$PATH:/$FLASH/PortableApps/apache-maven/bin
# Add Node.js from the local pc to your PATH:
export PATH=$PATH:/c/Programms/nodejs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment