Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Ohmyzsh
Commits
8f71efc0
"plugins/vscode:/vscode.git/clone" did not exist on "c4d84f1b77ff120cf337cb6bd8fcc9d29ca04a14"
Commit
8f71efc0
authored
May 05, 2012
by
mapc
Browse files
Add helper to easily define default values for variables and env variables.
parent
dbef8b1a
Changes
1
Show whitespace changes
Inline
Side-by-side
lib/functions.zsh
View file @
8f71efc0
...
...
@@ -45,3 +45,31 @@ function alias_value() {
function
try_alias_value
()
{
alias_value
"
$1
"
||
echo
"
$1
"
}
#
# Set variable "$1" to default value "$2" if "$1" is not yet defined.
#
# Arguments:
# 1. name - The variable to set
# 2. val - The default value
# Return value:
# 0 if the variable exists, 3 if it was set
#
function
default
()
{
test
`
typeset
+m
"
$1
"
`
&&
return
0
typeset
-g
"
$1
"
=
"
$2
"
&&
return
3
}
#
# Set enviroment variable "$1" to default value "$2" if "$1" is not yet defined.
#
# Arguments:
# 1. name - The env variable to set
# 2. val - The default value
# Return value:
# 0 if the env variable exists, 3 if it was set
#
function
env_default
()
{
env
|
grep
-q
"^
$1
="
&&
return
0
export
"
$1
=
$2
"
&&
return
3
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment