Skip to content

Commit 398c6c5

Browse files
committed
fix: clean up install aliases, shell formatting
1 parent d17ca31 commit 398c6c5

18 files changed

Lines changed: 290 additions & 291 deletions

bash/bash_prompt.symlink

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
#
2323
# iTerm → Profiles → Text → use 13pt Menlo/Monaco with 1.1 vertical spacing.
2424

25-
if [[ $COLORTERM = gnome-* ]] && [[ $TERM = xterm ]] && infocmp gnome-256color &> /dev/null; then
25+
if [[ $COLORTERM = gnome-* ]] && [[ $TERM = xterm ]] && infocmp gnome-256color &>/dev/null; then
2626
export TERM="gnome-256color"
2727
elif infocmp xterm-256color >/dev/null 2>&1; then
2828
export TERM="xterm-256color"
2929
fi
3030

31-
if tput setaf 1 &> /dev/null; then
32-
tput sgr0; # reset colors
31+
if tput setaf 1 &>/dev/null; then
32+
tput sgr0 # reset colors
3333
bold=$(tput bold)
3434
reset=$(tput sgr0)
3535
# Default (http://www.calmar.ws/vim/256-xterm-24bit-rgb-color-chart.html)
@@ -122,20 +122,30 @@ yellow="\[$yellow\]"
122122
# Active git branch and icons representing git status...
123123
# git:main 2◀︎ ▶︎1 (3) M T A D R C U ? ! $
124124
################################################################################
125-
prompt_git () {
125+
prompt_git() {
126126
local working_dir_path="${1:-$PWD}"
127127
local git_icons=''
128128
local branch_name=''
129129
local change_count
130130
# Check if the current directory is in a Git repository.
131-
if type "git" &> /dev/null && [[ "$(cd "$working_dir_path"; git rev-parse --is-inside-work-tree &> /dev/null; echo ${?})" == '0' ]]; then
131+
if type "git" &>/dev/null && [[ "$(
132+
cd "$working_dir_path"
133+
git rev-parse --is-inside-work-tree &>/dev/null
134+
echo ${?}
135+
)" == '0' ]]; then
132136
# check if the current directory is in .git before running git checks
133-
if [[ "$(cd "$working_dir_path"; git rev-parse --is-inside-git-dir 2> /dev/null)" == 'false' ]]; then
137+
if [[ "$(
138+
cd "$working_dir_path"
139+
git rev-parse --is-inside-git-dir 2>/dev/null
140+
)" == 'false' ]]; then
134141
# Ensure the index is up to date.
135-
git update-index --really-refresh -q &> /dev/null
142+
git update-index --really-refresh -q &>/dev/null
136143
# Get git status output, in parse-ready format.
137144
# Info: https://git-scm.com/docs/git-status
138-
git_status_output="$(cd "$working_dir_path" || return; git status -b --show-stash --porcelain -u --ignore-submodules --ahead-behind --renames)"
145+
git_status_output="$(
146+
cd "$working_dir_path" || return
147+
git status -b --show-stash --porcelain -u --ignore-submodules --ahead-behind --renames
148+
)"
139149
git_status_output_branch="$(echo "${git_status_output}" | head -1)"
140150
git_status_output_changes="$(echo "${git_status_output}" | tail -n +2)"
141151
[[ -n "$git_status_output_changes" ]] && change_count="$(echo "${git_status_output_changes}" | wc -l)"
@@ -157,39 +167,39 @@ prompt_git () {
157167
fi
158168
[[ "$change_count" -gt 0 ]] && branch_name+=" ${gray}(${change_count})"
159169
# Modified in index / work tree changed since index.
160-
if [[ "$git_status_output" =~ .*M[\ MTD]\ .+ ]] \
161-
|| [[ "$git_status_output" =~ .*[\ MTARC]M\ .+ ]]; then
170+
if [[ "$git_status_output" =~ .*M[\ MTD]\ .+ ]] ||
171+
[[ "$git_status_output" =~ .*[\ MTARC]M\ .+ ]]; then
162172
git_icons+=" ${yellow}M"
163173
fi
164174
# File type changed in index. File type changed in work tree since index.
165-
if [[ "$git_status_output" =~ .*T[\ MTD]\ .+ ]] \
166-
|| [[ "$git_status_output" =~ .*[\ MTARC]T\ .+ ]]; then
175+
if [[ "$git_status_output" =~ .*T[\ MTD]\ .+ ]] ||
176+
[[ "$git_status_output" =~ .*[\ MTARC]T\ .+ ]]; then
167177
git_icons+=" ${purple}T"
168178
fi
169179
# Added from index, work tree.
170-
if [[ "$git_status_output" =~ .*A[\ MTDU]\ .+ ]] \
171-
|| [[ "$git_status_output" =~ .*[AU]A\ .+ ]]; then
180+
if [[ "$git_status_output" =~ .*A[\ MTDU]\ .+ ]] ||
181+
[[ "$git_status_output" =~ .*[AU]A\ .+ ]]; then
172182
git_icons+=" ${green}A"
173183
[[ "$git_status_output" =~ .*UA\ .+ ]] && git_icons+="⬆︎" # unmerged, added by them
174184
[[ "$git_status_output" =~ .*AU\ .+ ]] && git_icons+="⬇︎" # unmerged, added by us
175-
[[ "$git_status_output" =~ .*AA\ .+ ]] && git_icons+="" # unmerged, both added
185+
[[ "$git_status_output" =~ .*AA\ .+ ]] && git_icons+="" # unmerged, both added
176186
fi
177187
# Deleted from index, work tree.
178-
if [[ "$git_status_output" =~ .*D[\ DU]\ .+ ]] \
179-
|| [[ "$git_status_output" =~ .*[\ MTARC]D\ .+ ]]; then
188+
if [[ "$git_status_output" =~ .*D[\ DU]\ .+ ]] ||
189+
[[ "$git_status_output" =~ .*[\ MTARC]D\ .+ ]]; then
180190
git_icons+=" ${red}D"
181191
[[ "$git_status_output" =~ .*UD\ .+ ]] && git_icons+="⬆︎" # unmerged, deleted by them
182192
[[ "$git_status_output" =~ .*DU\ .+ ]] && git_icons+="⬇︎" # unmerged, deleted by us
183-
[[ "$git_status_output" =~ .*DD\ .+ ]] && git_icons+="" # unmerged, both deleted
193+
[[ "$git_status_output" =~ .*DD\ .+ ]] && git_icons+="" # unmerged, both deleted
184194
fi
185195
# Renamed in index, work tree.
186-
if [[ "$git_status_output" =~ .*R[\ MTD]\ .+ ]] \
187-
|| [[ "$git_status_output" =~ .*\ R\ .+ ]]; then
196+
if [[ "$git_status_output" =~ .*R[\ MTD]\ .+ ]] ||
197+
[[ "$git_status_output" =~ .*\ R\ .+ ]]; then
188198
git_icons+=" ${orange}R"
189199
fi
190200
# Copied in index, work tree.
191-
if [[ "$git_status_output" =~ .*C[\ MTD]\ .+ ]] \
192-
|| [[ "$git_status_output" =~ .*\ C\ .+ ]]; then
201+
if [[ "$git_status_output" =~ .*C[\ MTD]\ .+ ]] ||
202+
[[ "$git_status_output" =~ .*\ C\ .+ ]]; then
193203
git_icons+=" ${gray}C"
194204
fi
195205
# Unmerged, both modified.
@@ -199,8 +209,11 @@ prompt_git () {
199209
# Ignored files.
200210
[[ "$git_status_output" =~ .*\!\!\ .+ ]] && git_icons+=" ${dkgray}!"
201211
# Stashed files.
202-
if [[ "$git_status_output" =~ .*stash\ [0-9]+.* ]] \
203-
|| [[ $(cd "$working_dir_path"; git rev-parse --verify refs/stash &> /dev/null) ]]; then
212+
if [[ "$git_status_output" =~ .*stash\ [0-9]+.* ]] ||
213+
[[ $(
214+
cd "$working_dir_path"
215+
git rev-parse --verify refs/stash &>/dev/null
216+
) ]]; then
204217
git_icons+=" ${blue}$"
205218
fi
206219

@@ -218,11 +231,13 @@ prompt_git () {
218231
# Get the short symbolic ref.
219232
# If HEAD isn’t a symbolic ref, get the short SHA for the latest commit
220233
# Otherwise, just give up.
221-
[[ -z "$branch_name" ]] && branch_name="$(cd "$working_dir_path" || return; \
222-
git symbolic-ref --quiet --short HEAD 2> /dev/null || \
223-
git rev-parse --short HEAD 2> /dev/null || \
224-
git branch | tail -c +3 || \
225-
echo '(unknown)')"
234+
[[ -z "$branch_name" ]] && branch_name="$(
235+
cd "$working_dir_path" || return
236+
git symbolic-ref --quiet --short HEAD 2>/dev/null ||
237+
git rev-parse --short HEAD 2>/dev/null ||
238+
git branch | tail -c +3 ||
239+
echo '(unknown)'
240+
)"
226241

227242
echo "${violet}git${white}:${green}${branch_name}${git_icons}${reset}"
228243
fi
@@ -235,16 +250,16 @@ prompt_git () {
235250
PSUSERHOST="${gray}"
236251
# Highlight the user name when logged in as root.
237252
[[ "${USER:-}" == "root" ]] && PSUSERHOST="${red}"
238-
PSUSERHOST+=${USER:-$(id -un 2> /dev/null || echo "\u")}
253+
PSUSERHOST+=${USER:-$(id -un 2>/dev/null || echo "\u")}
239254
PSUSERHOST+="${dkgray} @ "
240255
# Highlight the hostname when connected via SSH.
241256
[[ "${SSH_TTY:-}" ]] && PSUSERHOST+="${bold}${red}"
242-
PSUSERHOST+=${HOST:-${HOSTNAME:-$(hostname 2> /dev/null || echo "\h")}}
257+
PSUSERHOST+=${HOST:-${HOSTNAME:-$(hostname 2>/dev/null || echo "\h")}}
243258
[[ "${SSH_TTY:-}" ]] && {
244-
PSUSERHOST+=-${UARCH:-${HOSTTYPE:-$(uname -p 2> /dev/null)}}
245-
PSUSERHOST+=-${UMACH:-${MACHTYPE:-$(uname -m 2> /dev/null)}}
259+
PSUSERHOST+=-${UARCH:-${HOSTTYPE:-$(uname -p 2>/dev/null)}}
260+
PSUSERHOST+=-${UMACH:-${MACHTYPE:-$(uname -m 2>/dev/null)}}
246261
}
247-
PSUSERHOST+=" ${dkgray}(${UTYPE:-${OSTYPE:-$(uname 2> /dev/null)}})${reset}"
262+
PSUSERHOST+=" ${dkgray}(${UTYPE:-${OSTYPE:-$(uname 2>/dev/null)}})${reset}"
248263

249264
#-------------------------------------------------------------------------------
250265
# PROMPT
@@ -313,10 +328,10 @@ function prompt_right() {
313328
function prompt() {
314329
local working_dir_path="$PWD"
315330
local compensate=9
316-
if tput cols &> /dev/null; then
317-
PS1=$(printf "\n%s%*s\r%s\n%s\n%s" "$(prompt_time)" "$(( $(tput cols) + compensate ))" "$(prompt_right)" "${PSTITLE:-}" "$(prompt_userhost)" "$(prompt_main "$working_dir_path")" 2> /dev/null)
331+
if tput cols &>/dev/null; then
332+
PS1=$(printf "\n%s%*s\r%s\n%s\n%s" "$(prompt_time)" "$(($(tput cols) + compensate))" "$(prompt_right)" "${PSTITLE:-}" "$(prompt_userhost)" "$(prompt_main "$working_dir_path")" 2>/dev/null)
318333
else
319-
PS1=$(printf "%s\n%s %s\n%s" "${PSTITLE:-}" "$(prompt_time)" "$(prompt_userhost)" "$(prompt_main "$working_dir_path")" 2> /dev/null)
334+
PS1=$(printf "%s\n%s %s\n%s" "${PSTITLE:-}" "$(prompt_time)" "$(prompt_userhost)" "$(prompt_main "$working_dir_path")" 2>/dev/null)
320335
fi
321336
# export PS1
322337
}

0 commit comments

Comments
 (0)