Customize zsh prompt - macos

How can I remove the [ that is placed before my commands after they are entered (e.g. the top two lines in the picture). Looking for something to put in my .zshrc file.

As per chepner, they are part of the terminal not zsh.
The way to remove them is:
Choose Edit > Marks > Automatically Mark Prompt Lines. The tick lets you know whether the option is enabled.

Related

Why is a [ being added to my prompt after upgrading to OS X 10.11?

Since upgrading from OS X 10.10 to 10.11, my Bash prompt has started to behave strangely. A configuration that I've been using for years without issues and started adding a [, on the line above the current line. That is, if I have
~/dir $ cd foo
and hit return, I get
[~/dir $ cd foo
~/dir/foo $
or, if I just have
~/dir $
and hit return, I get
[~/dir $
~/dir $
I get the same behavior regardless of the command I enter (or if, as above, I enter none).
Even if I completely empty my .bash_profile I still get this behavior.
What can I do to fix this (and why might this suddenly have started happening as the result of the upgrade to El Capitan)?
It is not about the bash setting or any other bash config file. You just need to uncheck "Automatically Mark Prompt Lines" option in Edit menu of Terminal app.
The new Marks feature in El Capitan 10.11 adds structure to the terminal contents by marking prompt lines and other interesting content, enabling operations like navigating, selecting, Copying, Printing and deleting commands or their output.
You can hide the marks if you don't want to see them, with the View > Hide/Show Marks menu item.
It should be rare that someone actually needs to turn off automatic marking of prompt lines, since, other than their visual representation—which you can turn off—they are passive and only affect the new Marks-related commands. The Edit > Marks > Automatically Mark Prompt Lines menu item—which is a persistent preference—exists primarily in case you want to have complete manual control over which lines are marked, by using the other commands in the Marks submenu.
A very good explanation of what you can do with Marks and the related commands is found in this answer to this question.

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.

How to interactively set syntax highlighting in VI editor

Using vi, I want to display files in distinguished colors in unix. If I save a file as .sql or .java it will highlight the keywords. I want to make changes to which words are highlighted, and in what color.
How do I control syntax highlighting and color schemes with various vi file extensions?
Type following command after a colon:
:set ft=sql.
I just did it by putting :syntax on. I suppose you want to save the settings so it can be highlighted each time you open one of those files, in which case the answer by Eric it's the correct one.
For file specific settings, there is also the power of modelines.
You can put them in the first or last five (unless you change modelines variable) lines to control variable settings.
eg:
# vim: syn=sh
or even:
/* vim: tw=60 ts=2: */
see vim's help: :h modeline
Are you sure one of the user don't have an alias to vim or something like that? CF: http://masstransmit.com/garage_blog/alias-vi-vim/

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.

How can I make bash tab completion behave like vim tab completion and cycle through matching matches?

I've been meaning to find a solution for this for YEARS.
I am sooo much more productive in vim when manipulating files than bash for this reason.
If I have
file_12390983421
file_12391983421
file_12340983421
file_12390986421
In bash and type file_1->tab , it obviously lists:
file_12390983421 file_12391983421 file_12340983421 file_12390986421
And this is horrible and painful to work with.
The same sequence in vim will loop through the files one at a time.
Please someone tell me how to do this in bash, or if there is another shell that can do this, I'll switch tomorrow.
By default TAB is bound to the complete readline command. Your desired behavior would be menu-complete instead. You can change your readlines settings by editing ~/.inputrc. To rebind TAB, add this line:
TAB: menu-complete
For more details see the READLINE section in man bash.
For bash >= 4 you might like these settings. You can try them directly on the command-line, and put them in your ~/.bash_profile if you like them.
# If there are multiple matches for completion, Tab should cycle through them
bind 'TAB:menu-complete'
# And Shift-Tab should cycle backwards
bind '"\e[Z": menu-complete-backward'
# Display a list of the matching files
bind "set show-all-if-ambiguous on"
# Perform partial (common) completion on the first Tab press, only start
# cycling full results on the second Tab press (from bash version 5)
bind "set menu-complete-display-prefix on"
This setup is similar to Vim's set wildmode=longest:full:list,full
I pulled these settings from this question on the Unix & Linux site.
By the way, since you are here, here are some other great bindings:
# Cycle through history based on characters already typed on the line
bind '"\e[A":history-search-backward'
bind '"\e[B":history-search-forward'
# Keep Ctrl-Left and Ctrl-Right working when the above are used
bind '"\e[1;5C":forward-word'
bind '"\e[1;5D":backward-word'
This means if you type ssh<Up> it will cycle through previous lines where you ran ssh
If you don't like what you got, you can clear the line with Ctrl-K Ctrl-U
I pulled these settings from this question on AskUbuntu.
On top of
# cycle forward
Control-k: menu-complete
# cycle backward
Control-j: menu-complete-backward
you may also consider adding
# display one column with matches
set completion-display-width 1
This way you would preserve the current Tab functionality and make bash display the possibilities in one column. So instead of
file_12340983421 file_12390983421 file_12390986421 file_12391983421
you would get
file_12340983421
file_12390983421
file_12390986421
file_12391983421
P.S. You can get up to date readline library from this The GNU Readline Library website.
Thanks to #sth I found what works best for me:
To keep normal bash tab completion, and then use ctl-f to cycle through when needed using menu-complete
put this in your .inputrc file:
"\C-f": menu-complete
In my experience, the solution provided in sth's answer has never completely worked for me. TL;DR: Add set -o vi to your ~/.bashrc.
When using menu-complete in conjunction with vi keybindings, I have to make sure that my ~/.bashrc has:
set -o vi
It's never been enough for my ~/.inputrc just to have:
TAB: menu-complete
set editing-mode vi
set keymap vi
My guess is that somehow set editing-mode and set keymap are clobbering the TAB: ... setting, but I haven't looked into the documentation thoroughly to figure out why this is the case.

Resources