All Projects → adrg → Xdg

adrg / Xdg

Licence: mit
Go implementation of the XDG Base Directory Specification and XDG user directories

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Xdg

Midir
Cross-platform realtime MIDI processing in Rust.
Stars: ✭ 221 (+151.14%)
Mutual labels:  library, cross-platform
Reproc
A cross-platform (C99/C++11) process library
Stars: ✭ 325 (+269.32%)
Mutual labels:  library, cross-platform
Cute headers
Collection of cross-platform one-file C/C++ libraries with no dependencies, primarily used for games
Stars: ✭ 3,274 (+3620.45%)
Mutual labels:  library, cross-platform
Raz
Modern & multiplatform game engine in C++17
Stars: ✭ 161 (+82.95%)
Mutual labels:  library, cross-platform
Pycnn
Image Processing with Cellular Neural Networks in Python
Stars: ✭ 509 (+478.41%)
Mutual labels:  library, cross-platform
Uriparser
🔪 Strictly RFC 3986 compliant URI parsing and handling library written in C89; moved from SourceForge to GitHub
Stars: ✭ 163 (+85.23%)
Mutual labels:  library, cross-platform
Structopt
Parse command line arguments by defining a struct
Stars: ✭ 323 (+267.05%)
Mutual labels:  library, cross-platform
Csconsoleformat
.NET C# library for advanced formatting of console output [Apache]
Stars: ✭ 296 (+236.36%)
Mutual labels:  library, cross-platform
Machineid
Get the unique machine id of any host (without admin privileges)
Stars: ✭ 422 (+379.55%)
Mutual labels:  library, cross-platform
Kissme
Kissme: Kotlin Secure Storage Multiplatform
Stars: ✭ 351 (+298.86%)
Mutual labels:  library, cross-platform
Borealis
Hardware accelerated, controller and TV oriented UI library for PC and Nintendo Switch (libnx).
Stars: ✭ 135 (+53.41%)
Mutual labels:  library, cross-platform
Plog
Portable, simple and extensible C++ logging library
Stars: ✭ 1,061 (+1105.68%)
Mutual labels:  library, cross-platform
Kivymd
Set of widgets for Kivy inspired by Google's Material Design.
Stars: ✭ 107 (+21.59%)
Mutual labels:  library, cross-platform
Gwork
Skinnable GUI with useful widget collection. Fork of GWEN.
Stars: ✭ 179 (+103.41%)
Mutual labels:  library, cross-platform
Td
Cross-platform library for building Telegram clients
Stars: ✭ 4,260 (+4740.91%)
Mutual labels:  library, cross-platform
Argparse
Argument Parser for Modern C++
Stars: ✭ 680 (+672.73%)
Mutual labels:  library, cross-platform
Igropyr
a async http server base on libuv for Chez Scheme
Stars: ✭ 85 (-3.41%)
Mutual labels:  library, cross-platform
Beet.js
Polyrhythmic Sequencer library for Web Audio API.
Stars: ✭ 87 (-1.14%)
Mutual labels:  library
Flutter Mvvm Provider Demo
Stars: ✭ 89 (+1.14%)
Mutual labels:  cross-platform
Httptransfertasks
Cross Platform HTTP Transfers for downloading and uploading (supports background operations)
Stars: ✭ 87 (-1.14%)
Mutual labels:  cross-platform

xdg logo

Go implementation of the XDG Base Directory Specification and XDG user directories.

Build status Code coverage pkg.go.dev documentation MIT license
Go report card Awesome Go GitHub contributors GitHub open issues Buy me a coffee

Provides an implementation of the XDG Base Directory Specification. The specification defines a set of standard paths for storing application files, including data and configuration files. For portability and flexibility reasons, applications should use the XDG defined locations instead of hardcoding paths.

The package also includes the locations of well known user directories and an implementation of the state directory proposal. Most flavors of Unix, Windows, macOS and Plan 9 are supported.

Full documentation can be found at: https://pkg.go.dev/github.com/adrg/xdg.

Installation

go get github.com/adrg/xdg

Default locations

The package defines sensible defaults for XDG variables which are empty or not present in the environment.

XDG Base Directory

Unix macOS Windows Plan 9
XDG_DATA_HOME ~/.local/share ~/Library/Application Support %LOCALAPPDATA% $home/lib
XDG_DATA_DIRS /usr/local/share
/usr/share
/Library/Application Support %APPDATA%\Roaming
%PROGRAMDATA%
/lib
XDG_CONFIG_HOME ~/.config ~/Library/Application Support %LOCALAPPDATA% $home/lib
XDG_CONFIG_DIRS /etc/xdg ~/Library/Preferences
/Library/Application Support
/Library/Preferences
%PROGRAMDATA% /lib
XDG_CACHE_HOME ~/.cache ~/Library/Caches %LOCALAPPDATA%\cache $home/lib/cache
XDG_RUNTIME_DIR /run/user/UID ~/Library/Application Support %LOCALAPPDATA% /tmp

