xdg

package module
v6.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2024 License: MIT Imports: 7 Imported by: 1

README

go-xdg

PkgGoDev

Package xdg provides functions related to freedesktop.org.

License

MIT

Documentation

Overview

Package xdg provides functions related to freedesktop.org.

Index

Examples

Constants

View Source
const (

	// DefaultURLSchemeHandlerProperty is the default URL scheme handler property.
	DefaultURLSchemeHandlerProperty = "default-url-scheme-handler"

	// DefaultWebBrowserProperty is the default web browser property.
	DefaultWebBrowserProperty = "default-web-browser"
)

Variables

This section is empty.

Functions

func Open

func Open(fileOrURL string) error

Open opens fileOrURL with xdg-open.

Types

type BaseDirectorySpecification

type BaseDirectorySpecification struct {
	ConfigHome string
	ConfigDirs []string
	DataHome   string
	DataDirs   []string
	CacheHome  string
	RuntimeDir string
	StateHome  string
}

A BaseDirectorySpecification represents an XDG Base Directory Specification configuration. See https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html.

func NewBaseDirectorySpecification

func NewBaseDirectorySpecification() (*BaseDirectorySpecification, error)

NewBaseDirectorySpecification returns a new BaseDirectorySpecification, configured from the user's environment variables.

func NewTestBaseDirectorySpecification

func NewTestBaseDirectorySpecification(homeDir string, getenv GetenvFunc) *BaseDirectorySpecification

NewTestBaseDirectorySpecification returns a new BaseDirectorySpecification using homeDir and the getenv function. getenv can be nil, in which case default values are returned.

func (*BaseDirectorySpecification) OpenConfigFile

func (b *BaseDirectorySpecification) OpenConfigFile(fsys fs.FS, nameComponents ...string) (fs.File, string, error)

OpenConfigFile opens the first configuration file with the given name found, its full path, and any error. If no file can be found, the error will be fs.ErrNotExist.

func (*BaseDirectorySpecification) OpenDataFile

func (b *BaseDirectorySpecification) OpenDataFile(fsys fs.FS, nameComponents ...string) (fs.File, string, error)

OpenDataFile opens the first data file with the given name found, its full path, and any error. If no file can be found, the error will be fs.ErrNotExist.

type GetenvFunc

type GetenvFunc func(string) string

A GetenvFunc is a function that gets an environment variable, like os.Getenv.

type Setting

type Setting struct {
	Property    string
	SubProperty string
}

A Setting is a setting.

func (Setting) Check

func (s Setting) Check(value string) (bool, error)

Check checks that value of s is value. See https://portland.freedesktop.org/doc/xdg-settings.html.

Example
package main

import (
	"fmt"

	xdg "github.com/twpayne/go-xdg/v6"
)

func main() {
	setting := xdg.Setting{
		Property:    xdg.DefaultWebBrowserProperty,
		SubProperty: "",
	}
	isGoogleChrome, err := setting.Check("google-chrome.desktop")
	if err != nil {
		panic(err)
	}
	fmt.Println(isGoogleChrome)
}
Output:

func (Setting) Get

func (s Setting) Get() (string, error)

Get gets the value of s.

Example
package main

import (
	"fmt"

	xdg "github.com/twpayne/go-xdg/v6"
)

func main() {
	setting := xdg.Setting{
		Property:    xdg.DefaultURLSchemeHandlerProperty,
		SubProperty: "http",
	}
	value, err := setting.Get()
	if err != nil {
		panic(err)
	}
	fmt.Println(value)
}
Output:

func (Setting) Set

func (s Setting) Set(value string) error

Set sets s to value.

Example
package main

import (
	xdg "github.com/twpayne/go-xdg/v6"
)

func main() {
	setting := xdg.Setting{
		Property:    xdg.DefaultURLSchemeHandlerProperty,
		SubProperty: "http",
	}
	if err := setting.Set("firefox.desktop"); err != nil {
		panic(err)
	}
}
Output:

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL