How to open non text files in Cygwin? - linux

I am trying to open image files, pdf files and music files using Cygwin, a terminal that provides Linux functionality in Windows. So far I have not successfully executed a command that would accomplish what I want. I can only open text files at this moment using vim text editor.
Edit: Thanks for the comments. I am looking to open files using appropriate windows applications. Also, I do not know how I can figure out whether XServer is already installed and why would I need XServer to resolve my issue in the first place.

Use the cygstart utility, e.g.,
cygstart foo.bmp
will open up the image file in Paint.
It’s in the cygutils package, which I believe is installed by default. It has a man page that shows that you can use it to open URLs in your browser, among other things.

Related

Is it possible to change my default browser (lynx) on a remote server (Linux RedHat 4.4.7-17)? (Plotting in Julia using Gadfly)

I'm using julia and gadfly to draw some plots on a remote server (connected through Putty) and the plots are supposed to open in my default server. They open in lynx, and so don't look like anything really. I'm presuming lynx is the default browser on my work server, and I was wondering whether there is any way to open them in chrome or firefox? I'm not the server administrator and have no permission to use all commands (ie sudo etc).
When trying to use xdg-utils I get an error saying "command not found" and I don't have any applications in my /usr/.local/applications nor could I find a mimeapps.list in the directory.
Is there anything I can do to open these plots in another internet browser instead of lynx? Thank you!
The order of preferences
Gadfly plots on Julia's display if it can (for example if you're using an interactive graphical notebook with Jupyter).
If there's no suitable way to render on the REPLDisplay, Gadfly will save the plot into a file, then trigger some platform-specific "open this file" logic.
Julia's own display
This is almost certainly the best option. If you run your Julia code in an environment that knows how to display your plots (such as an interactive graphical notebook with Jupyter), then there's nothing more to do.
If you must run your Julia code from a text prompt, you can use a text-based backend renderer, or deal with the fallback process.
xdg-open
Gadfly's fallback display code uses xdg-open to display plot files on Linux-based systems.
The xdg-open tool is part of a package called xdg-utils. The xdg-utils package contains several commands, but xdg-utils is not itself a command -- that's why trying to run "xdg-utils" fails with "command not found".
xdg-open has its own chain of opening things: it will try the opening procedures specific to GNOME, KDE, or whatever desktop environment you're using. It falls back to something called "perl-shared-mimeinfo".
Another tool in the xdg-utils package is xdg-mime, which can query the current file associations as well as change them. You need administrator privileges to change system-wide associations, but you don't need any special permissions to add your own per-user associations.
Since Gadfly is writing to a file then asking xdg-open to open the file, you'll need to handle the filetype (rather than "browser" or URL handler). It might look something like this for HTML files:
$ xdg-mime default mybrowser.desktop text/html
Which computer runs the browser?
Now, you mention that you're using SSH and PuTTY to connect to this server. PuTTY provides a text-based interface to your server -- even if the server had a graphical browser like Firefox installed on it, PuTTY couldn't display it. (You'd need something else on your computer that the server could use to draw the browser window.)
It would probably be more comfortable to use your computer's own browser.
So what do I do?
Launching a browser is a bit weird for a server computer anyway, and it can be fiddly to make it happen. So my recommendation would be either:
Skip PuTTY, display directly in a Jupyter notebook.
Save your output as HTML (or SVGJS) somewhere that your computer's browser can access it.

How can I open a local file with a local program through my browser?

On my webpage, I have placed a link to a local file (e.g. "text.docx" on my local HD). I would like to double click on this link, and have a third party software which is installed locally on my PC (e.g. Microsoft Word) open it.
I would like to be able to do this with Firefox and Google Chrome. Obviously, I am a newbie to web programming.. can somebody show me the way? I have looked around and had the impression that I need to write and add an extension, maybe?
Thanks for your time. Jakob
This is only possible if you know either the absolute path to the file or the relative path from whatever working directory your browser runs from. You the create a link with
href="file://relative/path/to/file/text.docx"
or
href="file:///absolute/path/to/file/text.docx"
and any modern browser will query the system database for the mimetype of the file depending on its extension, thus prompting to open the correct application.
EDIT
I inawarently introduced a unixism in the previous code: Distinction bewteen absolute and realtive paths as above works well on current *nix desktops, but in Windows an absolute path will most likely look like
href="file://C:/drive/absolute/path/to/test.docx"
Mind the 2 (not 3) slashes a the beginning, and the forward (not backward) slashes.
As far as I know, you can't link to local files from a website. If you upload it to where your files are, you could then be able to download it.
I was able to execute code locally, using Firefox, by adding an extension which used the XPCOM interface. One such extension was "commandrun", and may be found here: https://github.com/aabeling/commandrun .

Automated Context Switching Between Projects via SSH and Multiple Terminals

I'm looking for some guidance on an approach to automate the process of quickly switching between projects.
Putty Windows (2 of them):
Vim with project.session open (multiple tabs)
IPython open to the working directory of the project
What I want to automate in its respective windows:
Save all files, save session, close vim, change working directory of vim to next project, open related project session.
Close ipython (as I often restart it during development and want a fresh instance), change directory to next project'ss location, open a new ipython
A magic solution would be a single command that would change the state of both putty windows. However, since I have no idea how that would be done my current approach would be:
Attempt to figure out how to bind all that Vim stuff to a key press or a custom vim script that is used like: :SwitchProj "projectName"
Write a bash script or find a bash command that will allow me to type as little as possible to perform the directory switch and open new ipython interpreter.
As I have very little experience on Linux and SSH I would be interested to know how other's have solved this problem or would approach it!
I believe that the Linux screen command should satisfy you. Google gives you many tutorials, like this one.
I sadly confess that I am not very familiar with screen. Learning it is in my todo list
If you use the Gnu Emacs editor, you can also open many shell buffers inside (and other interactive buffers, like gdb sessions, compilations, grep search) and edit many files. I do that very often. You can use emacs thru a tty interface, such as provided by ssh.
You could also use ssh with e.g. -X to also redirect X11 windowing. For you, that means that you'll need to run an X11 server on your local Windows machine.

linux script to dump web page from a browser to image file

Fo you know any script to make a screenshot of rendered web browser contents to an image file?
For now I've tried:
wkhtmltoimage - doesnt dump flash
cutycapt - problems to compile on my hosting
khtml2png - problems with compilation
At home I'm using Ubuntu, hosting is on Debian
Never got around to trying myself, but check out http://en.wikipedia.org/wiki/Xvfb. You should be able to run Firefox in xvfb and just save an image of the whole virtual window.
The xwd(1) program can capture a running browser window's contents and save it to a file or stdout:
xwd -out /tmp/image.out
You can view it again with xwud(1).
The ImageMagick import(1) command can also capture X11 windows or any rectangular portion of the screen. It also supports many output file formats, which might be nicer than the standard xwd format.
PDFMyURL - really useful except bug with header sending. They have
simple "API". Unless you need simple grab the screen from WebKit, it
is best solution IMHO
If you have own VDS, I recommend to discover PhantomJS See rasterize.js
UPD: I have just seen this is necropost Z)

Compatibility of x-www-browser

I want to open html files from a shell script. I know that Ubuntu has a command x-www-browser that will open the default browser on the system. I also found via some Googling that the command is part of the debian system. I was wondering if the command is available on non debian based distros. If it isn't is there a standard way of opening an html file in the default browser on a linux OS via command line? Note that I'm using Bash.
If you are wanting to open an HTML file that is local (and maybe even remote, I'd have to check), you can use xdg-open. This is the rough equivalent to "double-clicking" on a file to open it, so it's not limited to html files. Since you want to always open in the user's default browser, this would be the same as if they just opened it themselves.
Of course, if they have their system set up to have HTML files open in a text editor (like I did for awhile), this would backfire. But that's pretty rare.
Quick update
I just checked and xdg-open http://google.com brought up Google in Firefox (my default browser). So it does work for non-local files.
You could use xdg-open.

Resources