Questions tagged [ps1]

Questions about the BASH shell's PS1 input prompt facility. DO NOT USE this tag for questions about PowerShell scripts, use [powershell] instead.

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…
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…
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…
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…
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…
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…
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…
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:…
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…
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…
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…
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"…
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…
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..
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\]" …
StefanoGermani
  • 701
  • 7
  • 18
1
2
3
18 19