Share your file-opener script - Programming On Unix
Users browsing this thread: 5 Guest(s)
|
|||
Most of us have an handy script for opening files and/or links given as arguments. This is, sometimes, one of our most used scripts. Use this thread to share your file-opener or link-opener scripts and steal ideas from others.
Here is mine, I call it xopen. Code: #!/bin/sh It gets its configuration from a file specified in the environment variable $MIMEFILE (or after the -c option). Each line in this file is composed by a mimetype or a file extension followed by a colon, followed by the command that opens a file with that mimetype or extension. Here is my $MIMEFILE: Code: # web Now share yours! |
|||
|
|||
Mine is self-contained, though I like your way to use the mailcap entry… I'll look this out later.
I cleaned up mine a bit. The cool stuff about it (I think) is that you can pipe data to it and open it. Not only URIs: Code: curl -s 'https://random.tld/image.png' | plumb -s This would cache the file locally, and open it with the according mime entry. Here is the full script: Code: #!/bin/sh |
|||
|
|||
I rely on the freedesktop utility xdg-open as it already has full integration with mime types and desktop files. I kind of pointed it a bit in this discussion about default programs.
So what I usually do is xdg-open, and if it doesn't call the program I want then I can switch it using mimeopen -a. In the case where my program isn't listed, I create a desktop file in ~/.local/share/applications, then update-desktop-database. Most of the time, this solves my issues, otherwise I can dive into adding my own mimetype in ~/.local/share/mime/application. |
|||
|
|||
Almost on-topic: In a C++ software of mine (which I really should develop further... some day), I wrote a function to open a text file with the default editor. I would guess that, if one removes the VISUAL/EDITOR checks, it fulfills this thread’s needs as well.
Note that sanitizing the filename needs to be done beforehand. Better don’t make this function publicly callable. :) Code: inline bool openWithEditor(const char* filename) { -- <mort> choosing a terrible license just to be spiteful towards others is possibly the most tux0r thing I've ever seen |
|||
|
|||
Here is my current "go to what I'm looking at" emacs function: https://github.com/neeasade/emacs.d/blob...el#L54-L60
The goal is to handle various fallbacks, through org links, files, urls, and code definitions. |
|||
|
|||