keep terminal window title when using screen - bash

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?

Related

How to start emacs from the terminal with an emacs command that runs soon after emacs is opened

Is there a way to launch Emacs from terminal and execute some Emacs command automatically soon after Emacs is launched (the command to be executed inside of emacs is provided along with the Emacs-launching command executed from the shell.)
What I want to do exactly is to have a command to launch Emacs and then open a new empty buffer and activate org mode inside of this buffer.
I want something that might look like this
emacs -fs --command="evil-buffer-new && org-mode"
I want the -fs flag because I want Emacs to open in full-screen in this case.
Update
--eval flag didn't work. Forget about evil-buffer-new, I have tried something as simple as:
emacs --eval="(org-mode)" txt.txt
txt.txt is an empty text file created before executing the above command (and please don't ask me why I didn't use .org file extension).
after Emacs opened, org-mode wasn't active. I had to run pp-eval-expression then (org-mode) to activate it, and then it worked.
Am I missing something here? How about rephrasing the question like this:
How to open an empty text file (having .txt file extension) with Emacs from the terminal and have org-mode activated in that buffer automatically?
See C-hig (emacs)Action Arguments or even just run emacs --help -- there are several options for loading and evaluating arbitrary code.
--command="evil-buffer-new && org-mode"
More like:
--eval="(progn (evil-buffer-new) (org-mode))"
But you'll have to figure it out for yourself, because I don't know what evil-buffer-new is specifically.
You told an empty file is created before emacs is started. But instead of an empty file could you create a file with file-local mode variable specifying the org mode ? For example with bash:
#!/bin/bash
cat <<EOF >> "$1"
; -*- mode: Org;-*-
EOF
emacs "$1" &
Now the mode is always resolved correctly with normal major mode selection procedure.

Gnome Terminal keeps appending prompt when window is resized

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:

bash & mingw: overwrites output when scrolling up

I'm currently using git-for-windows-sdk, with Bash 3.1.33(1)-release. I experience quite annoying and buggy behavior when I scroll up and press key up: Console doesn't scroll back to bottom, just shows the prompt and starts overwriting output.
Clearing helps just for the currently shown area, after outputting goes next, there is still buffered output.
How to reproduce:
Output something longer than 1 screen.
Scroll up.
Press arrow up key.
Expected behavior:
Bash scrolls down and shows prompt.
Current behavior:
Bash stays on the screen and shows prompt on the last line. Then overwrites buffered output.
Actually, I tried to investigate this behavior a little bit. And I realized, that it's affected by PS1/PROMPT setting. Color escapes and new lines have some role in it, but I was unable to define it.
the default git-bash prompt setting doesn't produce this wrong behavior:
export PROMPT_COMMAND='__git_ps1 "\n\[\033[33m\]\w\[\033[0m\]\[\033[32m\]" "\[\033[0m\]\n$ "'
just removing the new line produces wrong behavior:
export PROMPT_COMMAND='__git_ps1 "\n\[\033[33m\]\w\[\033[0m\]\[\033[32m\]" "\[\033[0m\]$ "'
however, one line prompt without colors doesn't produce wrong behavior:
export PROMPT_COMMAND='__git_ps1 "\w" " \$ "'
For better understanding see this screencast: http://screencast.com/t/vqItWFSoR

Terminal shows "?

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.

Change in the hostname/user in Terminal in Leopard OSX

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.

Resources