2012-08-17 06:01:01 -04:00
|
|
|
#!/bin/sh
|
|
|
|
|
2012-08-17 09:59:32 -04:00
|
|
|
|
|
|
|
print_ok()
|
|
|
|
{
|
|
|
|
local OK="\\033[1;32m"
|
|
|
|
local RAZ="\\033[0;39m"
|
|
|
|
local cols=$1
|
|
|
|
local name=$2
|
2013-02-20 04:17:46 -05:00
|
|
|
# printf "\e${OK}%-${cols}s %-${cols}s\n${RAZ}" "$name" "OK"
|
|
|
|
printf "${OK}%-${cols}s %-${cols}s\n${RAZ}" "$name" "OK"
|
2012-08-17 09:59:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
print_no()
|
|
|
|
{
|
|
|
|
local NOK="\\033[1;31m"
|
|
|
|
local RAZ="\\033[0;39m"
|
|
|
|
local cols=$1
|
|
|
|
local name=$2
|
|
|
|
local sub=$3
|
|
|
|
local line=$4
|
2013-02-20 04:17:46 -05:00
|
|
|
# printf "\e${NOK}%-${cols}s %-${cols}s #%-5s\n${RAZ}" "$name" "$sub" "$line"
|
|
|
|
printf "${NOK}%-${cols}s %-${cols}s #%-5s\n${RAZ}" "$name" "$sub" "$line"
|
2012-08-17 09:59:32 -04:00
|
|
|
}
|
|
|
|
|
2012-08-17 06:01:01 -04:00
|
|
|
assert()
|
|
|
|
{
|
2012-08-17 09:59:32 -04:00
|
|
|
local has=$1
|
|
|
|
local name=$2
|
|
|
|
local sub=$3
|
|
|
|
local line=$4
|
2012-08-17 06:01:01 -04:00
|
|
|
|
|
|
|
if [[ -z "$sub" ]]
|
|
|
|
then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2012-08-17 09:59:32 -04:00
|
|
|
cols=20
|
|
|
|
|
|
|
|
if [[ $has == 1 ]] ; then
|
|
|
|
if [[ "$PS1" == *$sub* ]]
|
|
|
|
then
|
|
|
|
print_ok $cols "has $name"
|
|
|
|
else
|
|
|
|
print_no $cols "has $name" $sub $line
|
|
|
|
fi
|
|
|
|
elif [[ $has == 0 ]] ; then
|
|
|
|
if [[ "$PS1" != *$sub* ]]
|
|
|
|
then
|
|
|
|
print_ok $cols " no $name"
|
|
|
|
else
|
|
|
|
print_no $cols " no $name" $sub $line
|
|
|
|
fi
|
2012-08-17 06:01:01 -04:00
|
|
|
else
|
2012-08-17 09:59:32 -04:00
|
|
|
if [[ "$PS1" == $sub ]]
|
|
|
|
then
|
|
|
|
print_ok $cols " is $name"
|
|
|
|
else
|
|
|
|
print_no $cols " is $name" $sub $line
|
|
|
|
fi
|
2012-08-17 06:01:01 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2012-08-17 09:59:32 -04:00
|
|
|
assert_has()
|
|
|
|
{
|
|
|
|
|
|
|
|
assert 1 "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_not()
|
|
|
|
{
|
|
|
|
assert 0 "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_is()
|
|
|
|
{
|
|
|
|
assert 2 "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
log_prompt()
|
|
|
|
{
|
|
|
|
echo -e "$PS1" 1>&2
|
|
|
|
}
|
2012-08-17 06:01:01 -04:00
|
|
|
|
|
|
|
#####################
|
|
|
|
# REDEFINE COMMANDS #
|
|
|
|
#####################
|
|
|
|
|
|
|
|
command()
|
|
|
|
{
|
|
|
|
echo "fake command $@" 1>&2
|
|
|
|
echo "/bin/fake"
|
|
|
|
}
|
|
|
|
|
|
|
|
uname()
|
|
|
|
{
|
|
|
|
echo "fake uname $@" 1>&2
|
|
|
|
echo Linux
|
|
|
|
}
|
|
|
|
|
|
|
|
nproc()
|
|
|
|
{
|
2012-08-17 06:23:36 -04:00
|
|
|
echo "fake nproc $@" 1>&2
|
2012-08-17 06:01:01 -04:00
|
|
|
echo 2
|
|
|
|
}
|
|
|
|
|
|
|
|
# battery
|
|
|
|
acpi()
|
|
|
|
{
|
|
|
|
echo "fake acpi $@" 1>&2
|
|
|
|
echo 'Battery 0: Discharging, 55%, 01:39:34 remaining'
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
git()
|
|
|
|
{
|
|
|
|
echo "fake git $@" 1>&2
|
|
|
|
case $1 in
|
|
|
|
"rev-parse" )
|
|
|
|
echo ".git";;
|
|
|
|
"branch" )
|
|
|
|
echo "* fake_test";;
|
|
|
|
"diff" )
|
2012-08-17 09:00:23 -04:00
|
|
|
echo "2 1 fake_file"
|
|
|
|
return 1;;
|
2012-08-17 06:01:01 -04:00
|
|
|
"status" )
|
|
|
|
echo "# Untracked";;
|
|
|
|
"rev-list" )
|
2012-08-17 09:00:23 -04:00
|
|
|
echo 111;;
|
2012-08-17 06:01:01 -04:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
# global variables
|
|
|
|
export http_proxy="fake"
|
|
|
|
|
|
|
|
|
|
|
|
##########################
|
|
|
|
# Call the liquid prompt #
|
|
|
|
##########################
|
|
|
|
|
|
|
|
# As if we were in an interactive shell
|
|
|
|
export PS1="fake prompt \$"
|
|
|
|
# load functions
|
|
|
|
source ./liquidprompt
|
|
|
|
|
|
|
|
# Force liquid prompt function redefinition
|
|
|
|
_lp_cpu_load()
|
|
|
|
{
|
|
|
|
echo "fake _lp_cpu_load $@" 1>&2
|
2012-08-17 06:23:36 -04:00
|
|
|
echo "0.64"
|
2012-08-17 06:01:01 -04:00
|
|
|
}
|
|
|
|
|
2012-08-17 06:29:13 -04:00
|
|
|
|
|
|
|
################
|
|
|
|
# ADHOC CONFIG #
|
|
|
|
################
|
|
|
|
|
|
|
|
export LP_BATTERY_THRESHOLD=60
|
|
|
|
export LP_LOAD_THRESHOLD=1
|
|
|
|
export LP_MARK_PROXY="proxy"
|
|
|
|
export LP_MARK_BATTERY="BATT"
|
|
|
|
export LP_MARK_LOAD="LOAD"
|
|
|
|
export LP_MARK_UNTRACKED="untracked"
|
|
|
|
export LP_MARK_GIT="gitmark"
|
|
|
|
|
|
|
|
|
2012-08-17 06:01:01 -04:00
|
|
|
# Force erroneous command
|
|
|
|
fake_error
|
|
|
|
|
|
|
|
# Force set prompt
|
|
|
|
_lp_set_prompt
|
|
|
|
|
|
|
|
|
|
|
|
#########
|
|
|
|
# TESTS #
|
|
|
|
#########
|
|
|
|
|
2012-08-17 09:59:32 -04:00
|
|
|
echo "FULL PROMPT"
|
|
|
|
log_prompt
|
|
|
|
|
|
|
|
assert_has Battery_Mark BATT $LINENO
|
|
|
|
assert_has Battery_Level 55% $LINENO
|
|
|
|
assert_has Load_Mark LOAD $LINENO
|
|
|
|
assert_has Load_Level 32% $LINENO
|
|
|
|
assert_has User "[\\\u" $LINENO
|
|
|
|
assert_has Perms : $LINENO
|
|
|
|
assert_has Path $(pwd | sed -e "s|$HOME|~|") $LINENO
|
|
|
|
assert_has Proxy proxy $LINENO
|
|
|
|
assert_has Error 127 $LINENO
|
|
|
|
assert_has GIT_Branch fake_test $LINENO
|
|
|
|
assert_has GIT_Changes "+2/-1" $LINENO
|
|
|
|
assert_has GIT_Commits 111 $LINENO
|
|
|
|
assert_has GIT_Untrack untracked $LINENO
|
|
|
|
assert_has GIT_Mark gitmark $LINENO
|
|
|
|
|
|
|
|
# start hiding features
|
2012-08-17 10:16:35 -04:00
|
|
|
echo "DISABLE BATTERY"
|
|
|
|
export LP_ENABLE_BATT=0
|
|
|
|
_lp_set_prompt
|
|
|
|
log_prompt
|
|
|
|
assert_not Battery_Mark BATT $LINENO
|
|
|
|
assert_not Battery_level 55% $LINENO
|
|
|
|
assert_not Error 127 $LINENO
|
|
|
|
|
2012-08-17 09:59:32 -04:00
|
|
|
echo "HIDE BATTERY LEVEL"
|
2012-08-17 10:16:35 -04:00
|
|
|
export LP_ENABLE_BATT=1
|
2012-08-17 09:59:32 -04:00
|
|
|
export LP_BATTERY_THRESHOLD=50
|
|
|
|
_lp_set_prompt
|
|
|
|
log_prompt
|
|
|
|
assert_has Battery_Mark BATT $LINENO
|
|
|
|
assert_not Battery_level 55% $LINENO
|
|
|
|
assert_not Error 127 $LINENO
|
|
|
|
|
|
|
|
alias acpi="echo 'Battery 0: Full, 100%'"
|
|
|
|
_lp_set_prompt
|
|
|
|
log_prompt
|
|
|
|
assert_not Battery_Mark BATT $LINENO
|
|
|
|
|
2012-08-17 10:16:35 -04:00
|
|
|
echo "DISABLE LOAD"
|
|
|
|
export LP_ENABLE_LOAD=0
|
|
|
|
_lp_set_prompt
|
|
|
|
log_prompt
|
|
|
|
assert_not Load_Mark LOAD $LINENO
|
|
|
|
assert_not Load_Level 32% $LINENO
|
|
|
|
|
2012-08-17 09:59:32 -04:00
|
|
|
echo "HIDE LOAD"
|
2012-08-17 10:16:35 -04:00
|
|
|
export LP_ENABLE_LOAD=1
|
2012-08-17 09:59:32 -04:00
|
|
|
export LP_LOAD_THRESHOLD=40
|
|
|
|
_lp_set_prompt
|
|
|
|
log_prompt
|
|
|
|
assert_not Load_Mark LOAD $LINENO
|
|
|
|
assert_not Load_Level 32% $LINENO
|
|
|
|
|
2012-08-17 10:16:35 -04:00
|
|
|
echo "DISABLE PROXY"
|
|
|
|
export LP_ENABLE_PROXY=0
|
|
|
|
_lp_set_prompt
|
|
|
|
log_prompt
|
|
|
|
assert_not Proxy_Mark proxy $LINENO
|
|
|
|
|
2012-08-17 09:59:32 -04:00
|
|
|
echo "NO PROXY"
|
2012-08-17 10:16:35 -04:00
|
|
|
export LP_ENABLE_PROXY=1
|
2012-08-17 09:59:32 -04:00
|
|
|
export http_proxy=""
|
|
|
|
_lp_set_prompt
|
|
|
|
log_prompt
|
|
|
|
assert_not Proxy_Mark proxy $LINENO
|
|
|
|
|
2012-08-17 10:16:35 -04:00
|
|
|
echo "DISABLE GIT"
|
|
|
|
export LP_ENABLE_GIT=0
|
|
|
|
_lp_set_prompt
|
|
|
|
log_prompt
|
|
|
|
assert_not GIT_Branch fake_test $LINENO
|
|
|
|
assert_not GIT_Changes "+2/-1" $LINENO
|
|
|
|
assert_not GIT_Commits 111 $LINENO
|
|
|
|
assert_not GIT_Untrack untracked $LINENO
|
|
|
|
assert_not GIT_Mark gitmark $LINENO
|
|
|
|
assert_has User_Mark $ $LINENO
|
|
|
|
|
|
|
|
echo "NO GIT"
|
|
|
|
export LP_ENABLE_GIT=1
|
2012-08-17 09:59:32 -04:00
|
|
|
alias git="echo"
|
|
|
|
_lp_set_prompt
|
|
|
|
log_prompt
|
|
|
|
assert_not GIT_Branch fake_test $LINENO
|
|
|
|
assert_not GIT_Changes "+2/-1" $LINENO
|
|
|
|
assert_not GIT_Commits 111 $LINENO
|
|
|
|
assert_not GIT_Untrack untracked $LINENO
|
|
|
|
assert_not GIT_Mark gitmark $LINENO
|
|
|
|
assert_has User_Mark $ $LINENO
|
|
|
|
|
2012-08-17 10:16:35 -04:00
|
|
|
# create a deep dir tree
|
|
|
|
current=$PWD
|
2012-08-17 09:59:32 -04:00
|
|
|
for d in $(seq 20) ; do
|
|
|
|
dirname=""
|
|
|
|
for i in $(seq 5); do
|
|
|
|
dirname="$dirname$d"
|
|
|
|
done
|
|
|
|
mkdir -p $dirname
|
|
|
|
cd $dirname
|
|
|
|
done
|
2012-08-17 10:16:35 -04:00
|
|
|
|
|
|
|
echo "DISABLE SHORTEN PATH"
|
|
|
|
export LP_ENABLE_SHORTEN_PATH=0
|
|
|
|
_lp_set_prompt
|
|
|
|
log_prompt
|
|
|
|
assert_has Path "$(pwd | sed -e "s|$HOME|~|")" $LINENO
|
|
|
|
|
|
|
|
echo "NO SHORTEN PATH"
|
|
|
|
export LP_ENABLE_SHORTEN_PATH=1
|
2012-08-17 09:59:32 -04:00
|
|
|
export LP_PATH_LENGTH=35
|
|
|
|
export LP_PATH_KEEP=1
|
|
|
|
_lp_set_prompt
|
|
|
|
log_prompt
|
2012-08-17 10:16:35 -04:00
|
|
|
assert_has Short_Path " … " $LINENO
|
|
|
|
|
|
|
|
# get back out of the deep tree
|
|
|
|
cd $current
|
|
|
|
|
|
|
|
echo "LOCAL HOST NAME"
|
|
|
|
export LP_HOSTNAME_ALWAYS=1
|
|
|
|
_lp_set_prompt
|
|
|
|
log_prompt
|
|
|
|
assert_has Hostname $(hostname) $LINENO
|
2012-08-17 09:59:32 -04:00
|
|
|
|
|
|
|
echo "prompt_OFF"
|
|
|
|
prompt_OFF
|
|
|
|
log_prompt
|
2012-08-17 10:16:35 -04:00
|
|
|
assert_is Prompt "$ " $LINENO
|
|
|
|
|
|
|
|
echo "prompt_on"
|
|
|
|
prompt_on
|
|
|
|
log_prompt
|
|
|
|
assert_has User "[\\\u" $LINENO
|
|
|
|
assert_has Perms : $LINENO
|
|
|
|
assert_has Path $(pwd | sed -e "s|$HOME|~|") $LINENO
|
|
|
|
assert_has Prompt "$ " $LINENO
|
2012-08-17 09:59:32 -04:00
|
|
|
|