Questions about the BASH shell's PS1 input prompt facility. DO NOT USE this tag for questions about PowerShell scripts, use [powershell] instead.
Questions tagged [ps1]
285 questions
9
votes
5 answers
Use PS0 and PS1 to display execution time of each bash command
It seems that by executing code in PS0 and PS1 variables (which are eval'ed before and after a prompt command is run, as I understand) it should be possible to record time of each running command and display it in the prompt. Something like…
![](../../users/profiles/272865.webp)
Vladimir Keleshev
- 11,246
- 15
- 57
- 88
9
votes
2 answers
Only list host in the bash prompt if running remotely?
I'm trying to modify my Bash prompt to my will; this is how $PS1 looks at the moment (with colors edited out for clarity):
PS1='\u@\h:\w\$ '
Which results in:
andreas@tablet-2710p-ubuntu:~$
Can I tweak the prompt so it hides the…
![](../../users/profiles/617937.webp)
IQAndreas
- 7,014
- 4
- 36
- 63
8
votes
1 answer
PS1 env cannot parse on the new mac Catalina
My PS1 variable cannot parsed correctly, it looks like this,
\[\033[01;32m\]\u@\h\[\033[01;34m\] [\w]\[\033[00m\]
\[\033[01;32m\]\u@\h\[\033[01;34m\] [\w]\[\033[00m\]
\[\033[01;32m\]\u@\h\[\033[01;34m\] [\w]\[\033[00m\]mv .bashrc…
![](../../users/profiles/8183106.webp)
Polaris
- 316
- 3
- 10
8
votes
1 answer
Simplifying advanced Bash prompt variable (PS1) code
So I've found the following cool Bash prompt:
..with the very basic logic of:
PS1="\[\033[01;37m\]\$? \$(if [[ \$? == 0 ]]; then echo \"\[\033[01;32m\]\342\234\223\"; else echo \"\[\033[01;31m\]\342\234\227\"; fi) $(if [[ ${EUID} == 0 ]]; then echo…
![](../../users/profiles/1821548.webp)
Det
- 3,447
- 2
- 18
- 26
8
votes
6 answers
How to add an icon to the bash prompt
I know you can edit the bash prompt permanently by editing the PS1 variable in your ~/.bashrc file, mine looks like this:
PS1="\[\e[0;31m\]\[\e[0;0m\]";
but can you set a tiny little image in there as well? For instance, if I wanted…
![](../../users/profiles/1467202.webp)
kjh
- 3,168
- 8
- 32
- 71
8
votes
1 answer
bash: How to evaluate PS1, PS2, ...?
Possible Duplicate:
Echo expanded PS1
Is there any way to 'evaluate' PS1, PS2, etc from within a bash script?
Although, I can use alternate means to get all elements of my current PS1, I would really like to be able to reuse its definition…
![](../../users/profiles/125540.webp)
Harry
- 3,264
- 4
- 33
- 45
6
votes
1 answer
Anaconda environment bash prefix too long
I created an anaconda environment in a project folder specifying the path with -p option, i.e. not in the default anaconda3/envs folder:
conda create -p venv
The problem is that when I activate that environment, the bash prefix in the terminal is…
![](../../users/profiles/1526756.webp)
Dark Templar
- 896
- 8
- 23
6
votes
2 answers
Launch powershell script with keyboard hotkey
I want to execute a powershell script (ps1-file) with a hotkey on my keyboard (CTRL + SHIFT + F for instance).
I managed to create a shortcut of the script (right click in explorer > new > shortcut). The shortcut's target is:…
![](../../users/profiles/4019429.webp)
theRunner
- 129
- 1
- 8
6
votes
1 answer
Changing Prompt from Shell Script?
I'm new to shell scripting and can't for the life of me figure out why this isn't working.
I'm trying to change the prompt from inside my shell script. It works when I type it into the terminal, but does nothing when I run the script and choose it…
![](../../users/profiles/6039891.webp)
PSherman
- 61
- 1
- 3
6
votes
2 answers
Bash printf %q invalid directive
I want to change my PS1 in my .bashrc file.
I've found a script using printf with %q directive to escape characters :
#!/bin/bash
STR=$(printf "%q" "PS1=\u@\h:\w\$ ")
sed -i '/PS1/c\'"$STR" ~/.bashrc
The problem is that I get this error…
![](../../users/profiles/3552679.webp)
il0venoobs
- 127
- 3
- 8
6
votes
3 answers
Bash PS1 shows $ instead of # for root
When logging into root, the default prompt when echoed is \s-\v\$, which shows as bash-4.2#. I am trying to play around with the bash prompt so it displays the working directory.
export PS1="\w \$".
The prompt displays correctly, however, the symbol…
![](../../users/profiles/1042350.webp)
dook
- 973
- 1
- 10
- 26
6
votes
1 answer
How do I set $? in functions called by PS1?
I currently have a prompt in bash that calls a function to output the return code of the last command run (if non-zero):
exit_code_prompt()
{
local exit_code=$?
if [ $exit_code -ne 0 ]
then
tput setaf 1
printf "%s"…
![](../../users/profiles/973568.webp)
Stephen Wattam
- 505
- 2
- 12
5
votes
1 answer
Dynamic elements in bash PS1
I have put the following in my ~/.localsh file to customize my bash prompt when working with git.
Basically I want to get the current branch displayed in my terminal.
The gitk tool shows branches with green background and black foreground, so thats…
![](../../users/profiles/180464.webp)
eric.frederich
- 1,338
- 2
- 15
- 27
5
votes
1 answer
How to convert Powershell to C#
Is possible to convert PowerShell code .PS1 to C# code?
I'v been looking to it on google but I always find the contrary.
Reflector has the AddIn to convert DLL to PS Code, so I think it's possible..
![](../../users/profiles/1259559.webp)
hello B
- 826
- 3
- 16
- 39
5
votes
2 answers
PS1 bash command substitution not working on windows 10
This is my script that sets up my bash PS1
# Reset
Color_Off="\[\033[0m\]" # Text Reset
# Regular Colors
Black="\[\033[0;30m\]" # Black
Red="\[\033[0;31m\]" # Red
Green="\[\033[0;32m\]" # Green
Yellow="\[\033[0;33m\]" …
![](../../users/profiles/1683287.webp)
StefanoGermani
- 701
- 7
- 18