Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open file in default editor from bash

How do I open a file my script generated with the default GUI editor with bash?

On OS X there is the command open, but as far as I know that doesn't exist on linux. What is a good cross-platform alternative?

(executing open somefile.ext on OS X does the same as if I double clicked the file in Finder).

like image 402
Jawap Avatar asked Nov 29 '12 14:11

Jawap


3 Answers

Mostly close to this is xdg-open:

$ xdg-open somefile.ext
like image 88
Slava Semushin Avatar answered Oct 23 '22 23:10

Slava Semushin


On linux you have kde-open and gnome-open for specific desktop environments, and xdg-open is more generic but must still be run from a DE.

On windows, (obviously not bash but cmd.exe), I believe the similar command is start.

With bash a cross-platform code could be:

if which xdg-open &> /dev/null; then
    xdg-open $file       # linux
else
    open $file           # mac
fi
like image 5
Antoine Avatar answered Oct 23 '22 21:10

Antoine


On your .profile

export EDITOR='~/bin/mate -w'

and your bash use this editor

like image 1
Kamber Avatar answered Oct 23 '22 22:10

Kamber