11#! /bin/bash
2- # Shell prompt based on the Solarized Dark theme.
3- # Screenshot: http://i.imgur.com/EkEtphC.png
4- # Heavily inspired by @necolas’s prompt: https://github.com/necolas/dotfiles
5- # iTerm → Profiles → Text → use 13pt Monaco with 1.1 vertical spacing.
6- # vim: set filetype=sh :
7-
8- if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color > /dev/null 2>&1 ; then
9- export TERM=' gnome-256color' ;
10- elif infocmp rxvt-unicode-256color > /dev/null 2>&1 ; then
11- export TERM=' rxvt-unicode' ;
12- elif infocmp xterm-256color > /dev/null 2>&1 ; then
13- export TERM=' xterm-256color' ;
14- fi ;
15-
16- prompt_git () {
17- local s=' ' ;
18- local branchName=' ' ;
19-
20- # Check if the current directory is in a Git repository.
21- if [ " $( git rev-parse --is-inside-work-tree & > /dev/null; echo " ${?} " ) " == ' 0' ]; then
22-
23- # check if the current directory is in .git before running git checks
24- if [ " $( git rev-parse --is-inside-git-dir 2> /dev/null) " == ' false' ]; then
25-
26- if [[ -O " $( git rev-parse --show-toplevel) /.git/index" ]]; then
27- git update-index --really-refresh -q & > /dev/null;
28- fi ;
29-
30- # Check for uncommitted changes in the index.
31- if ! git diff --quiet --ignore-submodules --cached; then
32- s+=' +' ;
33- fi ;
34-
35- # Check for unstaged changes.
36- if ! git diff-files --quiet --ignore-submodules --; then
37- s+=' !' ;
38- fi ;
39-
40- # Check for untracked files.
41- if [ -n " $( git ls-files --others --exclude-standard) " ]; then
42- s+=' ?' ;
43- fi ;
44-
45- # Check for stashed files.
46- if git rev-parse --verify refs/stash & > /dev/null; then
47- s+=' $' ;
48- fi ;
49-
50- fi ;
51-
52- # Get the short symbolic ref.
53- # If HEAD isn’t a symbolic ref, get the short SHA for the latest commit
54- # Otherwise, just give up.
55- branchName=" $( git symbolic-ref --quiet --short HEAD 2> /dev/null || \
56- git rev-parse --short HEAD 2> /dev/null || \
57- echo ' (unknown)' ) " ;
58-
59- [ -n " ${s} " ] && s=" [${s} ]" ;
60-
61- echo -e " ${1}${branchName}${blue}${s} " ;
62- else
63- return ;
64- fi ;
2+ function set_win_title(){
3+ echo -ne " \033]0; ${PWD} \007"
654}
66-
67- cloud=" "
68- if [[ -f /proc/cpuinfo ]] && grep -q " ^flags.* hypervisor" /proc/cpuinfo && [[ ! -d " /mnt/c/Windows/" ]]; then
69- cloud=" ☁️ "
70- fi
71-
72- if tput setaf 1 & > /dev/null; then
73- tput sgr0; # reset colors
74- bold=$( tput bold) ;
75- reset=$( tput sgr0) ;
76- # Solarized colors, taken from http://git.io/solarized-colors.
77- black=$( tput setaf 0) ;
78- blue=$( tput setaf 33) ;
79- cyan=$( tput setaf 37) ;
80- green=$( tput setaf 64) ;
81- orange=$( tput setaf 166) ;
82- purple=$( tput setaf 125) ;
83- red=$( tput setaf 124) ;
84- violet=$( tput setaf 61) ;
85- white=$( tput setaf 15) ;
86- yellow=$( tput setaf 136) ;
87- else
88- bold=' ' ;
89- reset=" \\ e[0m" ;
90- # shellcheck disable=SC2034
91- black=" \\ e[1;30m" ;
92- blue=" \\ e[1;34m" ;
93- cyan=" \\ e[1;36m" ;
94- green=" \\ e[1;32m" ;
95- # shellcheck disable=SC2034
96- orange=" \\ e[1;33m" ;
97- # shellcheck disable=SC2034
98- purple=" \\ e[1;35m" ;
99- red=" \\ e[1;31m" ;
100- violet=" \\ e[1;35m" ;
101- white=" \\ e[1;37m" ;
102- yellow=" \\ e[1;33m" ;
103- fi ;
104-
105- # Highlight the user name when logged in as root.
106- if [[ " ${USER} " == " root" ]]; then
107- userStyle=" ${red} " ;
108- else
109- userStyle=" ${blue} " ;
110- fi ;
111-
112- # Highlight the hostname when connected via SSH.
113- if [[ " ${SSH_TTY} " ]]; then
114- hostStyle=" ${bold}${cyan} " ;
115- else
116- hostStyle=" ${cyan} " ;
117- fi ;
118-
119- # Set the terminal title to the current working directory.
120- PS1=" \\ [\\ 033]0;\\ w\\ 007\\ ]" ;
121- PS1+=" \\ [${bold} \\ ]\\ n" ; # newline
122- PS1+=" \\ [${userStyle} \\ ]\\ u" ; # username
123- PS1+=" \\ [${white} \\ ] at " ;
124- PS1+=" \\ [${hostStyle} \\ ]${cloud} \\ h" ; # host
125- PS1+=" \\ [${white} \\ ] in " ;
126- PS1+=" \\ [${green} \\ ]\\ w" ; # working directory
127- PS1+=" \$ (prompt_git \" ${white} on ${violet} \" )" ; # Git repository details
128- PS1+=" \\ n" ;
129- PS1+=" \\ [${white} \\ ]\$ \\ [${reset} \\ ]" ; # `$` (and reset color)
130- export PS1;
131-
132- PS2=" \\ [${yellow} \\ ]→ \\ [${reset} \\ ]" ;
133- export PS2;
5+ # shellcheck disable=SC2034
6+ starship_precmd_user_func=" set_win_title"
7+ STARSHIP_CONFIG=" ${HOME} /.config/starship.toml"
8+ export STARSHIP_CONFIG
9+ eval " $( starship init bash) "
0 commit comments