Skip to content

Instantly share code, notes, and snippets.

@psprint
Created February 18, 2017 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psprint/7a3bef1976e17319e4814b64caddf9f9 to your computer and use it in GitHub Desktop.
Save psprint/7a3bef1976e17319e4814b64caddf9f9 to your computer and use it in GitHub Desktop.
# Return n-th (z) segment of given text
# $1 - text
# $2 - segment (default is 1)
# $3 - destination variable name (default is "REPLY")
#
# Can use e.g. 'reply[1]' for $3
function -zui_stdlib_get_segment() {
local -a segs
segs=( "${(z@)1}" )
local varname="${3-REPLY}"
local index="${2-1}"
: ${(P)varname::=${segs[index]}}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment