Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
zsh: zstyle examples
# reference: http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#The-zsh_002fzutil-Module
# https://unix.stackexchange.com/questions/214657/what-does-zstyle-do
# list all zstyle settings
zstyle -L
# set a string value
zstyle :example:favorites fruit apple
# set an explicit string value
zstyle -s ':example:favorites' 'computer' 'apple'
# assign new $fav variable with -g
zstyle -g fav ':example:favorites' fruit && echo $fav
# be explicit about the assignment data type:
# -a: array, -b: boolean, -s: string
zstyle -b ':example:favorites:vegtable' 'broccoli' no
# test with -t
if zstyle -t ':example:favorites' 'fruit' 'apple'; then
echo "an apple a day keeps the dr. away"
fi
if ! zstyle -t ':example:favorites:vegtable' 'broccoli' 'no'; then
echo "Broccoli is the deadliest plant on Earth - why, it tries to warn you itself with its terrible taste"
fi
# delete a value with -d
zstyle -d ':example:favorites' 'computer'
# list only zstyle settings for a certain pattern
zstyle -L ':example:favorites*'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.