Module utils

Module utils 

Source
Expand description

Provides various utility functions and extension traits for common tasks.

This module contains general-purpose helpers that don’t fit neatly into other domain-specific modules. This includes functions for string manipulation, as well as potentially other reusable components or patterns.

Modules§

dto
Data Transfer Objects when importing and exporting

Structs§

FuzzyTerm
Represents an individual search term and its associated matching semantics
ShellInfo
SplitCaptures
An iterator that splits a text string based on a regular expression, yielding both the substrings that don’t match the regex and the Captures objects for the parts that do match.

Enums§

FuzzyMatch
Represents a component of a fuzzy search query.
FuzzyTermKind
Defines the different kinds of matching strategies for a FuzzyTerm.
ShellType
SplitItem
Represents an item yielded by the SplitCaptures iterator.

Statics§

COMMAND_VARIABLE_REGEX
Regex to match variables from a command, with a capturing group for the name
COMMAND_VARIABLE_REGEX_ALT
Regex to match variables from a command, with two capturing groups for the name
COMMAND_VARIABLE_REGEX_QUOTES
Regex to match variables from a command, with a capturing group for the name.

Functions§

add_tags_to_description
Adds tags to a description, only those not already present will be added
convert_alt_to_regular
Converts alternative variable syntax <var> to the regular {{var}} syntax
execute_shell_command_capture
Executes a shell command, capturing stdout and stderr.
execute_shell_command_inherit
Executes a shell command, inheriting the parent’s stdout and stderr
extract_gist_data
Parses a Gist location string to extract its ID, and optional SHA and filename.
extract_tags_and_cleaned_text
Extracts hashtags from a string and returns them along with the cleaned text.
extract_tags_from_description
Extracts hashtags from a description string
extract_tags_with_editing_and_cleaned_text
Extracts hashtags from a string and returns the tag where the cursor is placed, other tags found on the text and the cleaned text.
extract_variables
Extracts all Variable instances from a given command string
flatten_str
Normalizes a string by performing ASCII transliteration and converting to lowercase.
flatten_variable_name
Normalizes a variable name string by performing ASCII transliteration and converting to lowercase.
format_env_var
Formats an env var name into its shell representation, based on the current shell
generate_working_dir_tree
Generates a string representation of the current working directory tree, respecting .gitignore files
get_executable_version
A helper function to get the version from an executable (e.g. git)
get_export_gist_token
Retrieves a GitHub personal access token for gist, checking configuration and environment variables.
get_os_info
Retrieves the operating system information
get_shell_info
Retrieves information about the current shell, including its type and version
get_shell_type
Retrieves the current shell type
get_working_dir
Retrieves the working directory
github_to_raw
Converts a GitHub file URL to its raw.githubusercontent.com equivalent.
parse_fuzzy_query
Parses a fuzzy search query string into a vector of FuzzyMatch items.
prepare_command_execution
Builds a base Command object for executing a command string via the OS shell
read_history
Reads command history from a specified shell or history manager.
remove_newlines
Removes newline sequences and any surrounding whitespace, replacing them with a single space.
resolve_completion
Fetches suggestions from a variable completion by executing its provider command
resolve_completions
Fetches suggestions from variable completions by executing their commands
truncate_spans
Truncates a slice of spans to fit within a maximum width
truncate_spans_with_ellipsis
Truncates a slice of spans and adds an ellipsis if truncation occurred
unify_newlines
Converts all types of newline sequences (\r, \n, \r\n) in a string to a single newline character (\n).