aboutsummaryrefslogtreecommitdiffstats
path: root/kerl
diff options
context:
space:
mode:
authorYurii Rashkovskii <[email protected]>2011-08-31 08:14:58 -0700
committerYurii Rashkovskii <[email protected]>2011-08-31 08:14:58 -0700
commit4ca2ed29258c965c444cc55cc982286c84c6802c (patch)
treef47989766de0c43dddb943a08f917241963d787c /kerl
parent79591094d94028fe10e68845bdeb94a0e5e16ad3 (diff)
parentf001b0c17bfa8bb319757ceb0dc1934b0cc5a006 (diff)
downloadkerl-4ca2ed29258c965c444cc55cc982286c84c6802c.tar.gz
kerl-4ca2ed29258c965c444cc55cc982286c84c6802c.tar.bz2
kerl-4ca2ed29258c965c444cc55cc982286c84c6802c.zip
Merge pull request #9 from nox/prompt-action
Add a new action "prompt"
Diffstat (limited to 'kerl')
-rwxr-xr-xkerl39
1 files changed, 37 insertions, 2 deletions
diff --git a/kerl b/kerl
index fe8f44a..f17effe 100755
--- a/kerl
+++ b/kerl
@@ -97,6 +97,7 @@ usage()
echo " delete Delete builds and installations"
echo " active Print the path of the active installation"
echo " status Print available builds and installations"
+ echo " prompt Print a string suitable for insertion in prompt"
exit 1
}
@@ -487,11 +488,28 @@ update_usage()
echo "usage: $0 $1 <releases|agner>"
}
-do_active()
+get_active_path()
{
if [ -n "$_KERL_SAVED_PATH" ]; then
+ echo $PATH | cut -d ":" -f 1 | sed 's/\(.*\)..../\1/'
+ fi
+ return 0
+}
+
+get_name_from_install_path()
+{
+ if [ -f "$KERL_BASE_DIR/otp_installations" ]; then
+ grep -F "$1" "$KERL_BASE_DIR/otp_installations" | cut -d ' ' -f 1
+ fi
+ return 0
+}
+
+do_active()
+{
+ ACTIVE_PATH=`get_active_path`
+ if [ -n "$ACTIVE_PATH" ]; then
echo "The current active installation is:"
- echo `echo $PATH | cut -d ":" -f 1 | sed 's/\(.*\)..../\1/'`
+ echo $ACTIVE_PATH
return 0
else
echo "No Erlang/OTP kerl installation is currently active"
@@ -656,6 +674,23 @@ case "$1" in
do_active
exit 0
;;
+ prompt)
+ FMT=" (%s)"
+ if [ -n "$2" ]; then
+ FMT="$2"
+ fi
+ ACTIVE_PATH=`get_active_path`
+ if [ -n "$ACTIVE_PATH" ]; then
+ ACTIVE_NAME=`get_name_from_install_path "$ACTIVE_PATH"`
+ if [ -z "$ACTIVE_NAME" ]; then
+ VALUE="`basename "$ACTIVE_PATH"`*"
+ else
+ VALUE="$ACTIVE_NAME"
+ fi
+ printf "$FMT" "$VALUE"
+ fi
+ exit 0
+ ;;
*)
echo "unkwnown command: $1"; usage; exit 1
;;