how can I change the place where the command line is written

1

I want to change the ps1 and make it look like that

╔Dir: /root/
╠cmd: #aqui se escriben los comandos
╚[user1]

but I do not know if you can do this .. if you can someone help me ..

    
asked by iknxhk 10.06.2018 в 03:12
source

2 answers

2

Yes it is possible to make your terminal look exactly as you want using ANSI escape codes :

PS1='╔Dir: \w\n╠cmd: \n╚[\u]\[\e[A\e[6G\] '

The problem is that the part where the user goes will end up being replaced by the information that the commands or the same interpreter print on the screen.

For example, when executing echo foo , this is how my terminal looks before executing the command:

And that's how it looks after running it (see how foo and ╚[user] combine):

I assume that it is possible to overcome this problem with more complex escape codes, using PROMPT_COMMAND or writing some type of wrapper, but my recommendation is that you keep the part of the command down to avoid problems:

PS1='╔Dir: \w\n╠[\u]\n╚cmd: '

As an additional note, it is also possible to color the prompt using the escape codes mentioned above:

PS1='\[\e[1;34m\]╔Dir: \[\e[1;32m\]\w\[\e[0m\]\n\[\e[1;34m\]╠[\[\e[1;32m\]\u\[\e[1;34m\]]\[\e[0m\]\n\[\e[1;34m\]╚cmd:\[\e[0m\] '

Related links

answered by 01.08.2018 в 12:25
0

To change the prompt you must use the export command and enter as a parameter the environment variable you intend to change:

export PS1="Dir: \w \u cmd:“

As you can see, I have changed the order of what you want in your promt, because, as far as I know, it is impossible to enter the commands in the middle of the promt. \ w refers to the path of the current working directory (\ W so that only the directory is read, and not the entire path), and \ u to the user. In any case, export will change the promt temporarily. If you want to make it final, you must include that line in your .bashrc file as follows:

echo 'export PS1="Dir: \w \u cmd:" ' >> ~/.bashrc'
    
answered by 03.07.2018 в 03:52