/places-cli

A cli program to get file and directory locations from XDG

Primary LanguageRustGNU General Public License v3.0GPL-3.0

Crates.io GitHub Release CI License: GPL v3

places-cli

A handy tool for your scripts to get correct path names from known locations or XDG directories.

NOTE: The package name is places-cli and the binary name is just places.

Motivation

Let's say you want to find the desktop and the download directory. Without this tool you have to do something like:

test -f ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs && \
     source ${XDG_CONFIG_HOME:-~/.config}/user-dirs.dirs
echo ${XDG_DESKTOP_DIR:-$HOME/Desktop}
echo ${XDG_DOWNLOAD_DIR:-$HOME}

Or use something xdg-user-dir DOWNLOAD, but this is prone to errors. With places it becomes:

places desktop
places downloads

Ah, much better, no UPPERCASE and will return an error if you make some typo. But wait, you can do much more with it

  • Get a path like: /home/alice/.config/gizmo/theme/colors.txt
places -a gizmo config theme colors.txt \
places config gizmo theme colors.txt
  • List all config files for the 'gizmo' program
lsd $(places --app=gizmo data) \
places --app=gizmo data | xargs lsd
  • Copy a config file
cp gizmo_config.toml $(places -a gizmo config)
  • Get a folder inside 'Downloads dir', even if it is localized.
places downloads Software

This returns something like /home/alice/Descargas/Software

Installation

To install the places-cli, you just need to run

cargo install --force places-cli

--force just makes it update to the latest places-cli if it's already installed

Download the man page and the completions for github repository and put them in the right place.

Next version will have an installation script and hopefully some deb packages and rpms (help wanted with github actions).

Verifiy the installation

To verify if the installation was successful, you can run

which places

that should output similar to

$HOME/.cargo/bin/places