forked from arun11299/RIFT.ware
/
rift-prompt
51 lines (44 loc) · 1.31 KB
/
rift-prompt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
#
# (c) Copyright RIFT.io, 2013-2016, All Rights Reserved
#
#
# These functions can be used to create an informative prompt for your shell. If
# you are over-riding the PROMPT_COMMAND in your .bashrc file, one approach you
# can take is,
#
# your mileage may vary
# this software is provided as-is in the hopes that some may find it useful.
#
#
# my_rift_prompt() {
# if type -t __rw_workspace_tag >/dev/null; then
# PS1="$(__rw_workspace_tag) [\u@\h]\$ "
# else
# PS1="[\u@\h]\$ "
# fi
# }
#
# if [ -n "$RIFT_ROOT" ]; then
# . $RIFT_ROOT/rift-prompt
# PROMPT_COMMAND=my_rift_prompt
# fi
#
# This will prepend your prompt with the name of the workspace you are in (if
# you are in the workspace), or 'INVALID' if you are not in the workspace to
# inform you that the environment variables setup by the rift shell will be
# incorrect if you are in another workspace.
__rw_in_workspace(){
local path=$(realpath $PWD)
[[ "${path}" != "${path#${RIFT_ROOT}}" ]] && echo "true"
}
__rw_workspace_tag() {
local G="\[\033[0;32m\]" # green
local R="\[\033[0;31m\]" # red
local NONE="\[\033[0m\]" # unsets color to term's fg color
if [[ "$(__rw_in_workspace)" ]]; then
echo -e "${G}${RIFT_WORKSPACE}${NONE}:"
else
echo -e "${R}INVALID${NONE}:"
fi
}