Created
February 18, 2017 13:54
-
-
Save psprint/7a3bef1976e17319e4814b64caddf9f9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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