XDG user directories

Unix macOS Windows Plan 9
XDG_DESKTOP_DIR ~/Desktop ~/Desktop %USERPROFILE%\Desktop $home/desktop
XDG_DOWNLOAD_DIR ~/Downloads ~/Downloads %USERPROFILE%\Downloads $home/downloads
XDG_DOCUMENTS_DIR ~/Documents ~/Documents %USERPROFILE%\Documents $home/documents
XDG_MUSIC_DIR ~/Music ~/Music %USERPROFILE%\Music $home/music
XDG_PICTURES_DIR ~/Pictures ~/Pictures %USERPROFILE%\Pictures $home/pictures
XDG_VIDEOS_DIR ~/Videos ~/Movies %USERPROFILE%\Videos $home/videos
XDG_TEMPLATES_DIR ~/Templates ~/Templates %USERPROFILE%\Templates $home/templates
XDG_PUBLICSHARE_DIR ~/Public ~/Public %PUBLIC% $home/public

Non-standard directories

State directory

Unix macOS Windows Plan 9
XDG_STATE_HOME ~/.local/state ~/Library/Application Support %LOCALAPPDATA% $home/lib/state

Application directories

Unix macOS Windows Plan 9
$XDG_DATA_HOME/applications /Applications %APPDATA%\Roaming\Microsoft\Windows\Start Menu\Programs $home/bin
~/.local/share/applications /bin
/usr/local/share/applications
/usr/share/applications
$XDG_DATA_DIRS/applications

Font directories

Unix macOS Windows Plan 9
$XDG_DATA_HOME/fonts ~/Library/Fonts %windir%\Fonts $home/lib/font
~/.fonts /Library/Fonts %LOCALAPPDATA%\Microsoft\Windows\Fonts /lib/font
~/.local/share/fonts /System/Library/Fonts
/usr/local/share/fonts /Network/Library/Fonts
/usr/share/fonts
$XDG_DATA_DIRS/fonts

Usage

XDG Base Directory

package main

import (
	"log"

	"github.com/adrg/xdg"
)

func main() {
	// XDG Base Directory paths.
	log.Println("Home data directory:", xdg.DataHome)
	log.Println("Data directories:", xdg.DataDirs)
	log.Println("Home config directory:", xdg.ConfigHome)
	log.Println("Config directories:", xdg.ConfigDirs)
	log.Println("Cache directory:", xdg.CacheHome)
	log.Println("Runtime directory:", xdg.RuntimeDir)

	// Non-standard directories.
	log.Println("Home state directory:", xdg.StateHome)
	log.Println("Application directories:", xdg.ApplicationDirs)
	log.Println("Font directories:", xdg.FontDirs)

	// Obtain a suitable location for application config files.
	// ConfigFile takes one parameter which must contain the name of the file,
	// but it can also contain a set of parent directories. If the directories
	// don't exist, they will be created relative to the base config directory.
	configFilePath, err := xdg.ConfigFile("appname/config.yaml")
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Save the config file at:", configFilePath)

	// For other types of application files use:
	// xdg.DataFile()
	// xdg.CacheFile()
	// xdg.RuntimeFile()
	// xdg.StateFile()

	// Finding application config files.
	// SearchConfigFile takes one parameter which must contain the name of
	// the file, but it can also contain a set of parent directories relative
	// to the config search paths (xdg.ConfigHome and xdg.ConfigDirs).
	configFilePath, err = xdg.SearchConfigFile("appname/config.yaml")
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Config file was found at:", configFilePath)

	// For other types of application files use:
	// xdg.SearchDataFile()
	// xdg.SearchCacheFile()
	// xdg.SearchRuntimeFile()
	// xdg.SearchStateFile()
}

XDG user directories

package main

import (
	"log"

	"github.com/adrg/xdg"
)

func main() {
	// XDG user directories.
	log.Println("Desktop directory:", xdg.UserDirs.Desktop)
	log.Println("Download directory:", xdg.UserDirs.Download)
	log.Println("Documents directory:", xdg.UserDirs.Documents)
	log.Println("Music directory:", xdg.UserDirs.Music)
	log.Println("Pictures directory:", xdg.UserDirs.Pictures)
	log.Println("Videos directory:", xdg.UserDirs.Videos)
	log.Println("Templates directory:", xdg.UserDirs.Templates)
	log.Println("Public directory:", xdg.UserDirs.PublicShare)
}

Stargazers over time

Stargazers over time

Contributing

Contributions in the form of pull requests, issues or just general feedback, are always welcome.
See CONTRIBUTING.MD.

Contributors: adrg, wichert, bouncepaw, gabriel-vasile, KalleDK.

References

For more information see:

License

Copyright (c) 2014 Adrian-George Bostan.

This project is licensed under the MIT license. See LICENSE for more details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].