github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/core/open/open_doc.yaml (about)

     1  - DocumentID: open
     2    Title: >+
     3      `open`
     4    CategoryID: commands
     5    Summary: >-
     6      Open a file with a preferred handler
     7    Description: |-
     8      `open` is a smart tool for reading files:
     9      
    10      1. It will read a file from disk or a HTTP(S) endpoints
    11      2. Detect the file type via file extension or HTTP header `Content-Type`
    12      3. It intelligently writes to STDOUT
    13        - If STDOUT is a TTY it will perform any transformations to render to the
    14          terminal (eg using inlining images)
    15        - If STDOUT is a pipe then it will write a byte stream with the relevant
    16          data-type
    17      4. If there are no open handlers then it will fallback to the systems default.
    18         eg `open` (on macOS, Linux), `open-xdg` (X11), etc.
    19    Usage: |-
    20      ```
    21      open filename[.gz]|uri -> <stdout>
    22      ```
    23    Examples: |-
    24      ```
    25      » open https://api.github.com/repos/lmorg/murex/issues -> foreach issue { out "$issue[number]: $issue[title]" }
    26      ```
    27    Flags:
    28    Detail: |-
    29      ### File Extensions
    30  
    31      Supported file extensions are listed in `config` under the app and key names of
    32      **shell**, **extensions**.
    33  
    34      Unsupported file extensions are defaulted to generic, `*`.
    35  
    36      Files with a `.gz` extension are assumed to be gzipped and thus are are
    37      automatically expanded.
    38  
    39      ### MIME Types
    40  
    41      The `Content-Type` HTTP header is compared against a list of MIME types, which
    42      are stored in `config` under the app and key names of **shell**, **mime-types**.
    43  
    44      There is a little bit of additional logic to determine the Murex data-type to
    45      use should the MIME type not appear in `config`, as seen in the following code:
    46  
    47      ```go
    48      {{ include "lang/define_mime.go" }}
    49      ```
    50  
    51      ### HTTP User Agent
    52  
    53      `open`'s user agent is the same as `get` and `post` and is configurable via
    54      `config` under they app **http**
    55  
    56      ```
    57      » config -> [http]
    58      {
    59          "cookies": {
    60              "Data-Type": "json",
    61              "Default": {
    62                  "example.com": {
    63                      "name": "value"
    64                  },
    65                  "www.example.com": {
    66                      "name": "value"
    67                  }
    68              },
    69              "Description": "Defined cookies to send, ordered by domain.",
    70              "Dynamic": false,
    71              "Global": false,
    72              "Value": {
    73                  "example.com": {
    74                      "name": "value"
    75                  },
    76                  "www.example.com": {
    77                      "name": "value"
    78                  }
    79              }
    80          },
    81          "default-https": {
    82              "Data-Type": "bool",
    83              "Default": false,
    84              "Description": "If true then when no protocol is specified (`http://` nor `https://`) then default to `https://`.",
    85              "Dynamic": false,
    86              "Global": false,
    87              "Value": false
    88          },
    89          "headers": {
    90              "Data-Type": "json",
    91              "Default": {
    92                  "example.com": {
    93                      "name": "value"
    94                  },
    95                  "www.example.com": {
    96                      "name": "value"
    97                  }
    98              },
    99              "Description": "Defined HTTP request headers to send, ordered by domain.",
   100              "Dynamic": false,
   101              "Global": false,
   102              "Value": {
   103                  "example.com": {
   104                      "name": "value"
   105                  },
   106                  "www.example.com": {
   107                      "name": "value"
   108                  }
   109              }
   110          },
   111          "insecure": {
   112              "Data-Type": "bool",
   113              "Default": false,
   114              "Description": "Ignore certificate errors.",
   115              "Dynamic": false,
   116              "Global": false,
   117              "Value": false
   118          },
   119          "redirect": {
   120              "Data-Type": "bool",
   121              "Default": true,
   122              "Description": "Automatically follow redirects.",
   123              "Dynamic": false,
   124              "Global": false,
   125              "Value": true
   126          },
   127          "timeout": {
   128              "Data-Type": "int",
   129              "Default": 10,
   130              "Description": "Timeout in seconds for `get` and `getfile`.",
   131              "Dynamic": false,
   132              "Global": false,
   133              "Value": 10
   134          },
   135          "user-agent": {
   136              "Data-Type": "str",
   137              "Default": "murex/1.7.0000 BETA",
   138              "Description": "User agent string for `get` and `getfile`.",
   139              "Dynamic": false,
   140              "Global": false,
   141              "Value": "murex/1.7.0000 BETA"
   142          }
   143      }
   144      ```
   145  
   146      ### Open Flags
   147  
   148      If the `open` builtin falls back to using the systems default (like `open-xdg`)
   149      then the only thing that gets passed is the path being opened. If the path is
   150      stdin then a temporary file will be created. If you want to pass command line
   151      flags to `open-xdg` (for example), then you need to call that command directly.
   152      In the case of macOS and some Linux systems, that might look like:
   153  
   154      ```
   155      exec open --flags filename
   156      ```
   157    Synonyms:
   158    Related:
   159    - openagent
   160    - fexec
   161    - exec
   162    - get
   163    - getfile
   164    - post
   165    - config
   166    - foreach
   167    - out
   168    - generic
   169  
   170  
   171  - DocumentID: openagent
   172    Title: >+
   173      `openagent`
   174    CategoryID: commands
   175    Summary: >-
   176      Creates a handler function for `open`
   177    Description: |-
   178      `openagent` creates and destroys handler functions for writing data to the
   179      terminal when accessed via `open` and STDOUT is a TTY.
   180    Usage: |-
   181      Display code block for an associated data-type:
   182  
   183      ```
   184      openagent get data-type
   185      ```
   186  
   187      Define an `open` handler function:
   188  
   189      ```
   190      openagent set data-type { code-block }
   191      ```
   192  
   193      Undefine an `open` handler:
   194  
   195      ```
   196      !openagent data-type
   197      ```
   198    Examples:
   199    Flags:
   200    Detail: |-
   201      ### FileRef
   202  
   203      It is possible to track which shell script or module installed what `open`
   204      handler by checking `runtime --open-agents` and checking it's **FileRef**.
   205    Synonyms:
   206    - openagent
   207    - "!openagent"
   208    Related:
   209    - open
   210    - fexec
   211    - runtime
   212    - fileref
   213    - modules
   214