bash-prompt | Improved bash prompt with support for Git | Script Programming library
kandi X-RAY | bash-prompt Summary
kandi X-RAY | bash-prompt Summary
![screenshot] "Example screenshot of bash prompt."). Improved bash prompt with support for Git. Colors, display options and symbols are fully customizeable. Currently supports: * 16 colors. * Username & hostname. * Working directory (partial or full). * Git branch (with "dirty" status indicator).
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of bash-prompt
bash-prompt Key Features
bash-prompt Examples and Code Snippets
Community Discussions
Trending Discussions on bash-prompt
QUESTION
I want to use the last exit code to customize my bash prompt. So following this question I should add $?
inside a function:
ANSWER
Answered 2021-Feb-26 at 16:16Follow these instructions to configure your git-bash prompt.
First, open git-bash, and cd
to your ~
directory.
Using vim
or nano
, edit your ~/.bash_profile
file to contain the following two lines:
QUESTION
green="\033[0;32m"
Where \033
is the escape character and \003[
starts an escape sequence. However why doesn't it need a terminating character such as \]
I read \]
is required to terminate the escape sequence
https://tldp.org/HOWTO/Bash-Prompt-HOWTO/bash-prompt-escape-sequences.html
ANSWER
Answered 2021-Jan-05 at 01:18Why bash color encoding doesn't need terminating character?
It needs one and has one - the terminating character is m
.
why doesn't it need a terminating character such as ]
Because a character, in this case character m
, is used to detect the end of ansi escape sequence.
For more information read wikipedia ansi escape code and ECMA-35 around section 13 and ECMA-48 section 5.
I read ] is required to terminate the escape sequence
The \[
and \]
are used to notify bash that a prompt it uses has an ansi escape sequence inside if it, so that when bash calculates the length of line with the prompt it doesn't make mistakes.
It's used like:
QUESTION
The intent is to put the cursor at some position on the screen (around the center of the screen), enter some initial text, and prompt the user to enter more text to be saved in a variable, while leaving him the normal readline
line editing capabilities.
My initial attemp was to:
- center the cursor vertically
echo
/printf
ing some whitespace, - center the cursor horizontally again through
echo
/printf
, - issue
read -i "editable pre-text" -e answer
.
However I noticed the behavior described below, and crafted the following exemplifying two lines-code to demonstrate it.
When executing the following script
...ANSWER
Answered 2019-Oct-13 at 07:00As mentioned in a comment, you should use read
's -p
option to print the prompt, rather than trying to set it up before the read
command.
The -e
option asks read
to use the readline
library to handle the input, allowing a wider range of line-editing characters. However, in order to implement these behaviours, readline
needs to be able to redraw the current line, and that's not possible if there is anything on the current line when the read starts. It's not possible because Unix provides no mechanism for an application to look at what's being displayed on the console. So under some circumstances, readline
will simply clear the line. Using the -p
option allows readline
to output the prompt, and it can then know what the line currently looks like.
QUESTION
I am writing a game engine for Bash using the cursor movement feature described here. However, if I echo emojis or other UTF-8 characters that span more than 1 byte, the cursor position seems to get messed up.
For example, the following code is supposed to echo "13", move the cursor back 3 positions and then echo "abc" in the same place. The result should only be "abc" (ideally). Instead, I see "1abc"
...ANSWER
Answered 2019-Jun-28 at 12:50Try this:
QUESTION
I'm writing several bash-prompts functions in the style of oh-my-git and I want them to run in parallel and merge their output in order. Speed is of the essence and I want to avoid writing to any file system, be their in memory or on hard-drive.
My idea was to try to set variables in parallel but it's not doable in the same scope. GNU Parallel and parset does not seam to take in bash functions.
End of my .bashrc :
...ANSWER
Answered 2019-Jun-23 at 11:30To narrowly answer the question, spawning three process substitutions and concatenating their results will let the work happen in parallel, while generating output in a known order:
QUESTION
In my ~/.profile
I am using this in FreeBSD 12.0 which works great:
ANSWER
Answered 2019-Apr-12 at 07:10Moving the trap to after PS1
is set eliminated the problem. I don't know why that makes a difference.
QUESTION
I am on windows 10 and just had an issue with git bash.
When I was using git bash in the past month, it looked like the screenshot from this question.
However, something happened in the last week or so and now it looks like the one from this question instead.
I looked through the answers of both of those, and more, but none of them told me how to return it.
I tried installing/updating git through their website but that didn't help.
...ANSWER
Answered 2018-Nov-05 at 20:07Please try to add the below lines in your git config file and then restart the command prompt and run git commands.
QUESTION
I was working on my own bash prompt when hit strange behaviour (both iTerm and Terminal.app on macos). I managed to boil it down to the minimum working example:
~/.bash_profile:
...ANSWER
Answered 2018-Aug-13 at 16:00Bash has always had trouble handling long prompts with invisible characters, so the usual practice is to avoid them. For example, you could automatically trim the length of the prompt by omitting the beginning of the path if it is too long, or you could automatically output a trailing newline if the path is very long. (In such cases, you might want to use $COLUMNS
, which will normally tell you the width of the window.)
In patch 19 to bash v4.4 (which I realise is not really relevant to your environment since you seem to still be using the antique version of bash provided by a default OS X install), a long-standing bug was corrected, which had the effect of triggering a segfault in certain very rare cases of multiline prompts with both invisible and multibyte characters. The behaviour definitely changed between v4.4.18 and v4.4.19, but even with that patch very long prompts cause problems when the prompt extends to a third line.
There is a comment in lib/readline/display.c
which indicates that the readline library assumes that prompts will not exceed two lines. I suggest that you use that as a limit.
QUESTION
Assuming I call something like:
...ANSWER
Answered 2018-Jun-26 at 10:46It seems you are trying to read the list of all file/folder names in a particular directory. In your case the current working directory. It also appears you are interested in a *NIX solution since you tried to use ls
.
There are many ways to read the output from a subprocess into the parent process. You can use fork
/exec
with pipes or you are use popen
.
But for this example you need not go through ls
. You are directly read the directory using the Linux API.
You need to use the functions opendir
and readdir
.
Consider the following program -
QUESTION
I am attempting to reuse a shell function I have defined in bash script later on in the script, within a perl cmd execution block. The call to perl cmd basically needs to to run the defined shell function after matching a piece of the regex (capture group #2). See code definitions below.
The CodeThe pertinent function definition in bash shell script:
...ANSWER
Answered 2018-Jun-22 at 00:00The answer was to scrap this whole idea and use a better one..
Lets step back first.. Big Picture:
Goal was to make the script
program output an executable shell script of the entire recorded session.
Back to Answers..
The above implementation was supposed to remove all prompts and control characters from the output of script
(which is the input examples I gave) and then remove the output of each command (i.e. any line that didn't contain control characters).
Passing the evalPS
function to perl
to execute proved to be quite redundant and getting bash
and perl
to expand the parameters correctly was a nightmare..
The Final Solution
Scrapped the perl regex idea and used a combination of subshell and history redirection to grab the commands for the entire script
session, while it was running.
The entire implementation looks like this:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install bash-prompt
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page