-
Notifications
You must be signed in to change notification settings - Fork 0
/
gCustomPrompt.sh
43 lines (39 loc) · 1.27 KB
/
gCustomPrompt.sh
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
#!/bin/bash
# This script is used to customize the prompt for the gitBranchTool.
# Author: Cyrus Mobini - https://github.com/cyrus2281
# Github Repository: https://github.com/cyrus2281/gitBranchTool
# License: MIT License
# Custom prompt
__g_get_propmt() {
brn=""
branch=$(git branch 2> /dev/null | grep \* | cut -d "*" -f2 | cut -d " " -f2)
if [[ -n $branch ]]; then
alias=$(g get-branch-alias $branch -N)
if [[ -n $alias ]]; then
branch="$branch ($alias)"
fi
topPath="$(git rev-parse --show-toplevel)"
repo=$(basename $topPath)
# Find the index of the repository name in the current working directory
index=$(echo "$PWD" | awk -v repo="$repo" '{print index($0, repo)}')
# Use expr to calculate the start position for the subpath
start=$((index + ${#repo}))
# Extract the subpath after the repository name
subpath="${PWD:$start}"
# Remove leading slash if present
subpath=${subpath#/}
# Check if subpath is not empty and set it to [subpath]
if [ -n "$subpath" ]; then
subpath=" [$subpath]"
fi
brn="$repo$subpath ⌥ $branch "
else
brn="$(pwd) "
fi
echo $brn
}
__update_prompt() {
PS1="$(whoami) ➤ $(__g_get_propmt) ❖ "
}
PROMPT_COMMAND=__update_prompt
precmd() { eval "$PROMPT_COMMAND"; }