I am looking for a way to print the bash prompt, command and its output as shown below into an image for documentation purposes while studying, I wrote a quick command to do that, but I need the bash prompt to be automatically printed instead of me changing this part of the command [$USER@`hostname` ~]#
when the user or path changes, not forgetting the tilde for home directory and #/$ depending on whether the user is root or not so that all I need to change is cmd="ls -l";
, I also don't want to use $PWD because I get the complete path, rather I need exact bash prompt:
cmd="ls -l"; convert -font DejaVu-Sans-Mono-Book -pointsize 16 label:"$(echo "[$USER@`hostname` ~]# $cmd\n";$cmd)" /home/myuser/Desktop/result.png
The above results in this image, note that [root@centos7 ~] is also included in the image:
I tried the variable $PS1 from this answer and this answer, but I get:
[\u@\h \W]\$
Thank you
bash
; there you could probably useps1=$(PS1=$PS1 bash -i 2>&1 </dev/null); ps1=${ps1%exit}