Utility Functions¶
Command Line Utils¶
- cd([string]) [void]
Change the present working directory of the main process. Note that the following do not have the same effect:
cd("my_dir") # This one does not work: $ cd my_dir
This is because using the shell operator ($) spawns a subprocess, which does not affect the parent process.
- which([string]) [string]
Equivelent of the Unix command
which
. Wraps the rust crate ‘which’.
- open([string]) [void]
Opens a path (either a URL or a file path) with the default system program. Uses
xdg-open
on linux, andopen
on mac. See the rust crate ‘opener’ for more information.
- exists([string]) [bool]
Test if a path exists.
- is_directory([string]) [bool]
Test if a path is a directory. Returns false if directory does not exist.
- canonicalize([string]) [string]
Canonicalize e.g. a relative path, to make an absolute path.
- strip_path_prefix(path: [string], prefix: [string]) [string]
Removes a prefix from a given path. This could be used, for example, to find the relative path of a file within a directory. Throws an error if the given path doesn’t contain the given prefix.
- args() [list(string)]
Returns a list of the command line arguments passed to the script, excluding the executable name and script name, if applicable.
- os() [string]
Returns “Linux” or “Darwin” depending on the operating system the script is running on.
Miscellaneous Utilities¶
The following utilities either come from the rust sys-info
crate, or the rust whoami
crate, both for getting various information about the system.
- linux_distro() [string]
Returns the name of the linux distribution the script is running on, or “Unknown” if it’s not known. Throws an error on unsupported systems (non-linux systems). This information is sourced from /etc/os-release. See the sys-info rust crate for more information.
- hostname() [string]
Returns the host device’s hostname.
- device_name() [string]
Returns a “pretty name” for the system, which is used for bluetooth pairing.
- real_name() [string]
Returns the real name of the current user.
- username() [string]
Returns the username of the current user.
- languages() [list(string)]
Returns a list of the languages in order of preference of the current user. For example:
['en-US', 'en']
- desktop_env() [string]
Returns the current desktop environment of the user, or
"Unknown: ..."