summaryrefslogtreecommitdiff
path: root/src/.bashrc_ps1
diff options
context:
space:
mode:
Diffstat (limited to 'src/.bashrc_ps1')
-rw-r--r--src/.bashrc_ps145
1 files changed, 45 insertions, 0 deletions
diff --git a/src/.bashrc_ps1 b/src/.bashrc_ps1
new file mode 100644
index 0000000..33daa0d
--- /dev/null
+++ b/src/.bashrc_ps1
@@ -0,0 +1,45 @@
+# Dynamic PS1: exit code, time, user, current directory, git, colorized
+function update_ps1 {
+ local exit_code=$?
+
+ # Color exit code: green if 0, red otherwise
+ if [[ $exit_code -eq 0 ]]; then
+ local exit_display="\[\033[1;32m\]$exit_code\[\033[0m\]" # green
+ else
+ local exit_display="\[\033[1;31m\]$exit_code\[\033[0m\]" # red
+ fi
+
+ # Symbol always white
+ local symbol="\[\033[1;37m\]\$\[\033[0m\]"
+
+ # White brackets
+ local open_bracket="\[\033[1;37m\][\[\033[0m\]"
+ local close_bracket="\[\033[1;37m\]]\[\033[0m\]"
+
+ # Time in HH:MM:SS
+ #local time="\[\033[1;37m\]\t\[\033[0m\]"
+
+ # User
+ #local user="\[\033[1;37m\]\u\[\033[0m\]"
+ local user="\[\033[1;36m\]\u\[\033[0m\]"
+
+ # Current folder only, ~ for home
+ local folder="\[\033[1;33m\]\W\[\033[0m\]"
+
+ # Git status
+ local git_status=""
+ if [[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" == true ]]; then
+ if [[ -z $(git log origin/master..HEAD 2>/dev/null) ]]; then
+ git_status="\[\033[1;38;5;10m\](git)\[\033[0m\]" # green if up to date
+ else
+ git_status="\[\033[1;38;5;9m\](git)\[\033[0m\]" # red if ahead
+ fi
+ fi
+
+ # Build the prompt
+ export PS1="${open_bracket} ${exit_display} ${user} ${folder} ${git_status}${close_bracket} ${symbol} "
+}
+
+
+# Update PS1 after every command
+PROMPT_COMMAND='update_ps1'