dbef8b1a92f789f4109435a3b7278f899e328767

Author
mapc <musikmichael@web.de>
Committer
mapc <musikmichael@web.de>
Date

Message

Add helper to get the value of an alias only

Diff

 1diff --git a/lib/functions.zsh b/lib/functions.zsh
 2index d2dcadd0cb4d7235c8876556eb863140c315df12..b4d89a64a5076dfdd10c9e0953707f4acd2aa70a 100644
 3--- a/lib/functions.zsh
 4+++ b/lib/functions.zsh
 5@@ -15,3 +15,33 @@ function take() {
 6   cd $1
 7 }
 8 
 9+#
10+# Get the value of an alias.
11+#
12+# Arguments:
13+#    1. alias - The alias to get its value from
14+# STDOUT:
15+#    The value of alias $1 (if it has one).
16+# Return value:
17+#    0 if the alias was found,
18+#    1 if it does not exist
19+#
20+function alias_value() {
21+    alias "$1" | sed "s/^$1='\(.*\)'$/\1/"
22+    test $(alias "$1")
23+}
24+
25+#
26+# Try to get the value of an alias,
27+# otherwise return the input.
28+#
29+# Arguments:
30+#    1. alias - The alias to get its value from
31+# STDOUT:
32+#    The value of alias $1, or $1 if there is no alias $1.
33+# Return value:
34+#    Always 0
35+#
36+function try_alias_value() {
37+    alias_value "$1" || echo "$1"
38+}