diff --git a/bash/2line_prompt.sh b/bash/2line_prompt.sh deleted file mode 100644 index f89d35a..0000000 --- a/bash/2line_prompt.sh +++ /dev/null @@ -1,18 +0,0 @@ -# Produces a nice, colorful 2-line prompt, basically of the form: -# [username@hostname]-[current_directory] -# $ -# -# Also includes a [x] on the first line if the last command returned false. -# -# TODO: add current git branch - -function fancy_ps1 () { - local COLOR1="\033[1;32m" - local COLOR2="\033[0;32m" - local NO_COLOR="\033[0m" - - local cur_pwd=${PWD//$HOME/\~} - echo -e "[${COLOR2}${cur_pwd}${NO_COLOR}]" -} - -PS1="\[\033[0;37m\]\342\224\214\342\224\200\$([[ \$? != 0 ]] && echo \"[\[\033[0;31m\]\342\234\227\[\033[0;37m\]]\342\224\200\")[$(if [[ ${EUID} == 0 ]]; then echo '\[\033[0;31m\]\h'; else echo '\[\033[0;33m\]\u\[\033[0;37m\]@\[\033[0;96m\]\h'; fi)\[\033[0;37m\]]\342\224\200\$(fancy_ps1)\[\033[0;37m\]\n\[\033[0;37m\]\342\224\224\342\224\200\342\224\200\342\225\274 \[\033[0m\]" diff --git a/bash/colorize.sh b/bash/colorize.sh new file mode 100644 index 0000000..7997a2b --- /dev/null +++ b/bash/colorize.sh @@ -0,0 +1,26 @@ +function colorize() { + local TEXT=$2 + local NO_COLOR="\033[0m" + case "$1" in + red) + local COLOR="\033[31m" + ;; + green) + local COLOR="\033[32m" + ;; + yellow) + local COLOR="\033[33m" + ;; + blue) + local COLOR="\033[34m" + ;; + magenta) + local COLOR="\033[35m" + ;; + cyan) + local COLOR="\033[36m" + ;; + esac + + echo -e "${COLOR}${TEXT}${NO_COLOR}" +} diff --git a/bash/super_prompt.sh b/bash/super_prompt.sh new file mode 100644 index 0000000..78f5793 --- /dev/null +++ b/bash/super_prompt.sh @@ -0,0 +1,29 @@ +# Produces a nice, colorful 2-line prompt of the form: +# [username@hostname:current_directory] (git_repo|branch) +# $ + +source ./colorize.sh + +function super_prompt { + local git_dir=$(git rev-parse --show-toplevel 2>/dev/null) + if [ "$git_dir" != "" ]; then + local path=$(colorize green ${PWD//$git_dir/\!}) + else + local path=$(colorize green ${PWD//$HOME/\~}) + fi + + local git_branch=$(git branch 2>/dev/null | grep "*" | cut -d ' ' -f 2) || "" + if [ "$git_branch" != "" ]; then + local git_repo=$(git rev-parse --show-toplevel) + git_branch=\($(colorize magenta ${git_repo//*\/})"|"$(colorize magenta ${git_branch})\) + fi + + local user=$(colorize yellow $(whoami)) + local host=$(colorize blue ${HOSTNAME}) + local prompt_char=$(colorize red '$') + + prompt=$(printf "[%s@%s:%s] %s\n\f\r%s " "$user" "$host" "$path" "$git_branch" "$prompt_char") + echo $prompt +} + +# export PS1=super_prompt