Fix things for bash.

This commit is contained in:
Ivan Malison 2014-05-01 23:28:17 -07:00
parent c4f9df8968
commit 6ff0d0bf10
3 changed files with 51 additions and 15 deletions

View File

@ -7,41 +7,69 @@ Blue='\e[0;34m' # Blue
Purple='\e[0;35m' # Purple
Cyan='\e[0;36m' # Cyan
White='\e[0;37m' # White
BoldYellow='\e[1;33m' # Yellow
function current_directory() {
local PWD=$(pwd)
echo "${PWD/#$HOME/~}"
pwd | sed "s:$HOME:~:"
}
function current_directory() {
local PWD=$(pwd)
echo "${PWD/#$HOME/~}"
}
function git_prompt_info() {
if test -z $(git branch-or-sha);
then
echo ""
else
echo " on $(git branch-or-sha)$(git_status_character)"
echo " $(separator "on") $(git branch-or-sha)$(git_status_character)"
fi
}
function git_status_character() {
if git dirty;
then
echo "✘"
print_with_color "✘" "$Red"
else
echo "✔"
print_with_color "✔" "$Green"
fi
}
function sandbox_prompt() {
if [ ! -z $(sandbox_prompt_info) ];
if [ ! -z "$(sandbox_prompt_info)" ];
then
echo " with $(colored_sandbox_string)"
echo " $(separator "with") $(colored_sandbox_string)%{$reset_color%}"
fi
}
PS1="╭─% ${Green}\u ${White}at ${Blue}\h ${White}in \$(current_directory)\$(git_prompt_info)\$(sandbox_prompt)
╰─± "
function command_line_character() {
if ! test -z $(git branch-or-sha);
then
echo "±"
else
echo "○"
fi
}
function prompt_basic_colors() {
export USERNAME_COLOR="$Green"
export SEPARATOR_COLOR="$Black"
export HOSTNAME_COLOR="$Blue"
export CURRENT_DIRECTORY_COLOR="$BoldYellow"
}
function print_with_color() {
echo "$2$1\e[0m"
}
function separator() {
print_with_color "$1" "$SEPARATOR_COLOR"
}
prompt_basic_colors
function set_bash_prompt() {
PS1="╭─$(print_with_color "$(whoami)" "$USERNAME_COLOR") $(separator "at") $(print_with_color "`hostname -s`" "$HOSTNAME_COLOR") $(separator "in") $(print_with_color "`current_directory`" "$CURRENT_DIRECTORY_COLOR")$(git_prompt_info)$(sandbox_prompt)
╰─$(command_line_character) "
}
export PROMPT_COMMAND=set_bash_prompt
PS2='(%_) '

View File

@ -1,3 +1,9 @@
for filename in ~/.lib/shellrc/*; do
source $filename
done
# Source everything twice just in case there were things that depended
# on each other.
for filename in ~/.lib/shellrc/*; do
source $filename
done

View File

@ -105,7 +105,8 @@ function git_root() {
function git_diff_replacing() {
local original_sha='HEAD~1'
local new_sha='HEAD'
while getopts "do:n:" OPTCHAR; do;
while getopts "do:n:" OPTCHAR;
do
case $OPTCHAR in
o)
original_sha="$OPTARG"
@ -129,7 +130,8 @@ function git_diff_replacing() {
function git_reset_author() {
local should_update_command=''
local update_command=''
while getopts "a:e:A:E:h" OPTCHAR; do;
while getopts "a:e:A:E:h" OPTCHAR;
do
case $OPTCHAR in
a)
new_author="$OPTARG";