aboutsummaryrefslogtreecommitdiffstats
path: root/kerl
diff options
context:
space:
mode:
authorAnthony Ramine <[email protected]>2011-08-31 11:59:17 +0200
committerAnthony Ramine <[email protected]>2011-08-31 11:59:17 +0200
commitf001b0c17bfa8bb319757ceb0dc1934b0cc5a006 (patch)
treef47989766de0c43dddb943a08f917241963d787c /kerl
parent79591094d94028fe10e68845bdeb94a0e5e16ad3 (diff)
downloadkerl-f001b0c17bfa8bb319757ceb0dc1934b0cc5a006.tar.gz
kerl-f001b0c17bfa8bb319757ceb0dc1934b0cc5a006.tar.bz2
kerl-f001b0c17bfa8bb319757ceb0dc1934b0cc5a006.zip
Add a new action "prompt"
This action takes an optional format string (defaults to " (%s)" like __git_ps1) and prints a string where "%s" stands for the current active Erlang installation name. If the current installation isn't managed by kerl, the path basename is used with an asterisk appended to it. ``` nox@Bellcross:~$ export PS1="\u@\h:\w\$(kerl prompt [%s])\\\$ " nox@Bellcross:~$ . .kerl/installs/R14B03-64/activate nox@Bellcross:~[R14B03-64]$ kerl_deactivate nox@Bellcross:~$ logout ```
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
;;