Is there way to set terminator (Version: 0.95ppa1) title of tabs to a different string via bash command-line (CLI)?
I plan to use this feature with AutoKey and I can open multiple machines at same time and set title to Name of the machine its connected to.
ORIG=$PS1
TITLE="\e]2;\"This is just crazy enough to work\"\a"
PS1=${ORIG}${TITLE}
Resets title to
"This is just crazy enough to work"
This should apply to all xterm-style terminal emulators.
From the Terminator man pages,
Ctrl+Alt+W
Rename window title.
Ctrl+Alt+A
Rename tab title.
Ctrl+Alt+X
Rename terminal title.
You can also launch a new instance with
$ terminator --title [title]
Add follwing in your .bashrc file by editing it using vim ~/.bashrc and use set_title to rename your tab:
set_title()
{
ORIG=$PS1
TITLE="\e]2;$*\a"
PS1=${ORIG}${TITLE}
}
run source ~/.bashrc command after editing your .bashrc file
Ex.: set_title newtab will rename your current tab to newtab
working Properly in Gnome3.14 terminal and terminator 0.97
On Terminator 1.91-6 double click terminal title enables edition
PS1 does not need to be set. Credit for this function goes to geirha on freenode #bash
set_title() { printf '\e]2;%s\a' "$*"; }
This seems to work for me. I'm using BASH on Crunchbang (Debian derived)
$ echo -en '\e]0;echo works too\a'
With Terminator 0.96 and GNU bash 4.2.25 the printf suggestion above worked for me, but I had to tweak it slightly to make it into a function that would just work for me in a new Terminator tab. I added this to the end of my ~/.bashrc file:
set_title() { printf "\e]2;$*\a"; }
The key was placing the \a at the end of the quoted string. Then when opening a new tab in Terminator I can use this like so:
set_title "My new tab title"
Apologies to those who already stated the essentials of this answer, but since I found that I had to make slight changes to get it to work for me, this my also benefit someone else.
Try add PROMPT_COMMAND='echo -en "\033]0; $("pwd") \a"' in your .bashrc
For terminator 0.98 (Ubuntu 16.04 MATE), right clicking the title enables renaming it.
Right click on terminator and choose preferences from the drop-down menu. Choose profiles tab and enable "show title bar" option. It works!!
Tip: You can actually rename each terminator window!!
Related
I am installing dev tools on a new MacBook Air (M1) with Big Sur and the default terminal prompt is too long and includes my user name and host, so I found instructions on how to customize it.
Using the Terminal's preference window, I added this code.
export PS1="\W \$"; clear;
but when I launch the terminal, I get this prompt
\W $
I replaced W with other options, but they are never processed - I just get the literal string.
I suspect it has to do with the config file format for Terminal.
Create .zshrc file at user root and paste text. Follow steps mentioned below.
Run this command vi ~/.zshrc
Press i button in keyboard to enter in edit mode
Copy and paste this text into vi editor export PS1="%~ $ "
Press Esc button in keyboard
Press Shift + : button in keyboard
Press wq button in keyboard and press Enter
Restart your terminal by simply close and open again.
It Works!
For more configuration check documentation https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html
I have something like:
#!/usr/bin/env bash
export BEEP=$(echo -en "\007")
LIGHT_GRAY="\[\033[0;37m\]"
GREEN="\[\033[0;32m\]"
export PS1=$LIGHT_GRAY"\u#\h $GREEN\w : $BEEP"
Works for me to give:
robevans#Robs-Machine ~ : [start_typing_here_in_green]
with an audible sound (not a beep but macOS's 'chime') when a command's execution is complete.
Put the following in your .bashrc file:
export PS1='\W $'
My guess is that the \W is specific to bash.
Nowadays, the default macOS shell is zsh. See this page for some zsh prompt options
I am unable to test it on my Windows machine, but
PS1="%1~ $"
looks similar to \W to me.
Of course, if you want to configure your terminal to use bash, that's also an option.
I just found out in zsh if I have a variable, namely abc="cba", and if I type echo ${!abc} and pressing enter, it doesnt go as command but instead open new prompt below with expanded variable echo ${abc="cba"}.
And probably included that powerful zsh plugin that let us automatically insert sudo just by double tapping Esc.
So for further studying and probably opening new possibilities, what is the right terminology about that typed-command-but-not-entered manipulation?
Thanks...
Those seem to be unrelated. The first is zsh asking you to verify history expansion. The second is a ZLE (Zsh Line Editor) widget with a keybinding to modify the current command line. You can see what this ZLE widget looks like in oh-my-zsh the source code.
I'd like to remove a specific entry in my Zsh history.
Zsh's fc and history don't have any options to delete entries. I've tried looking for the ~/.zhistory but that doesn't exist. How can I go about finding the location of the history file and remove the entry?
You are looking in wrong File. Look at ~/.zsh_history not ~/.zhistory To view in which file your history is saved:
echo $HISTFILE
And delete:
rm $HISTFILE
Clearing Zsh History (oh-my-zsh)
close, quit and re-open iTerm
run nano .zsh_history
use the arrow keys to navigate to the part of your history you'd like to delete.
use the delete key to remove all unwanted history logs.
Once you've removed everything you'd like to remove, select control X to Exit.
You'll be prompted to Save the changes. If you're happy with your changes click shift Y.
You'll be asked where you'd like to save your changes. Select control T to save to File.
navigate to your .zsh_profile with your arrow keys and press enter.
Quit and restart iTerm.
type history to confirm the deletions.
You've successfully cleared your Zsh history.
osxterminalzshoh-my-zsh
Clear zsh history on unix systems.
echo "" > ~/.zsh_history & exec $SHELL -l
open ~/.zshrc
add the following line
alias clear_history='echo "" > ~/.zsh_history & exec $SHELL -l'
Save and close the file
Close the console or type zsh
if you to see the result directly, but this will open another zsh shell in the old one
Now you can clear the console typing clear_history
All the previous answers are good, this is simply the solution that worked for me.
You can use these commands to open the ZSH command's history(When you are in the home or ~ directory) and assume that you know how to use vim or nano :
nano ~/.zsh_history
vim ~/.zsh_history
open ~/.zsh_history
then you can delete the lines you want manually and save the file.
and if your zsh_history list is too long, for convenience use this:
enable mouse move and line numbering in the Vim environment by adding this to .vimrc:
open .vimrc:
vim ~/.vimrc
add these to .vimrc and save it(press ESC, enter ":" , write wq, and press enter):
:set number
set mouse=a
use the mouse to scroll easily in zsh_history by using Vim.
if you want to enable copy in Vim use holding shift on the keyboard.
read this for more info
https://www.techrepublic.com/article/how-to-effectively-clear-your-bash-history/
TL;DR
cat /dev/null > ~/.zsh_history
Type and run at the zsh command line, openĀ ~/.zsh_history (This opens TextEdit on my Mac.)
Delete any lines in the file
Save and close the file
Close/Exit the Zsh completely and restart the Zsh (this step is important!)
Now, open zsh and the history command does not show the lines that you deleted
This function will remove any one line you want from your Zsh history, no questions asked:
# Accepts one history line number as argument.
# Alternatively, you can do `dc -1` to remove the last line.
dc () {
# Prevent the specified history line from being saved.
local HISTORY_IGNORE="${(b)$(fc -ln $1 $1)}"
# Write out history to file, excluding lines that match `$HISTORY_IGNORE`.
fc -W
# Dispose of the current history and read the new history from file.
fc -p $HISTFILE $HISTSIZE $SAVEHIST
# TA-DA!
print -r "Deleted '$HISTORY_IGNORE' from history."
}
If you additionally want to prevent all dc commands from being written to history, add the following in your ~/.zshrc file:
zshaddhistory() {
[[ $1 != 'dc '* ]]
}
Alternatively, for a comprehensive, out-of-the-box solution, use my Zsh Hist plugin.
E.g. with vim you can easily delete the last n lines like this:
Open file: vim ~/.zsh_history
Go to the bottom of the file: G
Mark lines: V -> move up with arrow key
Delete: d
Write & quit: :wq
Or you can just navigate with the cursor and delete any particular line with dd
Open .zsh_history with your favourite editor and save keystrokes.
e.g. subl .zsh_history will open up history in Sublime editor and then delete whatever you want.
You can use TextEdit or other editors also.
This worked for me:
LC_ALL=C sed -i '' '/line/d' $HISTFILE
Replace "line" with what you want deleted.
From this answer:
https://stackoverflow.com/posts/13661794/revisions
For ZSH
To locate the history file do :
echo $HISTFILE
Then simply edit the file and remove any lines you wish to be gone as you would with history -d id.
Save the file.
Open a new terminal and you should see that there is nothing to see anymore !
However I am amazed that history -d does not exists. If it does exists it's well hidden.
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.
I am not exactly a pro at BASH Scripting, but I can get by with the basics. I use MRXVT with Cygwin on my windows box (MRXVT is an RXVT Terminal with tabs. RXVT is a Standard Cygwin terminal, but with enhanced features). I found a command to change the tab names for MRXVT:
echo -ne "\e]62;New tab title\a"
It works like a charm. I'm not, however, interested in A)Changing it manually or B)Changing it to a static String
I use a lot of SSH. I'd like the tab title to be username#host[current directory] at any given time.
I'm not sure if I'm supposed to use a trap for this. Frankly, I don't understand how traps work. I guess I could create an ssh alias that pulls the first argument of the ssh command and sets the tab title to that...This would be sufficient, but not preferred.
Do you guys have any ideas?
Found an answer. added
trap 'echo -ne "\e]62;mrxvt: $USER#${HOSTNAME}\007"' DEBUG
to the very end of my .bashrc. I decided I didn't like having the path in my tabs (or titlebar for that matter). Also, I had to add "mrxvt: " to the beginning of the string because of an AHK script that I wrote; it wouldn't work properly otherwise. The full answer to this is:
trap 'echo -ne "\e]62;$USER#${HOSTNAME}[${pwd}]\007"' DEBUG
Again, just add that line to the end of your .bashrc, and you're good to go.
Hope this helps somebody else :)