Monday, January 19, 2015
Thursday, January 08, 2015
Chances are high when you happen to use a cool new command while working in linux or mac shell and you are not sure you will remember it next time. Usually those cool commands tend to be messy. How about checking the git log with the graph and branch names.
Now this may be alright with many people. But I usually forget/hate long commands (no matter how awesome they are) and what I usually end up doing is setting up an alias.
You can do that in two sets.
- Add "alias gl=git log --graph --oneline --decorate" to your ~/.bash_profile.
- Open a new terminal or refresh the current terminal with "source ~/.bash_profile"
Now thats a pain. Specially if you happen to find "cool commands" so often and you just have to stop what you do and do that two steps every time when you need to add an alias. And remember, setting up aliases can be highly addictive. You basically end up creating whole new your DSL sort of thing.
So I thought how nice it would be if I can setup an alias using a single command. The goal is to create a command which does both steps for you. When you in a terminal session, when you find out a cool new long command, you just call our new tool, it will add the new alias to .bash_profile and reset the current session all at once without we have to do anything, making our new command available instantly.
Introducing the command aset.
If my long cool command to see git log with graph is this >> git log --graph --oneline --decorate
I will set an alias to that exact command as gl
Thats it. The new command gl should be available right after we press enter.
To get aset from follow instructions in my github,
Or simple run this command in your shell. (tested in OS X)
Some aliases to start with. Please note that its fun and easy to add more and more.
Happy aliasing !!
Saturday, January 03, 2015
See all installed java versions, (Please note the capital V, simple v will be used later on for different purpose)
Now you know whats available. All you need to do now is change your ~/.bash_profile to set JAVA_HOME. Before we do so, lets see how we can use /usr/libexec/java_home tool to retrieve JAVA_HOME paths of each versions.
Matching Java Virtual Machines (4): 1.8.0_25, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home 1.7.0_71, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home 1.6.0_65-b14-466.1, x86_64: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home 1.6.0_65-b14-466.1, i386: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Following command gives JAVA_HOME path of a given java version installed.
asanga@localhost:$ /usr/libexec/java_home -v 1.8 /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home
Now, lets add that trick to our ~/.bash_profile.
asanga@localhost:$ /usr/libexec/java_home -v 1.7 /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home
Now you can uncomment the version you need when you need.
export JAVA_HOME=`/usr/libexec/java_home -v 1.8` #export JAVA_HOME=`/usr/libexec/java_home -v 1.7` #export JAVA_HOME=`/usr/libexec/java_home -v 1.6`