Skip to content

Commit

Permalink
feat(prompt): updated the git prompt to be colorized based on the cur…
Browse files Browse the repository at this point in the history
…rent state
  • Loading branch information
Deavon M. McCaffery committed Aug 19, 2016
1 parent b875434 commit 71e66cc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
15 changes: 0 additions & 15 deletions src/bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,9 @@ alias cd..='cd ..'
alias ..='cd ..'
alias ...='cd .. ; ..'

# -- listing shortcuts
alias ls='ls -G'

# -- sudo alias (allow other alias extensions to work when sudo-ing)
alias sudo='sudo '

# -- special effects
alias colors="set | egrep 'CLR_w*'"
alias myprofile="history | awk '{print \$2}' | awk 'BEGIN{FS=\"|\"}{print \$1}' | sort | uniq -c | sort -n | tail -n 20 | sort -nr"

alias flushdns='dscacheutil -flushcache; sudo killall -HUP mDNSResponder'

# shell options
shopt -s checkwinsize # check window size on script exit
shopt -s cdable_vars # enable change directory to a variable value

# aliases
PATH=$PATH:~/.ssh/aliases

# play login sound
tlogi 1>&- 2>&-
23 changes: 15 additions & 8 deletions src/scripts/set-prompt.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# make sure that git prompt is sourced first
source ~/.ssh/scripts/git-prompt.sh

function set-prompt() {
# set the window title
echo -ne "\033]0;${USER}@${HOSTNAME%%.*} ${PWD}\007"

function emit-prompt-arrow()
{
# set the default color
local CLR_PROMPT=$CLR_USER_PROMPT

# set color for staff user (administrator)
if [ ! -z '`command id -Gn | grep -s -o admin`' ]; then
CLR_PROMPT=$CLR_STAFF_PROMPT
Expand All @@ -18,14 +16,23 @@ function set-prompt() {
CLR_PROMPT=$CLR_ROOT_PROMPT
fi

echo "\[${CLR_PROMPT}\] ==> \[${CLR_CLEAR}\]"
}

function set-prompt() {
# set the window title
echo -ne "\033]0;${USER}@${HOSTNAME%%.*} ${PWD}\007"

export PROMPT_COMMAND='__git_ps1 "\n\u@\h : \w\n" "`emit-prompt-arrow`"'

# specify the two-line prompt with color-coded arrow
export PS1="\n\u@\h : \w\n $(__git_ps1 '(%s)')\[${CLR_PROMPT}\] ==> \[${CLR_CLEAR}\]"
# export PS1="\n\u@\h : \w\n $(__git_ps1 '(%s)')\[${CLR_PROMPT}\] ==> \[${CLR_CLEAR}\]"
}

GIT_PS1_SHOWDIRTYSTATE=true
GIT_PS1_SHOWSTASHSTATE=true
GIT_PS1_SHOWCOLORHINTS=true
GIT_PS1_SHOWUNTRACKEDFILES=true
GIT_PS1_SHOWUPSTREAM="verbose"

# export the prompt command
export PROMPT_COMMAND=set-prompt
set-prompt
11 changes: 11 additions & 0 deletions src/scripts/show-profile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function show-profile() {
history | awk '{print \$2}' | awk 'BEGIN{FS=\"|\"}{print \$1}' | sort | uniq -c | sort -n | tail -n 20 | sort -nr
}

function showprofile() {
show-profile
}

function myprofile() {
show-profile
}

0 comments on commit 71e66cc

Please sign in to comment.