diff options
author | mapc <musikmichael@web.de> | 2012-05-05 10:39:05 +0200 |
---|---|---|
committer | mapc <musikmichael@web.de> | 2012-05-29 01:49:52 +0200 |
commit | dbef8b1a92f789f4109435a3b7278f899e328767 (patch) | |
tree | 79822aadc04d40fc3c9978c47fd52397f22be4b5 /lib/functions.zsh | |
parent | 1120f973054836eeb53750f57d69fbec41a340dc (diff) | |
download | zsh-dbef8b1a92f789f4109435a3b7278f899e328767.tar.gz zsh-dbef8b1a92f789f4109435a3b7278f899e328767.tar.bz2 zsh-dbef8b1a92f789f4109435a3b7278f899e328767.zip |
Add helper to get the value of an alias only
Diffstat (limited to 'lib/functions.zsh')
-rw-r--r-- | lib/functions.zsh | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/functions.zsh b/lib/functions.zsh index d2dcadd0c..b4d89a64a 100644 --- a/lib/functions.zsh +++ b/lib/functions.zsh @@ -15,3 +15,33 @@ function take() { cd $1 } +# +# Get the value of an alias. +# +# Arguments: +# 1. alias - The alias to get its value from +# STDOUT: +# The value of alias $1 (if it has one). +# Return value: +# 0 if the alias was found, +# 1 if it does not exist +# +function alias_value() { + alias "$1" | sed "s/^$1='\(.*\)'$/\1/" + test $(alias "$1") +} + +# +# Try to get the value of an alias, +# otherwise return the input. +# +# Arguments: +# 1. alias - The alias to get its value from +# STDOUT: +# The value of alias $1, or $1 if there is no alias $1. +# Return value: +# Always 0 +# +function try_alias_value() { + alias_value "$1" || echo "$1" +}
\ No newline at end of file |