forked from rdeese/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash_profile
106 lines (91 loc) · 2.68 KB
/
bash_profile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# add via line in bash_profile or bash_rc:
# source ~/dotfiles/bash_profile
source ~/.git/git-completion.bash
# for vim with tmux
export TERM='xterm-256color'
# set default editor, partially so that tmux uses vim bindings.
export VISUAL=vim
export EDITOR="$VISUAL"
# pyenv shims
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
# include locally installed node modules
if command -v npm 2>/dev/null; then
PATH=$(npm bin):$PATH
fi
# homebrew cask
export HOMEBREW_CASK_OPTS="--appdir=~/Applications"
# show time command was run in history
HISTTIMEFORMAT="%F %R "
# pretty PS1
__git_branch_and_status () {
# Get the status of the repo and color the branch name appropriately
local STATUS=$(git status --long 2>&1)
local BRANCH=$(git branch 2>/dev/null | grep '^*' | colrm 1 2)
local GREEN="\[\033[32m\]"
local RED="\[\033[31m\]"
local YELLOW="\[\033[33m\]"
if [[ "$STATUS" != *'Not a git repository'* ]]
then
PS1+="$DEFAULT:"
if [[ "$STATUS" != *'working tree clean'* ]]
then
if [[ "$STATUS" == *'Changes to be committed'* ]]
then
# green if all changes are staged
PS1+="$GREEN"
fi
if [[ "$STATUS" == *'Changes not staged for commit'* ]] || [[ "$STATUS" == *'Unmerged paths'* ]]
then
# red if there are unstaged changes
PS1+="$RED"
fi
else
if [[ "$STATUS" == *'Your branch is ahead'* ]]
then
# yellow if need to push
PS1+="$YELLOW"
else
# else default
PS1+="$DEFAULT"
fi
fi
PS1+="$BRANCH"
if [[ "$STATUS" == *'Untracked files'* ]]
then
# red question mark to indicate untracked files
PS1+="$RED"
PS1+="?"
fi
fi
}
__prompt_command() {
# returns the emoji clock closest to the current time
# CLOCK=$(date +%I\ 60*%M+45-30/24%%2+2~C*+C8335+0PP|dc|iconv -f ucs-4)
local DEFAULT="\[\033[0m\]"
local JADE="\[\033[36m\]"
local LAVENDER="\[\033[95m\]"
# $? gives exit code of last command
# \! gives history # of this command
PS1="$LAVENDER\W"
__git_branch_and_status
PS1+="$LAVENDER *>$DEFAULT "
}
PROMPT_COMMAND=__prompt_command
__pretty_line() {
local OFFSET=$(bc <<< "16 + ($RANDOM % 36 + 1)*6")
local END=$(bc <<< "$OFFSET + 5")
local LINE=""
local STUFF=""
for C in $(seq $OFFSET $END); do
STUFF=$(printf ' %.0s' $(seq 1 $(bc <<< "$(tput cols)/12")))
LINE+="\033[48;5;${C}m"$STUFF
done
for C in $(seq $END $OFFSET); do
STUFF=$(printf ' %.0s' $(seq 1 $(bc <<< "$(tput cols)/12")))
LINE+="\033[48;5;${C}m"$STUFF
done
LINE+=$(printf ' %.0s' $(seq 1 $(bc <<< "$(tput cols) - 12*($(tput cols)/12)")))
echo -e "$LINE"
tput sgr0
}
bind -x '"\C-l": clear; __pretty_line'