MacOS has a nice “open” command that will open any document with any application from the command line. I hacked my own for Linux for a bash shell:


TEMP=`getopt -o a: -- "$@"`
if [ $? != 0 ] ; then exit 1 ; fi
eval set -- "$TEMP"
while true ; do
case "$1" in
-a) COMMAND=$2 ; shift 2;;
--) shift ; break ;;
*)echo "should not happen" ; exit 1 ;;
esac
done
if [ $COMMAND ]; then
nohup $COMMAND $@ > ~/.s1 2> ~/.s2 &
else
/usr/bin/xdg-open $@
fi

4 Comments »

  1. If you are running GNOME, you can also use the command “gnome-open”.

    Comment by Jo Vermeulen — 22/9/2008 @ 4:06

  2. Hmmm, it’s not completely equivalent because “gnome-open” doesn’t allow you to choose the application you want to use, it always uses the default one.

    Comment by Jo Vermeulen — 22/9/2008 @ 4:54

  3. And… if a given file type has no default application? Then gnome-open fails.

    Comment by Daniel Lemire — 22/9/2008 @ 6:22

  4. Plus, what if you are not using gnome?

    Comment by Daniel Lemire — 22/9/2008 @ 6:23

Leave a comment

Warning: When entering a long comment, please ensure that you make copy of your text prior to submitting it. If the server should fail or if you hit a bug, you might lose your work. I am not responsible for your lost effort.

To spammers: I carefully review every single post and make sure that spam gets deleted. You are wasting your time if you are manually entering spam using this form. Read my terms of use to see what I consider to be abusive.

Example: duo plus septem is '9'. The numbers are expressed in latin numerals but you should give your answers using ordinary digits.

 

« Blog's main page

Powered by WordPress