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
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
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 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.
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.
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 <prefix> <suffix>), and sets PS1 to <prefix><status><suffix>.
By default, the status summary has the following format:
Click here to read the full legend of the Git Prompt
[{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 <file>..." to unstage)
#
# modified: this-changed.txt
# modified: this-too.txt
# deleted: gone.txt
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: not-staged.txt
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# new.txt
Final Thoughts
Instead of this 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.
The text was updated successfully, but these errors were encountered:
Very interesting topic @ravisankar-PIO !
However, I transferred it here as I think it should be a guideline rather than something automatically enforced by Code for i. What's displayed in the terminal prompt is a mater of personal choice.
Feel free to create a PR in this repository to add a topic in the Tips & Tricks section that explains the prompt customization as you did in this issue. It's quite valuable!
Looks good to me! Just rephrase it so it fits in a documentation, and maybe add a link to the list of available xterm color codes and to the available escape sequences - just so people know what they can use to customize their prompt 😉
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 likeusername, 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 belowAdvanced 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 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.Step-2:
Setup the open source path variable in
.profile
file. This is required or thegit-prompt.sh
to work correctly.Step-3:
Setup the
PROMPT_COMMAND
to reflect the git status. Run the three commands one by one. Know that thePROMPT_COMMAND
is a special shell variable that gets executed each time before the shell's primary prompt (PS1) is displayed.How it works?
We are instructing the
PROMPT_COMMAND
to call thegit-prompt.sh
script everytime the prompt is displayed.The function
__posh_git_ps1
takes two parameters (__posh_git_ps1 <prefix> <suffix>
), and setsPS1
to<prefix><status><suffix>
.Click here to read the full legend of the Git Prompt
{HEAD-name}
is the current branch, or the SHA of a detached HEAD. The colorof
{HEAD-name}
represents the divergence from upstream.{HEAD-name}
alsochanges to indicate progress if you are in the middle of a cherry-pick, a
merge, a rebase, etc.
cyan
the branch matches its remotegreen
the branch is ahead of its remote (green light to push)red
the branch is behind its remoteyellow
the branch is both ahead of and behind its remotex
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 remoteA
throughH
, whereA
throughD
represent counts for the index andE
throughH
represent counts forthe working directory. As in
git status
, index status is dark green andworking directory status is dark red.
+
added~
modified-
removed!
conflictingW
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 treewaiting to be committed
For example, a status of
[master ≡ +0 ~2 -1 | +1 ~1 -0 !]
corresponds to thefollowing
git status
:Final Thoughts
Instead of this 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.
The text was updated successfully, but these errors were encountered: