Expand description
Utility functions for zshrs
Port from zsh/Src/utils.c
Provides miscellaneous utilities: error handling, file operations, string utilities, and character classification.
Structs§
- DirSav
- Initialize directory save struct (from utils.c init_dirsav)
- Hook
Manager - Hook function manager (from utils.c callhookfunc)
- TimedFn
- Timed function entry (from utils.c addtimedfn/deltimedfn)
Enums§
- Quote
Type - Quote type constants for quotestring() Port from zsh.h QT_* enum
Statics§
- SCRIPT_
FILENAME - Script filename
- SCRIPT_
NAME - Script name for error messages
Functions§
- addlockfd
- Add lock file descriptor (from utils.c addlockfd)
- addmodulefd
- Add module file descriptor (from utils.c addmodulefd)
- addunprintable
- Add unprintable character representation (from utils.c addunprintable)
- adduserdir
- Add user directory (from utils.c adduserdir)
- adjustcolumns
- Adjust terminal columns (from utils.c adjustcolumns)
- adjustlines
- Adjust terminal lines (from utils.c adjustlines)
- adjustwinsize
- Adjust terminal window size (from utils.c adjustwinsize)
- append_
file - Append to file
- arrdup
- Duplicate array (from utils.c arrdup)
- arrdup_
max - Duplicate array with max elements (from utils.c arrdup_max)
- arrlen
- Array length - port from arrlen()
- arrlen_
ge - Check if array length >= n (from utils.c arrlen_ge)
- arrlen_
gt - Check if array length > n (from utils.c arrlen_gt)
- arrlen_
le - Check if array length <= n (from utils.c arrlen_le)
- arrlen_
lt - Check if array length < n (from utils.c arrlen_lt)
- attachtty
- Attach to the controlling tty’s process group (from utils.c attachtty)
- bicat
- Buffer concat (from utils.c bicat)
- charcount
- Character count for strings
- check_
fd_ table - Check fd table for valid file descriptors (from utils.c check_fd_table)
- checkglobqual
- Check glob qualifier syntax Port from zsh/Src/utils.c checkglobqual()
- checkmailpath
- Check mail paths (from utils.c checkmailpath)
- checkrmall
- Check before removing directory tree (from utils.c checkrmall)
- chuck
- Remove character from string (from utils.c chuck)
- colonsplit
- Split colon-separated list (from utils.c colonsplit)
- convbase
- Convert integer to string with specified base Port from zsh/Src/utils.c convbase()
- convfloat
- Convert float for output (from utils.c convfloat)
- convfloat_
underscore - Convert float with underscores (from utils.c convfloat_underscore)
- copy_
file - Copy file
- current_
time_ fmt - Get current time formatted
- dircmp
- Compare directory paths (from utils.c dircmp)
- dputs
- Debug printf (from utils.c dputs) - only active in debug builds
- dquotedzputs
- Double-quote and print string (from utils.c dquotedzputs)
- dquotedztrdup
- Duplicate and double-quote a string (from utils.c dquotedztrdup)
- dupstrpfx
- Duplicate string prefix
- dyncat
- String concat (from utils.c dyncat)
- eaccess
- Check access with effective UID (from utils.c eaccess)
- environ
- Get all environment variables
- equalsplit
- Split on ‘=’ returning (name, value) (from utils.c equalsplit)
- expand_
tilde - Expand tilde in a path
- file_
exists - Check if file exists
- file_
mtime - Get file modification time as seconds since epoch
- file_
size - Get file size
- find_
in_ path - Find an executable in PATH
- finddir
- Find named directory for path (from utils.c finddir)
- finddir_
scan - Scan for named directory matches (from utils.c finddir_scan)
- findpwd
- Get the current working directory (port of findpwd/set_pwd_env)
- findsep
- Find a separator in string (from utils.c findsep)
- findword
- Find word at position (from utils.c findword)
- format_
time - Format seconds as HH:MM:SS
- fprintdir
- Print directory name with ~ substitution (from utils.c fprintdir)
- freearray
- Free array (no-op in Rust, provided for API compat)
- freestr
- Free a string (from utils.c freestr) - no-op in Rust
- get_
groupname - Get group name from GID (from utils.c getgrgid handling)
- get_
term_ height - Get terminal height
- get_
term_ width - Get terminal width
- get_
user_ home_ by_ name - Get home directory for user by name (from utils.c getpwnam handling)
- get_
username - Get username from UID (from utils.c getpwuid handling)
- getegid
- Get effective group ID
- getenv
- Get environment variable
- geteuid
- Get effective user ID
- getgid
- Get current group ID
- gethostname
- Get hostname
- getkeystring
- Parse getkeystring escape sequences (from utils.c getkeystring) Handles \n \t \r \e \a \b \f \v \ ' " \xNN \uNNNN \UNNNNNNNN \0NNN
- getnameddir
- Get named directory (from utils.c getnameddir)
- getpid
- Get process ID
- getppid
- Get parent process ID
- getquery
- Simple interactive query (from utils.c getquery)
- getshfunc
- Get shell function by name (from utils.c getshfunc)
- gettempfile
- Create a temporary file (from utils.c gettempfile)
- gettempname
- Get temporary file/directory name Port from zsh/Src/utils.c gettempname()
- gettygrp
- Get the terminal’s process group (from utils.c gettygrp)
- gettyinfo
- Get terminal info (from utils.c gettyinfo/fdgettyinfo)
- getuid
- Get current user ID
- getumask
- Get umask
- getumask_
value - Get or set the file creation mask (wrapper over umask)
- has_
token - Check if metafied - port from zsh/Src/utils.c has_token()
- hash_
string - Hash a string (simple djb2)
- hasspecial
- Check for special characters that need quoting (from utils.c hasspecial)
- hmkarray
- Make single-element array on heap (from utils.c hmkarray)
- imeta
- Check if character needs metafication
- init_
dirsav - inittyptab
- Initialize character type table (from utils.c inittyptab) In Rust we use Unicode-aware char methods, so this is mostly a no-op
- invnstrcmp
- Inverted numeric comparison (from utils.c invnstrncmp)
- is_dir
- Check if path is a directory
- is_
directory - Check if a path is a directory
- is_
executable - Check if a file exists and is executable
- is_file
- Check if path is a file
- is_
float - Check if string is a valid floating point number
- is_
identifier - Check if string is a valid identifier
- is_
ifs_ char - Check if character is an IFS character
- is_link
- Check if path is a symlink
- is_
nicechar - Check if a character needs nice formatting (from utils.c is_nicechar)
- is_
niceformat - Check if nice formatting is needed (from utils.c is_mb_niceformat)
- is_
number - Check if string looks like a number
- is_root
- Check if running as root
- is_
sb_ niceformat - Check if single-byte needs nice format (from utils.c is_sb_niceformat)
- is_tty
- Check if a file descriptor is a tty
- is_
wcs_ nicechar - Check if wide char needs nice formatting (from utils.c is_wcs_nicechar)
- is_
word_ char - Check if character is a word character
- is_
word_ char_ simple - Check if character is a simple word character (from utils.c)
- isabspath
- Check if path is absolute
- isprintable
- Check if string contains only printable characters
- ispwd
- Check if path is the current directory (from utils.c ispwd)
- itype_
end - Check if a character type at end of string (from utils.c itype_end) Returns the position after the identifier characters
- iwsep
- Check if character is a whitespace separator
- lchdir
- Change directory with safeguards (from utils.c lchdir)
- linecount
- Line count for strings
- list_
dir - List directory contents
- mailstat
- Check mail file status (from utils.c mailstat)
- makeabspath
- Make path absolute
- makebangspecial
- Make bang character special/non-special (from utils.c makebangspecial)
- makecommaspecial
- Make comma character special (from utils.c makecommaspecial)
- mb_
charinit - Initialize multibyte state (from utils.c mb_charinit) - no-op in Rust
- mb_
charlenconv - Multibyte char length (from utils.c mb_charlenconv)
- mb_
charlenconv_ r - Multibyte char length with conversion (from utils.c mb_charlenconv_r)
- mb_
metacharlenconv_ r - Multibyte metachar length with conversion (from utils.c mb_metacharlenconv_r)
- mb_
metastrlenend - Multibyte metastring length to end (from utils.c mb_metastrlenend)
- metafy
- Metafy string (from utils.c metafy)
- metalen
- Count meta characters in string (from utils.c metalen)
- mindist
- Spelling correction with full path (from utils.c mindist)
- mkarray
- Make single-element array (from utils.c mkarray)
- mkdir
- Create directory
- mkdir_p
- Create directory recursively
- mode_
to_ octal - Convert file mode to octal string (from utils.c mode_to_octal)
- monotonic_
time_ ns - Get monotonic time in nanoseconds
- move_fd
- Move a file descriptor to a high number (>10)
- movefd
- Move file descriptor to a high number (from utils.c movefd)
- next_
word_ boundary - Get next word boundary (from utils.c)
- nicechar
- Nicely format a string for display (escape unprintable chars)
- nicechar_
ctrl - Get nice representation of control character
- nicechar_
sel - Nice char with quoting selection (from utils.c nicechar_sel)
- nicedup
- Dup string nicely (from utils.c nicedup)
- nicedupstring
- Nice-format and duplicate string (from utils.c nicedupstring)
- niceformat
- Nice format for string display (from utils.c mb_niceformat)
- nicezputs
- Nicely format a string
- niceztrlen
- Count nice string length (from utils.c niceztrlen)
- noquery
- Suppress query (from utils.c noquery)
- normalize_
path - Path normalization (from utils.c xsymlink handling)
- nstrcmp
- Numeric string comparison (from utils.c nstrncmp)
- parse_
time - Parse HH:MM:SS to seconds
- pathprog
- Find program in PATH (from utils.c pathprog)
- preprompt_
actions - Pre-prompt processing (from utils.c preprompt)
- prev_
word_ boundary - Get previous word boundary (from utils.c)
- print_
if_ link - Print symlink target if it is one (from utils.c print_if_link)
- printhhmmss
- Print/format time in HH:MM:SS (from utils.c printhhmmss)
- printprompt4
- Print prompt4 (PS4 for trace output) (from utils.c printprompt4)
- printsafe
- Print-safe string representation
- privasserted
- Check if running with elevated privileges (from utils.c privasserted)
- putraw
- Put raw character to terminal (from utils.c putraw)
- putshout
- Put character to shell output (from utils.c putshout)
- quote_
string - Quote a string for safe shell use (convenience wrapper)
- quotedzputs
- Duplicate a string with quoting for display (from utils.c quotedzputs)
- quotestring
- Quote a string according to the specified type Port from zsh/Src/utils.c quotestring() (lines 6141-6452)
- random_
int - Generate random integer
- random_
range - Generate random integer in range [0, max)
- read1char
- Read a single character (from utils.c read1char)
- read_
file - Read file contents to string
- read_
lines - Read file lines
- read_
loop - Read/write loop wrappers (from utils.c read_loop/write_loop)
- read_
poll - Read poll - check for pending input Port from zsh/Src/utils.c read_poll() lines 2643-2730
- readlink
- Read symlink target
- realpath
- Get real (canonical) path
- redup
- Redup: duplicate fd x to y (from utils.c redup)
- rename_
file - Rename/move file
- restoredir
- Restore saved directory (from utils.c restoredir)
- rm_dir
- Remove directory
- rm_
dir_ all - Remove directory recursively
- rm_file
- Remove file
- sb_
niceformat - Single-byte nice format (from utils.c sb_niceformat)
- sepjoin
- Join array with separator - port from zsh/Src/utils.c sepjoin() lines 3926-3958
- sepsplit
- Split string by separator - port from zsh/Src/utils.c sepsplit() lines 3961-3992
- set_
widearray - Set wide character array (from utils.c set_widearray) - no-op, Rust uses native UTF-8
- setblock_
fd - Set blocking/nonblocking on a file descriptor Port from zsh/Src/utils.c setblock_fd() lines 2578-2618
- setblock_
stdin - Set stdin to blocking mode (from utils.c setblock_stdin)
- setcbreak
- Set terminal to cbreak mode (from utils.c setcbreak)
- setenv
- Set environment variable
- settyinfo
- Set terminal info (from utils.c settyinfo/fdsettyinfo)
- setumask
- Set umask
- shescape
- Escape string for shell
- skipparens
- Skip balanced parentheses (from utils.c skipparens)
- skipwsep
- Skip whitespace separators (from utils.c skipwsep)
- skipwsep_
ifs - Skip whitespace separators from IFS (port helper, with custom IFS)
- slashsplit
- Split path into components (from utils.c slashsplit)
- spacesplit
- IFS-style word splitting - port from zsh/Src/utils.c spacesplit()
- spckword
- Spelling correction distance (from utils.c spdist, already exists but adding spckword) Check if word is close enough to correct (from utils.c spckword)
- spdist
- Compute edit distance between two strings (for spelling correction) Port from zsh/Src/utils.c spdist() lines 4675-4759
- split_
quoted - Split a string respecting quotes
- spname
- Spelling correction: find closest match (from utils.c spname)
- spscan
- Scan for spelling correction (from utils.c spscan)
- str_
ends_ with - Check if string ends with suffix (from utils.c)
- str_
starts_ with - Check if string starts with prefix
- strpfx
- Check if s is a prefix of t (from utils.c strpfx)
- strsfx
- Check if s is a suffix of t (from utils.c strsfx)
- strucpy
- Copy string with upper/lower case (from utils.c strucpy)
- struncpy
- Copy n chars with upper/lower case (from utils.c struncpy)
- subst_
string_ by_ func - Call shell function by name (from utils.c subst_string_by_func)
- subst_
string_ by_ hook - Call hook function by name (from utils.c subst_string_by_hook)
- substnamedir
- Substitute named directory in path (from utils.c substnamedir)
- symlink
- Create symlink
- term_
columns - Get terminal width (fallback to 80)
- term_
lines - Get terminal lines (fallback to 24)
- time_
now - Get current time as seconds since epoch
- time_
now_ ns - Get current time with nanoseconds
- timespec_
diff_ us - Compute time difference in microseconds (from utils.c timespec_diff_us)
- tricat
- Triple concat (from utils.c tricat)
- tulower
- Convert character to lowercase
- tuupper
- Convert character to uppercase
- ucs4tomb
- Convert UCS-4 to multibyte (from utils.c ucs4tomb)
- ucs4toutf8
- Convert UCS-4 to UTF-8 (from utils.c ucs4toutf8)
- unescape
- Unescape string
- unmeta
- Unmetafy string (from utils.c unmeta lines 4930-5051)
- unmeta_
one - Unmetafy a single character (from utils.c unmeta_one)
- unmetafy
- Unmetafy string (from utils.c unmetafy) - zsh meta encoding to plain
- unsetenv
- Unset environment variable
- upchdir
- Go up n directories (from utils.c upchdir)
- wcs_
nicechar - Wide char nice format (from utils.c wcs_nicechar)
- wcs_
nicechar_ sel - Wide char nice format (from utils.c wcs_nicechar_sel)
- wcs_
zarrdup - Duplicate array of wide strings (from utils.c wcs_zarrdup) - same as zarrdup in Rust
- wcsiblank
- Check if wide character is blank (from utils.c wcsiblank)
- wcsitype
- Get wide character type (from utils.c wcsitype)
- wordcount
- Word count for strings
- wordcount_
sep - Count words in string (from utils.c wordcount - extended version)
- write_
file - Write string to file
- write_
loop - write_
to_ fd - Write a string to a file descriptor
- xsymlink
- Resolve symlinks in path (from utils.c xsymlinks/xsymlink)
- zarrdup
- Duplicate array with zsh allocation (from utils.c zarrdup)
- zbasename
- Get basename of path (from utils.c)
- zbeep
- Ring the terminal bell (from utils.c zbeep)
- zchdir
- Set current working directory
- zclose
- Close a file descriptor
- zcloselockfd
- Close lock file descriptor (from utils.c zcloselockfd)
- zdeleteterm
- Delete terminal setup (from utils.c zdeleteterm)
- zdirname
- Get dirname of path (from utils.c)
- zerr
- Print an error message
- zerrmsg
- Print formatted error with optional errno
- zerrnam
- Print an error message with command name
- zexpandtabs
- Expand tabs to spaces (from utils.c zexpandtabs)
- zgetcwd
- Get current working directory
- zjoin
- Join array with delimiter (from utils.c zjoin)
- zmonotime
- Get monotonic time (from utils.c zmonotime)
- zreaddir
- Check if directory is readable with entries (from utils.c)
- zsetupterm
- Initialize terminal (from utils.c zsetupterm)
- zsleep
- Sleep for a given number of seconds (fractional)
- zsleep_
ms - Sleep for milliseconds
- zsleep_
random - Sleep random amount up to max microseconds (from utils.c zsleep_random)
- zstricmp
- Compare strings case-insensitively (from utils.c zstricmp)
- zstrstr
- Find needle in haystack (from utils.c zstrstr)
- zstrtol
- Parse a string to a signed integer with base detection Port from zsh/Src/utils.c zstrtol() lines 2384-2516
- zstrtol_
underscore - Parse integer with underscore separators (from utils.c zstrtol_underscore)
- zstrtoul_
underscore - Parse unsigned integer with underscore support Port from zsh/Src/utils.c zstrtoul_underscore() lines 2528-2575
- ztrcmp
- Compare strings with meta handling (from utils.c ztrcmp lines 5106-5130)
- ztrdup
- String duplicate (from utils.c ztrdup)
- ztrdup_
metafy - Metafy and duplicate string (from utils.c ztrdup_metafy)
- ztrftime
- Format time struct (from utils.c ztrftime)
- ztrftimebuf
- Buffer size helper for time formatting (from utils.c ztrftimebuf)
- ztrlen
- Unmetafied string length (from utils.c ztrlen lines 5135-5152)
- ztrlenend
- Get string length counting to end pointer (from utils.c ztrlenend)
- ztrncpy
- Duplicate n characters (from utils.c ztrncpy)
- ztrsub
- String pointer subtraction with meta handling (from utils.c ztrsub)
- zwarn
- Print a warning message
- zwarning
- Warning with va_list formatting (from utils.c zwarning)
- zwarnnam
- Print a warning with command name
- zwcwidth
- Get wide character width (from utils.c zwcwidth)
- zz_
plural_ z_ alpha - Plural helper (from utils.c zz_plural_z_alpha) - returns ‘s’ for plural
Type Aliases§
- Preprompt
Fn - Pre-prompt function list (from utils.c addprepromptfn/delprepromptfn)