You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Some tweaks](../2024/2024-01-05-bash-git-prompt-tweaks.md) I made to [bash-git-prompt](https://github.com/magicmonty/bash-git-prompt). dynamic Python venv path, new var `GIT_MESSAGE`, etc.
Copy file name to clipboardExpand all lines: docs/posts/2024/2024-01-05-bash-git-prompt-tweaks.md
+44-32Lines changed: 44 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,7 @@ categories:
8
8
comments: true
9
9
date:
10
10
created: 2024-01-05
11
+
updated: 2025-07-12
11
12
description: Some personal tweaks in bash-git-prompt
12
13
---
13
14
@@ -21,32 +22,28 @@ Some tweaks I made to [bash-git-prompt](https://github.com/magicmonty/bash-git-p
21
22
22
23
bash-git-prompt displays the current Python venv folder name within the prompt, among other things. I would like it to display the full path of the current Python venv if the venv is not located in the current folder. This will help prevent me from using the wrong venv when I switch between projects.
23
24
24
-
To achieve this, I have to modify the `gp_add_virtualenv_to_prompt` function in the `~/.bash-git-prompt/gitprompt.sh` script, as I used the [git clone method](https://github.com/magicmonty/bash-git-prompt#via-git-clone) to install bash-git-prompt.
25
-
26
-
```diff title="if the venv is not .venv inside current folder, display the full path of the venv. Node and Conda venv are not modified as I don't use them."
27
-
function gp_add_virtualenv_to_prompt {
28
-
local ACCUMULATED_VENV_PROMPT=""
29
-
local VENV=""
30
-
if [[ -n "${VIRTUAL_ENV-}" && -z "${VIRTUAL_ENV_DISABLE_PROMPT+x}" ]]; then
To achieve this, add following code into `function gp_add_virtualenv_to_prompt` in `~/.bash-git-prompt/gitprompt.sh` to add Python virtual environment name and version to the prompt.
if [[ -n "${NODE_VIRTUAL_ENV-}" && -z "${NODE_VIRTUAL_ENV_DISABLE_PROMPT+x}" ]]; then
50
47
```
51
48
52
49
## New var GIT_MESSAGE
@@ -59,20 +56,35 @@ alias gitpush='git ci -am "$GIT_MESSAGE" ; git push origin $GIT_BRANCH`
59
56
60
57
So I can just type `gitpush` to commit and push my changes to the remote repo.
61
58
62
-
To achieve this, I have to add one line right after `GIT_BRANCH` in the `~/.bash-git-prompt/gitprompt.sh` script.
59
+
To achieve this, declare a function `set_git_message` in `~/.bash-git-prompt/gitprompt.sh` to set the `GIT_MESSAGE` variable based on the current branch name. Then, call `set_git_message` in the `updatePrompt` function in the same file to get called upon each prompt re-computation, for e.g. right after the line `export GIT_BRANCH=$(replaceSymbols "${git_status_fields[@]:0:1}")`.
0 commit comments