For some reason whenever I shrink my terminal window to be shorter than my prompt, it will start appending my prompts on to one another. Below are all the lines in my .bashrc file that are concerned with the PS1 environment variable
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u#\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]'
and
export PS1="$PS1\$(__git_ps1)\[\033[00m\]\$ "
The problem I'm talking about can be seen in the following screenshots:
Related
(related: Identify gnome-terminal window by tab title)
When I open several tabs in GNOME Terminal (Version 3.44.0 for GNOME 42) on my Ubuntu 22.04, all tabs have the uninformative title "Terminal". I want them to be automatically titled:
the current working directory if it's in shell prompt (e.g. /home/user123/Downloads)
the name of the open process (e.g. vim ~/.bashrc) in case there is an open process.
How can I achieve that? I use bash, but I can switch to zsh if necessary.
From another thread somewhere on the internet:
function termtitle()
{
printf "\033]0;$*\007";
}
I put this in my .bashrc right above my PS1Update(). Then I call it in PS1Update, right after I update the prompt. I call it with a string constructed from some env flags, username, hostname, pwd. You can put almost anything. I throw in $0. I did try using $PS1, but I use color and I think the printf in termtitle() trips over the escape sequences. So I build another string with the same info but w/o color.
Every time the prompt is updated, so it the terminal window/tab title, like if I change dir, ssh to another machine.
Hope this helps!
I was editing .bash_profile and after I saved it ,terminal shows nothing.How can I reset it to previous mode.This is how it looks now.
I changed the value of PS1 variable.I don't have any knowledge about terminal.Please help.
The PS1 environment variable defines what the bash prompt looks like. The default varies among distros, but is generally something like this:
PS1='\h:\W \u\$ '
The bash manpage has an explanation of PS1 values under the heading "Prompting".
You can apply PS1 values to your current terminal session by pressing Control+C several times, then pasting in the line of code above and pressing return or enter. That should get your environment behaving normally long enough to edit your bash profile unless something else is wrong.
If something else is wrong with your profile, and bash is completely broken, you can temporarily use a different shell (one that doesn't care about your bash_profile) with the "New Command..." option in Terminal.app's file menu. When prompted for a command, enter /bin/zsh. You should then get a usable terminal window which you can use to edit or move your .bash_profile.
Whenever I start screen, it changes the title of the terminal window to 'screen'. Can I prevent that and have the window title remain what it would be if I hadn't run my command under screen?
More specifically, I'd like gnome-terminal to display the name of the buffer I'm editing in vim. I can do this by adding set title to my .vimrc. Now when I run vim, the buffer name (along with some other information), shows up in the title of gnome-terminal. When I start screen and run vim, the title changes to 'screen'.
I've looked at the following page:
http://beautifulpixels.blogspot.co.at/2012/01/automatic-screen-window-titles-in-bash.html
But the suggested solution places the window title in the screen status line. I also tried adding this:
case $TERM in
screen*)
# http://dtfm.tumblr.com/post/7193076007/the-sweetest-screenrc-hack-ever
SCREENTITLE='\[\ek\e\\\]\[\ek\W\e\\\]'
;;
*)
SCREENTITLE=''
;;
esac
TITLEBAR='\[\e]0;\a\]'
export PS1="${SCREENTITLE}${TITLEBAR}[\u#\h \W]\$ "
To my .bashrc, but this only sets the window title to the current directory. Even if I run vim, the window title remains the current working directory. This is not the case if I run it outside of screen.
Any ideas?
Although I didn't exactly solve it, demure's comment enticed me to check out tmux. Using that I was able to put the following line:
autocmd BufReadPost,FileReadPost,BufNewFile * call system("tmux rename-window '" . expand("%:p:~") . " - VIM'")
In my .vimrc file and I get the effect I wanted in the first place (except, of course, now I'm using tmux).
References:
tmux tabs with name of file open in vim
How can I expand the full path of the current file to pass to a command in Vim?
I'm looking for a way to make the cygwin terminal more compact, or an alternate terminal that is more compact. Currently, every command I enter has a header line above it with username and pwd, and there is a blank line trailing every command. For instance:
username ~
$ cd tmp
username ~/tmp
$
3 lines for every 1 line of command. I frequently work on a small screen, which makes all this wasted space quite irritating. Is there a setting somewhere I can alter to prevent all this wasted space? Or, perhaps another terminal?
Thanks in advance.
That's the default shell prompt set by Cygwin.
To use a smaller prompt in your current terminal:
PS1='$ '
To make the change permanent, put that command in your ~/.bashrc file.
You can set the prompt to just about anything you like, as explained by the bash manual (there are several variables that control different prompts; $PS1 is the main one).
It's important to remember than in Cygwin (as in Linux and Unix), the terminal program is a separate program from the shell that runs in it. The prompt is controlled by the shell; bash is the default. The graphical display is controlled by the terminal emulator, which could be rxvt, mintty, xterm, or even the Windows terminal that normally runs a DOS-like shell.
What you're seeing there is the prompt, as stored in the environment variable PS1
echo $PS1
will show you how it's created. By the way, that prompt is managed by the bash shell, not by the terminal.
export PS1=$
will give you just a $ prompt
export PS1="$ "
will leave some room behind the prompt. There are many more possibilities, here is a nice tutorial.
bash reads its settings from a file called ~/.bashrc aka a file called .bashrc in your home directory. Note that due to the initial dot in the name ls won't show the file by default, ls -a or ls -la will.
I would Recommend we go with modern terminals using Cygwin-X as shown in the below interactive menu
I love Xfce Terminal which allows creating tabs and new windows with font options and color options
My terminal previously showed subalcharla$ at the command line.
The terminial is now showing subalcharla#subal-charlas-macbook ~ $.
How do I go back to the original setting?
What is the difference between the two?
How did this get changed without my doing so?
At the end of ~/.profile add the line
export PS1='\u$ '
to get your old prompt back.
To do this you can type
nano ~/.profile
which will bring up a text editor. Press down until you get to the bottom of the file. Hit Enter to create a new line, and paste in
export PS1='\u$ '
Press Control+X to exit the editor and say "yes" when asked if you want to save. Now restart your terminal and your prompt should be restored.
The first prompt you gave shows your username, the second shows your username and hostname. There is no error and the functionality of your bash shell is not changed by changing the prompt.
Something must have changed your PS1 environment variable, maybe a system update or the installation of software. It's probably benign though.
I don't know how it got changed, but it's controlled by some symbol definitions. Use "man bash" in the terminal and search for the section called "PROMPTING". There are symbols named PS1-to-4 that it uses to construct the prompt.