-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bash_prompt
117 lines (96 loc) · 3.42 KB
/
.bash_prompt
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
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env bash
# terminal customizations - http://xta.github.com/HalloweenBash/
parse_git_branch() {
if $(git branch --no-color &>/dev/null); then
local branch='';
branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')
echo "${bold}${blue}${branch}${reset}"
fi
}
# via https://gist.github.com/chrisbraddock/4714691
git_dirty_stash() {
if $(git rev-parse --verify refs/stash &>/dev/null); then
echo " 💩 "
fi
return 0
}
parse_git_commit() {
if $(git rev-parse --short HEAD &>/dev/null); then
local sha='';
sha=$(git rev-parse --short HEAD 2>/dev/null)
echo " ${cyan}@${reset} ${bold}${yellow}${sha}${reset}"
fi
}
### Spaceship
# PACKAGE
# Show current package version
spaceship_package() {
[[ $SPACESHIP_PACKAGE_SHOW == false ]] && return
# Show package version only when repository is a package
# @todo: add more package managers
[[ -f package.json ]] || return
_exists npm || return
# Grep and cut out package version
# Grep -E does not support \d for digits shortcut, should use [:digit:] or [0-9] instead
local package_version=$(grep -E '"version": "v?([0-9]+\.){1,}' package.json | cut -d\" -f4 2> /dev/null)
# Handle version not found
if [ ! "$package_version" ]; then
package_version=" ⚠"
else
package_version=" v${package_version}"
fi
echo "${red} ${SPACESHIP_PACKAGE_PREFIX}${SPACESHIP_PACKAGE_SYMBOL}${package_version}${reset}"
# _prompt_section \
# "${SPACESHIP_PACKAGE_COLOR}" \
# "$SPACESHIP_PACKAGE_PREFIX" \
# "${SPACESHIP_PACKAGE_SYMBOL}${package_version}" \
# "$SPACESHIP_PACKAGE_SUFFIX"
}
# NODE
# Show current version of node, exception system.
spaceship_node() {
[[ $SPACESHIP_NODE_SHOW == false ]] && return
# Show NODE status only for JS-specific folders
# [[ -f package.json || -d node_modules || -n *.js ]] || return
[[ -f package.json || -d node_modules ]] || return
local node_version
if _exists nvm; then
node_version=$(nvm current 2>/dev/null)
[[ $node_version == "system" || $node_version == "node" ]] && return
elif _exists nodenv; then
node_version=$(nodenv version-name)
[[ $node_version == "system" || $node_version == "node" ]] && return
elif _exists node; then
node_version=$(node -v 2>/dev/null)
[[ $node_version == $SPACESHIP_NODE_DEFAULT_VERSION ]] && return
else
return
fi
echo "${green} ${SPACESHIP_NODE_PREFIX}${SPACESHIP_NODE_SYMBOL}${node_version}${reset}"
# _prompt_section \
# "$SPACESHIP_NODE_COLOR" \
# "$SPACESHIP_NODE_PREFIX" \
# "${SPACESHIP_NODE_SYMBOL}${node_version}" \
# "$SPACESHIP_NODE_SUFFIX"
}
tput sgr0; # reset colors
bold=$(tput bold);
reset=$(tput sgr0);
# base16-eighties colors, taken from http://chriskempson.github.io/base16/#eighties
black=$(tput setaf 236); #done.
blue=$(tput setaf 68); #done
cyan=$(tput setaf 80); #done.
green=$(tput setaf 114); #done.
orange=$(tput setaf 209); #done.
purple=$(tput setaf 176); #done
red=$(tput setaf 210); #done
violet=$(tput setaf 61);
white=$(tput setaf 15);
yellow=$(tput setaf 221); #done.
# Highlight the user name when logged in as root.
if [[ "${USER}" == "root" ]]; then
userStyle="${bold}${red}";
else
userStyle="${bold}${green}";
fi;
export PS1="${orange}\t${reset} ${userStyle}\u${reset}@${cyan}\h${reset} \w \$(parse_git_branch)\$(parse_git_commit)\$(git_dirty_stash)\$(spaceship_package)\$(spaceship_node) \n$ "