Monday, January 25, 2010

Command Line Open in UNIX

On OS X I can just "open" any file. On Windows, I can use "start". And on Linux? On modern installations, the "xdg-open" command works just fine. Unfortunately - this is not always the case. And I don't want to remember different commands for different machines. So here is the ultimate open alias setting for bash, for all systems that I use (it can be easily extended for other environments).


 
conditional_alias() {
  UNSET=false
  alias $1 > /dev/null 2>&1 || UNSET=true
  [ x$UNSET = xtrue ] && which $2 > /dev/null 2>&1 && alias $1=$2
}
 
conditional_alias open gvfs-open
conditional_alias open xdg-open
conditional_alias open gnome-open
conditional_alias open exo-open
uname | grep MINGW > /dev/null 2>&1 && alias open=start

No comments:

Post a Comment

Home

Followers