1

I'm using https://github.com/magicmonty/bash-git-prompt to customize my bash prompt. so, my prompt usually looks something like this

✔ ~/dotfiles [master|⚑ 1] 15:00 $

is there any command with which I can capture that prompt text? I want the [master|⚑ 1] text without having to copy the bash-git-prompt code into a new shell script.

kenwarner
  • 109

2 Answers2

2

if you're using bash 4.x, you can capture it into a variable

prompt="${PS1@P}"

or just output it for capture into a pipeline

echo "${PS1@P}"

You can also use script to capture a terminal session - including the prompt as displayed - to a file which you can then trim and use for whatever nefarious purposes:

$ script foo
user@host:~
$ exit
$ cat foo
Script started on Thu Jul  6 12:59:45 2017
user@host:~
$ exit
exit
Script done on Thu Jul  6 12:59:48 2017

Not shown here are all the ANSI color codes which spiff up the prompt.

DopeGhoti
  • 76,081
-1

Found a good solution here https://stackoverflow.com/a/44090232/55948

eval 'echo -en "'$PS1'"'

kenwarner
  • 109