WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Prompt  (Read 3349 times)

Offline TomyTurbos

  • Jr. Member
  • **
  • Posts: 95
Prompt
« on: February 17, 2019, 11:31:29 PM »
I feel like a total newb asking this...

What I want is my prompt to be as follows:

(user)@(host)[color][maybe date and time here?]
(current-directory)[different-color]
{type-stuff-here[different-color]}  <--this is the cursor behavior.

The newlines are significant.

I'm looking but not finding a succinct answer for how this might be done.
'(current-directory)' should be explicit path name for PWD.

TIA.
« Last Edit: February 17, 2019, 11:40:36 PM by TomyTurbos »

Offline TomyTurbos

  • Jr. Member
  • **
  • Posts: 95
Re: Prompt
« Reply #1 on: February 17, 2019, 11:53:25 PM »
Here's an example of what I mean:

foo@bar 25:61 02/30/3147
/home/foo
{cursor}
« Last Edit: February 17, 2019, 11:56:03 PM by TomyTurbos »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11695
Re: Prompt
« Reply #2 on: February 18, 2019, 12:06:08 AM »
Hi TomyTurbos
Try this in a terminal:
Code: [Select]
export PS1='\u@\h:${YELLOW}$(date "+%a %b %d %T") ${RED}$PWD\$${GREEN} 'Alter the  PS1  variable in your  .profile  file to make it permanent.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11695
Re: Prompt
« Reply #3 on: February 18, 2019, 12:35:37 AM »
Hi TomyTurbos
The above example was derived from these threads:
http://forum.tinycorelinux.net/index.php/topic,10429.msg55808.html#msg55808
http://forum.tinycorelinux.net/index.php/topic,3281.msg17139.html#msg17139

Here's an example that modifies the title bar of a terminal so it dynamically lists the current directory:
http://forum.tinycorelinux.net/index.php/topic,274.msg1657.html#msg1657
and a link from that thread that may be useful:
http://www.faqs.org/docs/Linux-mini/Xterm-Title.html

Offline TomyTurbos

  • Jr. Member
  • **
  • Posts: 95
Re: Prompt
« Reply #4 on: February 18, 2019, 12:59:52 AM »
Thanks for all that, rich.  I'll get back to you after school...

Offline TomyTurbos

  • Jr. Member
  • **
  • Posts: 95
Re: Prompt
« Reply #5 on: February 18, 2019, 11:59:35 PM »
Well, after some experimentation I wound up with what I wanted by using this in '/home/tc/.profile':

Code: (bash) [Select]
PS1='n\ ${RED}$(date "+%a %b %d %T")\n ${WHITE}\u@\h:\n ${BLUE}$PWD\/\n${GREEN}>> ${WHITE}'

My prompt now shows as:
Day Month Date Time
User@Host
Current Directory
>>

Note:  These are indented by one space. The line in the middle is white.
Part of the reason for doing this was to make it easier to find the breakpoints when scrolling back through a long list of terminal output.

But during the process I noted some unusual behavior in aterm while using 'export' and testing this.  At some point the command became lengthy enough that it could no longer be edited without restarting. Backspace and Delete became Paste.

As I said above, I solved my problem and have no more concern for the matter,  but this reveals a fluke elsewhere in the system. I thought I should report it.

« Last Edit: February 19, 2019, 12:01:54 AM by TomyTurbos »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11695
Re: Prompt
« Reply #6 on: February 19, 2019, 12:15:25 AM »
Hi TomyTurbos
Well, after some experimentation I wound up with what I wanted by using this in '/home/tc/.profile':

Code: (bash) [Select]
PS1='n\ ${RED}$(date "+%a %b %d %T")\n ${WHITE}\u@\h:\n ${BLUE}$PWD\/\n${GREEN}>> ${WHITE}'

If that code snippet is accurate, then the  n\  at the beginning is a typo and might account for the unusual behavior you mentioned.
It should be  \n  if you intended to put a linefeed there.
 

Offline TomyTurbos

  • Jr. Member
  • **
  • Posts: 95
Re: Prompt
« Reply #7 on: February 19, 2019, 10:10:44 AM »
Yes, that is a typo.