Modification of Prompt string to display useful details in PASE terminal
- Dominant language
- MDX
- Stars
- 5
- Forks
- 37
- Avg merge
- 23h 25m
- Merged PRs (30d)
- 1
Description
# Modification of Prompt string to display useful details in PASE terminal.
## Simple Method:
By modifying the `PS1` environment variable, we can we can display useful information like
username, server name, current working directory etc., like below

This would help the users to know exactly where they're currently located at without the need to issue a `pwd` command.
We only need to create a `.profile` file in the user's home directory and place the code below
```sh
echo 'PS1="\[\e[32m\]\u\[\e[0m\]@\[\e[32m\]\h\[\e[33m\]:\w\[\e[0m\]\$ "' >> ~/.profile
```
## Advanced Method:
By modifiying the `PROMPT_COMMAND`, we can display the git status on the prompt string.
When I was learning Git, I modified the powershell terminal to reflect the git status of my current working git directory. There was an application called [posh git](https://github.com/dahlbyk/posh-git) which would show us the git status on the prompt itself like below. I was trying to replicate the same in PASE. Then I came to know about the `__posh_git_ps1` shell function which can output the Git Status in an easily understandable string format.

This means, I am currently on the folder called `gitrepo` which is a git repository.
The cyan master = Branch name
? = No remote repository configured
The green +1 = One file is tracked and it is newly added
The red +2 = Two files are added and untracked
### Step-1:
First, get the `git-prompt.sh` shell script that can evaluate the git status. You can read more about this script [here](https://github.com/lyze/posh-git-sh).
```sh
/QOpenSys/pkgs/bin/wget --show-progress https://raw.githubusercontent.com/lyze/posh-git-sh/refs/heads/master/git-prompt.sh -O .git-prompt.sh
```
### Step-2:
Setup the open source path variable in `.profile` file. This is required or the `git-prompt.sh` to work correctly.
```sh
echo "export PATH=/QOpenSys/pkgs/bin:$PATH" >> .profile
```
### Step-3:
Setup the `PROMPT_COMMAND` to reflect the git status. Run the three commands one by one. Know that the `PROMPT_COMMAND` is a special shell variable that gets executed each time before the shell's primary prompt (PS1) is displayed.
```sh
echo "PROMPT_COMMAND='__posh_git_ps1 \"\${VIRTUAL_ENV:+(\`basename \$VIRTUAL_ENV\`)}\\[\\e[32m\\]\\u\\[\\e[0m\\]@\\h:\\[\\e[33m\\]\\w\\[\\e[0m\\] \" \"\\\\\\\$ \";'\$PROMPT_COMMAND" >> .profile
echo "source ~/.git-prompt.sh" >> .profile
source ~/.profile
```
### How it works?
We are instructing the `PROMPT_COMMAND` to call the `git-prompt.sh` script everytime the prompt is displayed.
The function `__posh_git_ps1` takes two parameters (`__posh_git_ps1 `), and sets `PS1` to ``.
By default, the status summary has the following format:
Click here to read the full legend of the Git Prompt
```sh
[{HEAD-name} x +A ~B -C !D | +E ~F -G !H W]
```
* `{HEAD-name}` is the current branch, or the SHA of a detached HEAD. The color
of `{HEAD-name}` represents the divergence from upstream. `{HEAD-name}` also
changes to indicate progress if you are in the middle of a cherry-pick, a
merge, a rebase, etc.
* `cyan` the branch matches its remote
* `green` the branch is ahead of its remote (green light to push)
* `red` the branch is behind its remote
* `yellow` the branch is both ahead of and behind its remote
* `x` is a symbol that represents the divergence from upstream.
* `≡` the branch matches its remote
* `↑` the branch is ahead of its remote
* `↓` the branch is behind its remote
* `↕` the branch is both ahead of and behind its remote
* Status changes are indicated by prefixes to `A` through `H`, where `A` through
`D` represent counts for the index and `E` through `H` represent counts for
the working directory. As in `git status`, index status is dark green and
working directory status is dark red.
* `+` added
* `~` modified
* `-` removed
* `!` conflicting
* `W` represents the overall status of the working directory.
* `!` there are unstaged changes in the working tree
* `~` there are uncommitted changes, i.e. staged changes, in the working tree
waiting to be committed
* None: there are no unstaged or uncommitted changes to the working tree
For example, a status of `[master ≡ +0 ~2 -1 | +1 ~1 -0 !]` corresponds to the
following `git status`:
# On branch master
#
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
#
# modified: this-changed.txt
# modified: this-too.txt
# deleted: gone.txt
#
# Changed but not updated:
# (use "git add ..." to update what will be committed)
# (use "git checkout -- ..." to discard changes in working directory)
#
# modified: not-staged.txt
#
# Untracked files:
# (use "git add ..." to include in what will be committed)
#
# new.txt
### Final Thoughts
Instead of [this](https://github.com/codefori/vscode-ibmi/blob/15ad548221d394ddf182ee8c13ad1d0cab325cb2/src/api/IBMi.ts#L781) line can we execute the above steps to display useful information on the PASE terminal prompt?
I have a working demo of both the methods which I can explain on the next code-for-i Friday meeting.
Thanks,
Ravi.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.