CMD+Shift+A alternative in iTerm - terminal

In Terminal app in macOS Sierra user can select the output with CMD+Shift+A.
E.g. do a ls command, then do CMD+Shift+A shortcut. The output of the ls command will be selected.
How to do the same in iTerm?

The same shortcut. You just need to install its shell integration.

Related

change VS Code Insider terminal from zsh to bash

I have updated my macOS to Catalina and the default terminal has changed to zsh in the VS Code Insider there, I need to change the terminal from zsh to bash.
Use the Terminal: Select Default Profile command or the GUI dropdown:
In settings, under Features->Terminal, you can specify the name or path to your shell.
Change user's login shell:
chsh -s path/to/shell_binary username

How to create terminal shortcuts (ssh shortcuts) on Mac OS Catalina (zsh)

Can't find many resources on this. With Mac OS Catalina, the default shell switched from bash to zsh.
I want to edit .zshrc so I can add some ssh shortcuts (and avoid having to copy/paste my ssh command from a text file every morning). I can't find .zshrc anywhere. Do I have to create it? Am I headed in the wrong direction? Any help appreciated.
.zshrc should be under /Users/username/
Try ls -a in terminal if you haven't to show hidden files. If .zshrc isn't there, you need to make one.

MacOS(Catalina) terminal bash looks weird

enter image description here
I just have installed Catalina on my imac, and I saw a terminal bash looks weird.
It should be ~$ but my terminal shows ~%
Can anyone change this uncommon line(~%) to a normal line(~$)?
Thank you in advance
You can set your PS1 variable in your .bashrc, .bash_profile, or .profile to whatever you want. For example:
export PS1=“\h \W $ “
Will give your hostname, current working directory, followed by the $ you wanted. This can be customized however you like, see this link for a good description.
Also, as chepner mentioned in the comments, you need to set your default shell back to bash. I believe the easiest thing to do is go into your terminal settings, and change your shell:
Terminal > Preferences... > General > Shells open with: Command (complete path): /bin/bash
For a long time, the bash was a default shell in macOS. However, Apple replaced Bourne Again SHell with Z shell for licensing reasons
Set default shell to bash on Macos Catalina. The procedure is as follows:
Open the terminal application.
List available shells by typing cat /etc/shells.
To update your account to use bash run chsh -s /bin/bash.
Close terminal app.
Open the terminal app again and verify that bash is your default shell.

emacs automatically open in mac

I was setting up with emacs on my macbook. In order to open the emacs from command line, I was follow other's suggestion to add an emacs script to my /usr/bin.
Now I can open graphic emacs from command line, but the problem is that every time when I open the terminal, the emacs is automatic run. I don't know why this happened.
Here is the script I added:
#!/bin/sh
/Applications/Emacs.app/Contents/MacOS/Emacs "$#"
I also use chmod +x /usr/bin/emacs after the script was added.
Please tell me what cause the problem happens.
If your using the standard OS X terminal, look under preferences->profile and the shell tab and make sure there isn't something set in the run on startup option.
If your using another terminal, such as iTerm, check the profiles.

How to make zsh run as a login shell on Mac OS X (in iTerm)?

When zsh is set as a login shell on Mac OS X, when it is started by iTerm, zsh doesn't consider that it's being run as a login shell, although it's started as ‘-zsh’ (‘-’ is put as the first character of arg[0]) which is supposed to mean that it should start as a login shell.
So, when I set the login shell to bash, bash recognizes this first ‘-’ in $0 and runs as a login shell, but zsh doesn't, although it seems that it should.
Is there a way to either make zsh recognize the ‘-’ in the arg[0], or make iTerm run the shell with a --login command line argument?
chsh -s $(which zsh)
You'll be prompted for your password, but once you update your settings any new iTerm/Terminal sessions you start on that machine will default to zsh.
In iTerm -> Preferences -> Profiles Tab -> General section set Command to: /bin/zsh --login
Go to the Users & Groups pane of the System Preferences -> Select the User -> Click the lock to make changes (bottom left corner) -> right click the current user select Advanced options... -> Select the Login Shell: /bin/zsh and OK
The command to change the shell at startup is chsh -s <path_to_shell>. The default shells in mac OS X are installed inside the bin directory so if you want to change to the default zsh then you would use the following
chsh -s /bin/zsh
If you're using different version of zsh then you might have to add that version to /etc/shells to avoid the nonstandard shell message. For example if you want home-brew's version of zsh then you have to add /usr/local/bin/zsh to the aforementioned file which you can do in one command sudo sh -c "echo '/usr/local/bin/zsh' >> /etc/shells" and then run
chsh -s /usr/local/bin/zsh
Or if you want to do the whole thing in one command just copy and paste this if you have zsh already installed
sudo sh -c "echo '/usr/local/bin/zsh' >> /etc/shells" && chsh -s /usr/local/bin/zsh
Have you tried editing the shell entry in account settings.
Go to the Accounts preferences, unlock, and right-click on your user account for the Advanced Settings dialog. Your shell should be /bin/zsh, and you can edit that invocation appropriately (i.e. add the --login argument).
Use the login utility to create a login shell. Assume that the user you want to log in has the username Alice and that zsh is installed in /opt/local/bin/zsh (e.g., a more recent version installed via MacPorts). In iTerm 2, go to Preferences, Profiles, select the profile that you want to set up, and enter in Command:
login -pfq Alice /opt/local/bin/zsh
See man login for more details on the options.

Resources