Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update git autocomplete bash so that it's not in the bashrc file. #42

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 50 additions & 20 deletions learners/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,47 @@ If you are using MacOS or Windows please consult the
[git autocomplete instructions](https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh)
at the top of the linked file.
Your instructor may point you to another online resource for your OS.
To enable this script add the following to your `~/.bashrc`
To enable this script add the following to a new `~/.bashrc.d/git.bash`
file:

```bash
# open a new terminal in the current working directory
source /etc/profile.d/vte.sh

GIT_PROMPT_PATH=~/git-prompt.sh
if [ -f "${GIT_PROMPT_PATH}" ]; then
source "${GIT_PROMPT_PATH}"
else
if [[ "$-" == *i* ]]; then
echo "${GIT_PROMPT_PATH} - not found, check version hasn't been updated"
if [[ $- =~ i ]]; then
GIT_PROMPT_PATH=~/git-prompt.sh
if [[ -r "${GIT_PROMPT_PATH}" ]]; then
source "${GIT_PROMPT_PATH}" >&2
else
if [[ "$-" == *i* ]]; then
echo "${GIT_PROMPT_PATH} - not found, check version hasn't been updated" >&2
fi
fi
export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWSTASHSTATE=1
export GIT_PS1_SHOWUPSTREAM="auto"
export GIT_PS1_SHOWCOLORHINTS=1
export GIT_PS1_SHOWUNTRACKEDFILES=1

export PROMPT_COMMAND=("${PROMPT_COMMAND[@]}" '__git_ps1 "${CONDA_PROMPT_MODIFIER}[\u@\h:\w]:" "\$ " "(%s)"')
export PS1='[\u@\h:\w]$(__git_ps1 "(%s)"):\$ '

# trim long working directory paths
PROMPT_DIRTRIM=3
fi
export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWSTASHSTATE=1
export GIT_PS1_SHOWUPSTREAM="auto"
export GIT_PS1_SHOWCOLORHINTS=1
export GIT_PS1_SHOWUNTRACKEDFILES=1
```

export PROMPT_COMMAND='__git_ps1 "${CONDA_PROMPT_MODIFIER}[\u@\h:\w]:" "\W\$ " "(%s)"'
export PS1='${CONDA_PROMPT_MODIFIER}[\u@\h:\w]$(__git_ps1 "(%s)"):\W\$ '
And make sure your `~/.bashrc` file includes:

# trim long working directory paths
PROMPT_DIRTRIM=3
```bash
# User specific aliases and functions

if [ -d ~/.bashrc.d ]; then
for rc in ~/.bashrc.d/*; do
if [ -f "$rc" ]; then
. "$rc"
fi
done
fi

unset rc
```

Your instructor will let you know if the value of `GIT_PROMPT_PATH` is
Expand All @@ -73,7 +88,8 @@ If you would like your own copy of the `git-prompt.sh` script you can
download the latest version from the
[git repository contrib directory](https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh).

If your `~/.bashrc` file already defines a `PROMPT_COMMAND` or `PS1`
If your `~/.bashrc` file, or any file in the `~/.bashrc.d/` directory,
already defines a `PROMPT_COMMAND` or `PS1`
you may need to merge what is shown above with your current script.
Your instructor may be able to help you with this.

Expand All @@ -96,6 +112,20 @@ To see the changes to your terminal prompt run:
source ~/.bashrc
```

::: callout

## Using MacOS or older versions of Bash

If your version of Bash is less than 5.1 or you are using
MacOS you might need to change the `export PROMPT_COMMAND`
line to:

```bash
export PROMPT_COMMAND=${PROMPT_COMMAND:+"$PROMPT_COMMAND; "}'__git_ps1 "${CONDA_PROMPT_MODIFIER}[\w]:" "\$ " "(%s)"'
```

:::

## Creating a GitHub Account

You will need an account for [GitHub](https://github.com) to follow episodes 7 & 8 in this lesson.
Expand Down