Skip to content

Commit

Permalink
Merge pull request arialdomartini#7 from shadowwalker/master
Browse files Browse the repository at this point in the history
Add support for python virtualenv
  • Loading branch information
cy4n authored Sep 21, 2017
2 parents 973ddbc + a3808ae commit f7bfccb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ Then, configure your terminal with the desired font, and restart it.

One liner for OS X:

git clone https://github.com/arialdomartini/oh-my-git.git ~/.oh-my-git && echo source ~/.oh-my-git/prompt.sh >> ~/.profile
git clone --depth=1 https://github.com/arialdomartini/oh-my-git.git ~/.oh-my-git && echo source ~/.oh-my-git/prompt.sh >> ~/.profile

One liner for Ubuntu:

git clone https://github.com/arialdomartini/oh-my-git.git ~/.oh-my-git && echo source ~/.oh-my-git/prompt.sh >> ~/.bashrc
git clone --depth=1 https://github.com/arialdomartini/oh-my-git.git ~/.oh-my-git && echo source ~/.oh-my-git/prompt.sh >> ~/.bashrc

Then restart your Terminal.

Expand Down
22 changes: 11 additions & 11 deletions base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ function enrich {
local color_on=${3:-$omg_default_color_on}

if [[ $flag != true && $omg_use_color_off == false ]]; then symbol=' '; fi
if [[ $flag == true ]]; then local color=$color_on; else local color=$omg_default_color_off; fi
if [[ $flag == true ]]; then local color=$color_on; else local color=$omg_default_color_off; fi

echo -n "${prompt}${color}${symbol}${reset} "
}

function get_current_action () {
local info="$(git rev-parse --git-dir 2>/dev/null)"
local info="$(git rev-parse --git-dir 2> /dev/null)"
if [ -n "$info" ]; then
local action
if [ -f "$info/rebase-merge/interactive" ]
Expand Down Expand Up @@ -50,18 +50,18 @@ function get_current_action () {
}

function build_prompt {
local enabled=`git config --get oh-my-git.enabled`
local enabled=`git config --get oh-my-git.enabled 2> /dev/null`
if [[ ${enabled} == false ]]; then
echo "${PSORG}"
exit;
fi

local prompt=""

# Git info
local current_commit_hash=$(git rev-parse HEAD 2> /dev/null)
if [[ -n $current_commit_hash ]]; then local is_a_git_repo=true; fi

if [[ $is_a_git_repo == true ]]; then
local current_branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
local current_branch_sanitized=${current_branch//\$/💩}
Expand All @@ -86,9 +86,9 @@ function build_prompt {

local number_of_untracked_files=$(\grep -c "^??" <<< "${git_status}")
if [[ $number_of_untracked_files -gt 0 ]]; then local has_untracked_files=true; fi

local tags_at_current_commit=$(git tag --points-at $current_commit_hash 2> /dev/null)

if [[ $has_upstream == true ]]; then
local commits_diff="$(git log --pretty=oneline --topo-order --left-right ${current_commit_hash}...${upstream} 2> /dev/null)"
local commits_ahead=$(\grep -c "^<" <<< "$commits_diff")
Expand All @@ -97,9 +97,9 @@ function build_prompt {

if [[ $commits_ahead -gt 0 && $commits_behind -gt 0 ]]; then local has_diverged=true; fi
if [[ $has_diverged == false && $commits_ahead -gt 0 ]]; then local should_push=true; fi

local will_rebase=$(git config --get branch.${current_branch_sanitized}.rebase 2> /dev/null)

local number_of_stashes="$(git stash list -n1 2> /dev/null | wc -l)"
if [[ $number_of_stashes -gt 0 ]]; then local has_stashes=true; fi

Expand Down Expand Up @@ -139,7 +139,7 @@ function build_prompt {
done
fi
fi

echo "$(custom_build_prompt \
${enabled:-true} \
${current_commit_hash:-""} \
Expand Down Expand Up @@ -169,7 +169,7 @@ function build_prompt {
${submodules_outdated:-false} \
${action} \
)"

}

function_exists() {
Expand Down
30 changes: 20 additions & 10 deletions prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ if [ -n "${BASH_VERSION}" ]; then

: ${omg_is_a_git_repo_symbol:=''}
: ${omg_submodules_outdated_symbol:=''}
: ${omg_has_untracked_files_symbol:=''} #          ?  
: ${omg_has_untracked_files_symbol:=''} #          ?  
: ${omg_has_adds_symbol:=''}
: ${omg_has_deletions_symbol:=''}
: ${omg_has_cached_deletions_symbol:=''}
: ${omg_has_modifications_symbol:=''}
: ${omg_has_cached_modifications_symbol:=''}
: ${omg_ready_to_commit_symbol:=''} #  →
: ${omg_ready_to_commit_symbol:=''} #  →
: ${omg_is_on_a_tag_symbol:=''} #       
: ${omg_needs_to_merge_symbol:=''} #
: ${omg_detached_symbol:=''} #   
: ${omg_detached_symbol:=''} #   
: ${omg_can_fast_forward_symbol:=''}
: ${omg_has_diverged_symbol:=''} #  
: ${omg_not_tracked_branch_symbol:=''} #   
Expand All @@ -32,10 +32,11 @@ if [ -n "${BASH_VERSION}" ]; then
: ${omg_should_push_symbol:=''} #  
: ${omg_has_stashes_symbol:=''}
: ${omg_arrow_symbol:=''}
: ${omg_is_virtualenv_symbol:=''}

: ${omg_default_color_on:='\[\033[1;37m\]'}
: ${omg_default_color_off:='\[\033[0m\]'}

PROMPT='$(build_prompt)'
RPROMPT='%{$reset_color%}%T %{$fg_bold[white]%} %n@%m%{$reset_color%}'

Expand Down Expand Up @@ -80,6 +81,11 @@ if [ -n "${BASH_VERSION}" ]; then
local prompt=""
local original_prompt=$PS1

local is_virtualenv="${VIRTUAL_ENV:-false}"
if [[ $is_virtualenv != false ]]; then
local virtualenv=$(basename $VIRTUAL_ENV)
fi


# foreground
local black='\e[0;30m'
Expand All @@ -100,7 +106,7 @@ if [ -n "${BASH_VERSION}" ]; then
local background_purple='\e[45m'
local background_cyan='\e[46m'
local background_white='\e[47m'

local reset='\e[0m' # Text Reset]'

local black_on_white="${black}${background_white}"
Expand Down Expand Up @@ -129,7 +135,7 @@ if [ -n "${BASH_VERSION}" ]; then
prompt+=$(enrich_append $has_untracked_files $omg_has_untracked_files_symbol "${red_on_white}")
prompt+=$(enrich_append $has_modifications $omg_has_modifications_symbol "${red_on_white}")
prompt+=$(enrich_append $has_deletions $omg_has_deletions_symbol "${red_on_white}")


# ready
if [[ ${omg_condensed} == true && ${has_adds} == true ]]; then
Expand All @@ -145,7 +151,7 @@ if [ -n "${BASH_VERSION}" ]; then
if [[ ${omg_condensed} == false ]]; then
prompt+=$(enrich_append $has_deletions_cached $omg_has_cached_deletions_symbol "${black_on_white}")
fi

# next operation

prompt+=$(enrich_append $ready_to_commit $omg_ready_to_commit_symbol "${red_on_white}")
Expand All @@ -166,7 +172,7 @@ if [ -n "${BASH_VERSION}" ]; then
prompt+=$(enrich_append $detached $omg_detached_symbol "${white_on_red}")
fi
prompt+=$(enrich_append $detached "(${current_commit_hash:0:7})" "${black_on_red}")
else
else
if [[ $has_upstream == false ]]; then
prompt+=$(enrich_append true "-- ${omg_not_tracked_branch_symbol} -- (${current_branch})" "${black_on_red}")
else
Expand All @@ -188,25 +194,29 @@ if [ -n "${BASH_VERSION}" ]; then
if [[ $commits_ahead == 0 && $commits_behind == 0 ]]; then
prompt+=$(enrich_append true " -- -- " "${black_on_red}")
fi

fi
prompt+=$(enrich_append true "(${current_branch} ${type_of_upstream} ${upstream//\/$current_branch/})" "${black_on_red}")
fi
fi
for tag in ${tags_at_current_commit}; do
prompt+=$(enrich_append true "${omg_is_on_a_tag_symbol} ${tag}" "${black_on_red}")
done
prompt+=$(enrich_append ${is_virtualenv} "${omg_is_virtualenv_symbol} ${virtualenv}" "${white_on_red}")
prompt+="${reset}${red}${omg_arrow_symbol}${reset}\n"
prompt+="$(eval_prompt_callback_if_present)"
prompt+="${omg_second_line}"
else
prompt+="$(eval_prompt_callback_if_present)"
prompt+="${omg_ungit_prompt}"
if [[ $is_virtualenv != false ]]; then
prompt+="${virtualenv}${omg_is_virtualenv_symbol} "
fi
fi

echo "${prompt}"
}

PS2="${yellow}${reset} "

function bash_prompt() {
Expand Down

0 comments on commit f7bfccb

Please sign in to comment.